在DrawGrid中怎样实现重画以及如何合并单元格(50分)

  • 主题发起人 主题发起人 luogt
  • 开始时间 开始时间
L

luogt

Unregistered / Unconfirmed
GUEST, unregistred user!
在DrawGrid中怎样实现重画以及如何合并单元格?
请各位大师指点指点!
 
用三方控件把。
 
StringGrid合并单元格(转载)

procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.DefaultDrawing :=False;
StringGrid1.Cells[1,1] := '111';
StringGrid1.Cells[3,1] := '222';
//StringGrid1.DefaultDrawing :=False; //不用系统默认风格 选择自己画
StringGrid1.Cells[1,4] := '总结:';
StringGrid1.Cells[3,4] := '内容';
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
StringGrid1.Canvas.Font.Assign(StringGrid1.Font);//制定字体
with StringGrid1.Canvas do begin
Brush.Color := clWindow; //制定边框颜色
Font.Color := clWindowText;

//下面是设定合并列 合并标题栏 和第四行
if ((acol=1) or (acol=3)) and ((ARow=0) or (ARow=4))then
rect.Right:=rect.Right+rect.Right-rect.Left;
if ((acol=2) or (acol=4)) and ((ARow=0) or (ARow=4))then
rect.Left:=rect.Right;

if gdFixed in State then Brush.Color := StringGrid1.FixedColor;
//填充合并rect
FillRect(Rect);
with StringGrid1 do
TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Cells[ACol, ARow]);
if gdFixed in State then DrawEdge(Handle, Rect, BDR_RAISEDINNER, BF_RECT);
end;
end;
 
后退
顶部