1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
| //--
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//--
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--
Graphics::TBitmap *Bitmap = new Graphics::TBitmap;
COLORREF V1_Color = clRed;
COLORREF V2_Color = clBlue;
COLORREF V3_Color = clGreen;
//--
__fastcall jLabel::jLabel(TComponent *Owner)
: TCustomControl(Owner)
{
if(Owner->InheritsFrom(__classid(TWinControl))) Parent = (TWinControl*)Owner;
FCaption = "---";
Canvas->Brush->Style = bsClear;
Canvas->Font->Color = clBlack;
Left = 10; Top = 10;
BringToFront();
}
//--
__fastcall jLabel::~jLabel()
{
}
//--
void __fastcall jLabel::Paint()
{
int we = Canvas->TextWidth(FCaption);
int he = Canvas->TextHeight(FCaption);
SetBounds(Left,Top,we,he);
Canvas->CopyRect(Rect(0,0,we,he), Bitmap->Canvas, BoundsRect);
Canvas->TextOut(0,0,FCaption);
//--------------- pour le test
OnMouseDown = WhenDown;
}
//--
void __fastcall jLabel::SetCaption(AnsiString N)
{
FCaption = N;
Paint();
}
//--------------pour le test
void __fastcall jLabel::WhenDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
OnMouseMove = WhenMove;
OnMouseUp = WhenUp;
Start = Point(X,Y);
}
//--------------pour le test
void __fastcall jLabel::WhenMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
int left = Left + X - Start.x;
int top = Top + Y - Start.y;
SetBounds(left, top, Width, Height);
Paint();
}
//--------------pour le test
void __fastcall jLabel::WhenUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
OnMouseMove = NULL;
OnMouseUp = NULL;
}
//---------------------------------------------------------------------------
jLabel *Label_A1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Label_A1 = new jLabel(this);
}
//--
void __fastcall TForm1::FormPaint(TObject *Sender)
{
DrawBitmap();
}
//--
void __fastcall TForm1::FormResize(TObject *Sender)
{
DrawBitmap();
}
//--
void __fastcall TForm1::DrawBitmap()
{
if(Bitmap != NULL)
{
int we = ClientWidth;
int he = ClientHeight;
if(Bitmap->Width != we) Bitmap->Width = we;
if(Bitmap->Height != he) Bitmap->Height = he;
TCanvas *C = Bitmap->Canvas;
C->Brush->Style = bsSolid;
C->Brush->Color = Color;
C->FillRect(Rect(0,0,we,he));
C->Brush->Color = (TColor)V1_Color;
C->Rectangle(20,20,100,100);
C->Brush->Color = (TColor)V2_Color;
C->Ellipse(50,50, 200, 150);
C->Brush->Color = (TColor)V3_Color;
C->Rectangle(100, 40, 120, 400);
Canvas->Draw(0,0,Bitmap);
}
}
//--
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
delete Bitmap;
Bitmap = NULL;
}
//--
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Label_A1->Caption = IntToStr(GetTickCount());
}
//--
void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
V1_Color = RGB(GetRValue(V1_Color) + 10,
GetGValue(V1_Color) - 15,
GetBValue(V1_Color) + 30);
V2_Color = RGB(GetRValue(V2_Color) - 20,
GetGValue(V2_Color) + 20,
GetBValue(V2_Color) - 10);
V3_Color = RGB(GetRValue(V3_Color) + 10,
GetGValue(V3_Color) + 20,
GetBValue(V3_Color) + 30);
DrawBitmap();
Label_A1->Repaint();
}
//-- |
Partager