Bonjours à toutes et à tous,


Je créer un composant dérivé de TShape :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
unit ShapeRu;
 
interface
 
uses
  Windows, SysUtils, Classes, Controls, ExtCtrls, Graphics, Math;
 
type
  TShapeRu = class(TShape)
  private
    { Déclarations }
    Pos :TPoint;
    Position :Byte;
    fTailleMini: Integer;
    fTailleMaxi: Integer;
    fTailleBlocDep: Byte;
    fLeftMini: Integer;
    fRightMaxi: integer;
    fTopMini: Integer;
    fTopMaxi: Integer;
  protected
    { Déclarations protégées }
 
    procedure MouseDown(Button : TMouseButton; Shift : TShiftState; X, Y : integer); override;
    procedure MouseMove(Shift : TShiftState; X, Y : integer); override;
    procedure MouseUp(Button : TMouseButton; Shift : TShiftState; X, Y : integer); override;
    function GetTailleMaxi: Integer;
    procedure SetTailleMaxi(aTailleMaxi: Integer);
    procedure SetTailleBlocDep(aTailleBlocDep: Byte);
    function GetTailleMini : Integer;
    procedure SetTailleMini(aTailleMini: Integer);
    function GetRightMaxi : Integer;
    procedure SetRightMaxi(aRightMaxi: Integer);
    function GetTopMini: Integer;
    procedure SetTopMini(aTopMini:integer);
    function GetTopMaxi: Integer;
    procedure SetTopMaxi(aTopMaxi:integer);
  public
    { Déclarations publiques }
    constructor Create(AOwner : TComponent); override;
    destructor Destroy; override;
  published
    { Déclarations publiées }
      property StartColor : Tcolor read fStartColor write fStartColor ;
      property EndColor : Tcolor read FEndColor write FEndColor ;
      property Caption1 : String read fCaption1 write fCaption1;
      property Caption2 : String read fCaption2 write fCaption2;
      property TailleMini : Integer read GetTailleMini write SetTailleMini;
      property TailleMaxi : Integer read GetTailleMaxi write SetTailleMaxi;
      property TailleBlocDep : Byte read fTailleBlocDep write SetTailleBlocDep Default 1;
      property LeftMini : Integer read fLeftMini write fLeftMini;
      property RightMaxi : Integer read GetRightMaxi write SetRightMaxi;
      property TopMini : Integer read GetTopMini write SetTopMini;
      property TopMaxi : Integer read GetTopMaxi write SetTopMaxi;
  end;
 
procedure Register;
 
implementation
 
constructor TShapeRu.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
    fTailleBlocDep := 1;
    fTailleMini := fTailleBlocDep + 3;
    fTailleMaxi := Width + Left;
end;
 
destructor TShapeRu.Destroy;
begin
  inherited Destroy;
end;
 
function TShapeRu.GetTailleMaxi: Integer;
begin
  if fTailleMaxi < Width
    then result := Width
    else result := fTailleMaxi;
end;
 
procedure TShapeRu.SetTailleMaxi(aTailleMaxi: Integer);
begin
  if aTailleMaxi < Width
    then ftailleMaxi := Width
    else ftailleMaxi := aTailleMaxi;
end;
 
procedure TShapeRu.SetTailleBlocDep(aTailleBlocDep: Byte);
begin
  if aTailleblocDep < 1
    then fTailleBlocDep := 1
    else fTailleBlocDep := aTailleBlocDep;
end;
 
function TShapeRu.GetTailleMini: integer;
begin
  if fTailleMini < fTailleBlocDep + 3
    then Result := fTailleBlocDep + 3
    else Result := fTailleMini;
end;
 
procedure TShapeRu.SetTailleMini(aTailleMini: Integer);
begin
  if aTailleMini < fTailleBlocDep + 3
    then fTailleMini := fTailleBlocDep + 3
    else fTailleMini := aTailleMini;
end;
 
function TShapeRu.GetRightMaxi: Integer;
begin
  if fRightMaxi < left + Width + (fTailleMaxi - left)
    then Result := left + Width + (fTailleMaxi - left)
    else Result := fRightMaxi;
end;
 
procedure TShapeRu.SetRightMaxi(aRightMaxi: Integer);
begin
  if aRightMaxi < Left + Width + (fTailleMaxi - left)
    then fRightMaxi := Left + Width + (fTailleMaxi - left)
    else fRightMaxi := aRightMaxi;
end;
 
function TShapeRu.GetTopMini: Integer;
begin
  if fTopMini < 0
    then Result := 0
    else Result := fTopMini;
end;
 
procedure TShapeRu.SetTopMini(aTopMini: Integer);
begin
  if aTopMini < 0
    then fTopMini := 0
    else fTopMini := aTopMini;
end;
 
function TShapeRu.GetTopMaxi: Integer;
begin
  if fTopMaxi < fTopMini + Height
  then Result := fTopMini + Height
  else Result := fTopMaxi;
end;
 
procedure TShapeRu.SetTopMaxi(aTopMaxi: Integer);
begin
  if aTopMaxi < fTopMini + Height
    then ftopMaxi := fTopMini + Height
    else ftopMaxi := aTopMaxi;
 
end;
 
