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
|
function MergedCells2(ASG:TStringGrid; ACol,ARow,ACol1,ARow1,ACol2,ARow2:Integer; ACurrentState: TGridDrawState):Boolean;
var
x1,y1,x2,y2:Integer;
Rect:TRect;
NoRightDrow: boolean;
OCol1,ORow1,OCol2,ORow2:Integer;
function GetWidth (FromCol, ToCol: integer): integer;
var
i: integer;
begin
result := 0;
for i := FromCol to ToCol do
inc (result,ASG.ColWidths [i]);
end;
begin
NoRightDrow := false;
with ASG, Canvas do
begin
//Initialisations diverses
OCol1 := ACol1;
ORow1 := ARow1;
OCol2 := ACol2;
ORow2 := ARow2;
result := false;
Rect := Bounds(0,0,0,0);
if ACol1 < LeftCol then /// MODIFICATION ICI
begin
ACol1 := LeftCol;
end;
x1 := ACol1;
y1 := ARow1;
if ACol2 >= LeftCol + VisibleColCount then /// MODIFICATION ICI
begin
ACol2 := LeftCol + VisibleColCount ;
NoRightDrow := true;
end;
x2 := ACol2;
y2 := ARow2;
//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
if ((ACol=aCol2) and (ARow=aRow2)) then
begin
Rect.Left := CellRect(ACol1,ARow1).Left;
Rect.Top := CellRect(ACol1,ARow1).Top;
Rect.Right := Rect.Left;
FillRect(Rect);
if NoRightDrow then
begin
Rect.Right := Rect.Left + GetWidth (oCol1,oCol2)+ 2;
end
else
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, 1(*BevelWidth*));
InflateRect(Rect,-2,-2);
DrawText(Handle, PChar(Cells[OCol1,ORow1]), -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