Bonjour,

Mon problème est de traçer un rectangle de sélection sur un TImage.
J'ai trouvé des routines qui utilisent des fonctions Windows telles que :
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
 
procedure TForm1.RemoveTheRect;
var
  R : TRect;
begin
  R := NormalizeRect(Rect(MaskRect.TopLeft.X,MaskRect.TopLeft.Y,MaskRect.BottomRight.X,MaskRect.BottomRight.Y));  // Rectangle might be flipped
  InflateRect(R,1,1);                     // Make the rectangle 1 pixel larger
  InvalidateRect(Handle,@R,True);         // Mark the area as invalid
  InflateRect(R,-2,-2);                   // Now shrink the rectangle 2 pixels
  ValidateRect(Handle,@R);                // And validate this new rectangle.
  // This leaves a 2 pixel band all the way around
  // the rectangle that will be erased & redrawn
  UpdateWindow(Handle);
end;
 
procedure TForm1.DrawTheRect;
begin
  // Determines starting pixel color of Rect
  Counter := CounterStart;
  // Use LineDDA to draw each of the 4 edges of the rectangle
  LineDDA(MaskRect.TopLeft.X,MaskRect.TopLeft.Y,MaskRect.BottomRight.X,MaskRect.TopLeft.Y,@MovingDots,LongInt(Canvas));
  LineDDA(MaskRect.BottomRight.X,MaskRect.TopLeft.Y,MaskRect.BottomRight.X,MaskRect.BottomRight.Y,@MovingDots,LongInt(Canvas));
  LineDDA(MaskRect.BottomRight.X,MaskRect.BottomRight.Y,MaskRect.TopLeft.X,MaskRect.BottomRight.Y,@MovingDots,LongInt(Canvas));
  LineDDA(MaskRect.TopLeft.X,MaskRect.BottomRight.Y,MaskRect.TopLeft.X,MaskRect.TopLeft.Y,@MovingDots,LongInt(Canvas));
end;
Ces routines sont appelées à partir des évenements OnMouseDown et OnMouseMove d'un TImge

Le problème est simple :

Si TImage se trouve directement sur TForm cette routine marche sans problème.

Si TImage se trouve sur un TPanel lui même sur TForm elle ne marche plus !

Quelqu'un sait-il pourquoi ?