procedure TShapeRu.Paint;
  Procedure Degrader;
  Var
    TailleDuTexte : Integer;
    aBand : TRect;    { Bande rectangulaire de couleur courante }
    i : Integer;  { Compteur pour parcourir la hauteur de la fiche }
    FStartRGB  : Array[0..2] of Byte;    { RGB de la couleur de départ }
    FCurrentRGB : Array[0..2] of Byte;    { RGB de la couleur courante  }
    FDeltaRGB  : Array[0..2] of Integer; { RGB à ajouter à la couleur de départ pour atteindre la couleur de fin }
    nbtranches: integer;
    Rect:TRect;
  Begin
    Rect.Left := 2;
    Rect.Top := 2;
    Rect.Right := Self.Width-2;
    Rect.Bottom := Self.Height-2;
    self.ParentColor := false;
 
    { Calcul des valeurs RGB pour la couleur courante }
    FStartRGB[0] := GetRValue( ColorToRGB( StartColor ) );
    FStartRGB[1] := GetGValue( ColorToRGB( StartColor ) );
    FStartRGB[2] := GetBValue( ColorToRGB( StartColor ) );
    { Calcul des valeurs à ajouter pour atteindre la couleur de fin }
    FDeltaRGB[0] := GetRValue( ColorToRGB( EndColor )) - FStartRGB[0] ;
    FDeltaRGB[1] := GetgValue( ColorToRGB( EndColor )) - FStartRGB[1] ;
    FDeltaRGB[2] := GetbValue( ColorToRGB( EndColor )) - FStartRGB[2] ;
 
    { Initialisation des dimensions de la bande de couleur }
    aBand.Left :=Rect.Left;
    aBand.Right:=Rect.Right;
    nbtranches:=min(256, Rect.Bottom-Rect.Top);
    { Boucle pour remplir la fiche courante en dégradé }
    With Canvas Do
    Begin
      Pen.Style:=psSolid;
      Pen.Mode:=pmCopy;
      For i:= 0 To nbtranches-1 Do
      Begin
          { Dimensions verticales de la bande }
          aBand.Left :=Rect.Left;
          aBand.Right:=Rect.Right;
          aBand.Top := Rect.Top+Round((Rect.Bottom-Rect.Top)/nbtranches*i);
          aBand.Bottom := Rect.Top+Round((Rect.Bottom-Rect.Top)/nbtranches*(i+1));
 
          { Calcul de la couleur courante }
          FCurrentRGB[0] := (FStartRGB[0] + MulDiv( i , FDeltaRGB[0] , nbtranches )) mod 256;
          FCurrentRGB[1] := (FStartRGB[1] + MulDiv( i , FDeltaRGB[1] , nbtranches )) mod 256;
          FCurrentRGB[2] := (FStartRGB[2] + MulDiv( i , FDeltaRGB[2] , nbtranches )) mod 256;
          { Affichage sur la fiche }
          Brush.color:=RGB(FCurrentRGB[0],FCurrentRGB[1],FCurrentRGB[2]);
          FillRect(aBand);
      End;
      Font.Name := self.Font.Name;
      Font.Size := self.Font.Size;
      Brush.Style := bsClear;
      if Self.Caption1 = '' then DrawText(Canvas.Handle, PChar(Self.Caption) , -1, Rect, DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE)
      else
      Begin
        DrawText(Canvas.Handle, PChar(Self.Caption1) , -1, Rect, DT_CENTER or DT_NOPREFIX or DT_WORDBREAK);
        TailleDuTexte := DrawText(Canvas.Handle, PChar(Self.Caption1) , -1, Rect, DT_CENTER or DT_NOPREFIX or DT_WORDBREAK);
        Rect.Top := Rect.Top + TailleDuTexte + 2;
        Pen.Color := clBlack;
        MoveTo(Rect.Left+2,Rect.Top);
        LineTo(Rect.Right-2,Rect.top);
        Rect.Top := Rect.Top + 2;
        DrawText(Canvas.Handle, PChar(Self.Caption2) , -1, Rect, DT_NOPREFIX or DT_WORDBREAK);
      end;
    End;
  End;
begin
  inherited Paint;
  Degrader;
end;
 
procedure TShapeRu.MouseDown(Button: TMouseButton; Shift: TShiftState; X: Integer; Y: Integer);
begin
  inherited;
  if (not Enabled) or (Button <> mbLeft) then exit;
  BringToFront;
  if (X >= Width-3) then position := 2
  else Begin position := 3; Pos := Point(X,Y); end;
end;
 
procedure TShapeRu.MouseMove(Shift: TShiftState; X: Integer; Y: Integer);
Var
  Pt : TPoint;
  rMaxi: Integer;
begin
  inherited;
  if Y > ClientHeight then exit;
  Cursor := crSizeAll;
  if X >= Width-3 then Cursor:=CrHsplit; // Cursor pour l'étirement
  if (Position = 2) then // Si on déplace le Shape (valeur donnée par MouseDown)
  begin
    if (X > TailleMini)
      and (X mod TailleBlocDep = 0)
        and (X + Left <= TailleMaxi)
          then Width := X;
  end
  else
    if (Position = 3) then
    begin
      Pt := ClientToParent(point(x,y));
      if InRange(Pt.y,TopMini,TopMaxi) then Top := Pt.y;
 
      rMaxi := RightMaxi - Width;
      if ((Left + X - Pos.X) mod TailleBlocDep = 0) then
        Begin
          X := (Left + X - Pos.X)-1;
          Left := EnsureRange(X, LeftMini, rMaxi); //Déplacement en X
        end;
 
    end;
end;
 
procedure TShapeRu.MouseUp(Button: TMouseButton; Shift: TShiftState; X: Integer; Y: Integer);
begin
  inherited;
  Position := 0;
end;
 
procedure Register;
begin
  RegisterComponents('RuCompos', [TShapeRu]);
end;
 
end.
Mon probleme se situe au niveau de la procédure

procedure TShapeRu.MouseMove(Shift: TShiftState; X: Integer; Y: Integer);

Lorsque je clique sur le shape, le curseur de ma souris ne bouge pas et se trouve là où j'ai cliqué, mais si je bouge (je move) le curseur de la souris se position automatiquement sur le bord haut du shape (le mouvement fonctionne bien) au lieu de laissé ma souris là où j'ai cliqué.

Merci de votre aide.