Bonjour à tous,

J'ai besoin de mettre un panel dans les cellules de la colonne 0 d'une StringGrid. Le panel est invisible jusqu'à ce que le pointeur de la souris arrive dans le dernier quart (approx) de la cellule. Le panel doit se mettre comme si nous pouvions faire un .Left (à droite sur la hauteur totale de la cellule). Chaque cellule de la colonne 0 est concernée. Le panel se comportera comme un bouton dans lequel je vais cliquer.

Nom : Sans titre.png
Affichages : 97
Taille : 401 octets

Je tourne en rond.
J'arrive à mettre mon panel, à détecter ma position mais c'est de le caler style .left dans la cellule qui pose problème. Je n'arrive pas à avoir la position gauche exacte de la cellule.

Je vous passe mon code, si quelqu'un à une idée.

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
procedure TForm1.StringGrid1MouseMove(Sender: TObject;Shift: TShiftState; X, Y: Integer);
Var
    ACol, ARow: Longint;
    ARect: TRect;
    ScreenPoint : TPoint;
    ClientPoint : TPoint;
    GridPoint : TPoint;
begin
    StringGrid1.MouseToCell(X, Y, ACol, ARow);
 
    GetCursorPos(ScreenPoint);
    ARect:=StringGrid1.CellRect(ACol,ARow);
    ClientPoint := Panel5.ScreenToClient(ScreenPoint);
    GridPoint := StringGrid1.ScreenToClient(ScreenPoint);
 
// Pour suivre la position et comprendre le truc
Label7.Caption:=Format('Largeur %d - Left %d - Pt.X %d' ,[aRect.width, aRect.Left, ClientPoint.Y]);
Label7.Update;
Label8.Caption:=Format('Top %d - Bottom %d - Pt.Y %d - Panel.top %d' ,[aRect.Top, aRect.Bottom, ScreenPoint.Y, Panel_Liste1.Top]);
Label8.Update;
 
if (ARow>0)
    then begin
        if (ACol=0)
        then begin
            if (ClientPoint.X>=ARect.Left+ARect.width + StringGrid1.GridLineWidth - Image_Liste1.Width)
            and (ClientPoint.X<=ARect.Left+ARect.width)
            then begin
                Panel_Liste1.Visible:=true;
                Panel_Liste1.BringToFront;
                Panel_Liste1.Width:=Image_Liste1.Width;
                Panel_Liste1.Left:=aRect.Left + aRect.width + StringGrid1.GridLineWidth - Image_Liste1.Width;
                Panel_Liste1.Top:= ClientPoint.Y; //(ScreenPoint.Y div (StringGrid1.DefaultRowHeight + StringGrid1.GridLineWidth))*(StringGrid1.DefaultRowHeight + StringGrid1.GridLineWidth)+1;
                Panel_Liste1.Height:=StringGrid1.DefaultRowHeight;
                StringGrid1.Invalidate;
            end
            else begin
                Panel_Liste1.Visible:=False;
                StringGrid1.Invalidate;
            end;
        end
        else begin
            Panel_Liste1.Visible:=False;
            StringGrid1.Invalidate;
        end;
    end;
end;