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
| function MergedCells(ASG:TStringGrid; ACol,ARow,ACol1,ARow1,ACol2,ARow2:Integer; ACurrentState: TGridDrawState):Boolean;
var
x1,y1,x2,y2:Integer;
Rect:TRect;
begin
with ASG, Canvas do
begin
//Initialisations diverses
Rect := Bounds(0,0,0,0);
x1 := ACol1;
y1 := ARow1;
x2 := ACol2;
y2 := ARow2;
result := false;
//On vérifie que la zone fusionnée est valide
if x1 < 0 then x1 := 0;
if x2 > ColCount-1 then x2 := ColCount-1;
if y1 < 0 then y1 := 0;
if y2 > RowCount-1 then y2 := RowCount-1;
if (x1 > x2) or (y1 > y2) then
begin
result := false;
exit;
end;
//Si la cellule courante est la dernière de la zone de fusion, on dessine dans la fusion le texte de la cellule en haut à gauche
if ((ACol=ACol2) and (ARow=ARow2)) then
begin
Rect.Left := CellRect(ACol1,ARow1).Left;
Rect.Top := CellRect(ACol1,ARow1).Top;
Rect.Right := CellRect(ACol2,ARow2).Right;
Rect.Bottom := CellRect(ACol2,ARow2).Bottom;
FillRect(Rect);
// Le bloc qui suit pour imiter le "look" par défaut
if GridLineWidth = 1 then
begin
Pen.Color := clBlack;Pen.Width := 1;
Canvas.Rectangle(Rect.Left-1,Rect.Top-1,Rect.Right+1,Rect.Bottom+1);
end;
//
Frame3D(Canvas, Rect, clBtnHighlight, clBtnShadow, BevelWidth);
InflateRect(Rect,-2,-2);
DrawText(Handle, PChar(Cells[ACol1,ARow1]), -1, Rect ,DT_CENTER or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE );
end;
//Si la cellule courante est dans la zone de fusion, on dit qu'on la dessiné (même si ce n'est pas vrai :) )
if ((ACol>=ACol1) and (ARow>=ARow1) and (ACol<=ACol2) and (ARow<=ARow2)) then
result := True;
end;
end; |
Partager