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
|
var ARowM1,IRow:integer;
RectM1:TRect;
SG:byte;
function CursorToRow(P:TPoint;SG:byte):integer;
var PR:TPoint;
begin
//Détermine le N° de Row de la StringGrid à partir de la position du curseur
case SG of
1:begin //SG1
PR:=EssaiFiche.ScreenToClient(P);
PR.Y:=PR.Y-EssaiFiche.SG1.Top;
Result:=Trunc((PR.Y-2)/25)-1+EssaiFiche.SG1.TopRow;
end;
2:begin
PR:=EssaiFiche.ScreenToClient(P);
PR.Y:=PR.Y-EssaiFiche.SG2.Top;
Result:=Trunc((PR.Y-2)/25)-1+EssaiFiche.SG2.TopRow;
end;
end;
end;
procedure TEssaiFiche.SG1DrawCell(Sender: TObject; ACol, ARow: integer;
Rect: TRect; State: TGridDrawState);
begin
with Sender as TStringGrid do with Canvas do
begin
//Sélection de la couleur du fond
if SG1.Focused then
if gdFixed in State then Brush.Color:=clBtnFace
else if gdSelected in State then Brush.Color:=clBlue
else Brush.Color:=clWhite
else if gdFixed in State then Brush.Color:=clBtnFace
else Brush.Color:=clWhite;
//Remplissage du fond
Fill(Rect);
//Sélection de la couleur d'écriture
if Brush.Color=clBlue then Font.Color:=clWhite
else Font.Color:=clBlack;
//Edition du Texte
TextOut(Rect.Left,Rect.Top,Cells[ACol,ARow]);
end;
end;
procedure TEssaiFiche.SG1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: integer);
var Point: TPoint;
begin
Point:=Mouse.CursorPos;
IRow:=CursorToRow(Point,1);
SG:=1;
if Button=mbLeft then
begin
//Code
end
else
begin
SG1.Row:=IRow;
RectM1:=Rect(0,(IRow-SG1.TopRow+1)*25,180,(IRow-SG1.TopRow+2)*25);
ARowM1:=IRow;BAnnul.Visible:=True;
SG1.Enabled:=False;SG2.Enabled:=False;
end;
end;
procedure TEssaiFiche.BAnnulClick (Sender: TObject);
begin
SG1.Enabled:=True;SG2.Enabled:=True;
case SG of
1:begin
with SG1.Canvas do
begin
Brush.Color:=clBlue;Font.Color:=clWhite;
FillRect(RectM1);
TextOut(RectM1.Left+1,RectM1.Top,SG1.Cells[0,ARowM1]);
SG1.Row:=ARowM1;
end;
end;
2:begin
with SG2.Canvas do
begin
Brush.Color:=clBlue;Font.Color:=clWhite;
FillRect(RectM1);
TextOut(RectM1.Left+1,RectM1.Top,SG2.Cells[0,ARowM1]);
SG2.Row:=ARowM1;
end;
end;
end;
BAnnul.Visible:=False;
end; |
Partager