+ -
当前位置:首页 → 问答吧 → 还是TAdvStringGrid的问题,高手来吧

还是TAdvStringGrid的问题,高手来吧

时间:2011-12-01

来源:互联网



如上图黄色单元格位置
我用如下代码,给单元格添加了边框

procedure TForm4.HNsGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
  var
  temp: TRect;
begin
  if (HNsGrid1.Focused) and (HNsGrid1.Col = ACol) and (HNsGrid1.Row = ARow) then
  begin

  temp.top := Rect.top-3;
  temp.left := Rect.Left-3;
  temp.right := Rect.right-1;
  temp.Bottom := Rect.Bottom-1;

  HNsGrid1.Canvas.Pen.Color := clBlack;
  HNsGrid1.Canvas.Brush.color := clRed;
  HNsGrid1.Canvas.Brush.Style := bsClear;
  HNsGrid1.Canvas.Pen.Width := 5;

  HNsGrid1.Canvas.Rectangle(temp);

  end;
end;

但是出来的效果,如图所示
上和左的边框出来了,右和下的边框不知道为什么被遮挡住了。
大家遇到过没?
求解决办法,谢谢了

作者: lzc2125   发布时间: 2011-12-01

-1,多减点试试呢

作者: bdmh   发布时间: 2011-12-01

引用 1 楼 bdmh 的回复:

-1,多减点试试呢


不行的,无论怎么调都不行

作者: lzc2125   发布时间: 2011-12-01

请参考!
Delphi(Pascal) code

procedure TForm1.AdvStringGrid1DrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
var
  s: string;
begin
  s := AdvStringGrid1.Cells[ACol, ARow];
  if ARow mod 2 = 0 then
  begin
    AdvStringGrid1.Canvas.Font.Color := clBlack;
    AdvStringGrid1.Canvas.Brush.Color := $00FFCACA;
    AdvStringGrid1.Canvas.FillRect(Rect);
    AdvStringGrid1.Canvas.TextOut(Rect.Left, Rect.top, s);
  end;

  if gdFocused in State then
  begin
    AdvStringGrid1.Canvas.Brush.Color := clYellow;
    AdvStringGrid1.Canvas.FillRect(Rect);
    AdvStringGrid1.Canvas.Pen.Width := 3;
    AdvStringGrid1.Canvas.Pen.Color := clBlue;
    AdvStringGrid1.Canvas.Pen.Style := psInsideFrame;
    AdvStringGrid1.Canvas.Rectangle(AdvStringGrid1.CellRect(ACol, ARow));
    AdvStringGrid1.Canvas.TextOut(Rect.Left + 5, Rect.top +3, s);
    AdvStringGrid1.Canvas.Brush.Color := clBlue;
    AdvStringGrid1.Canvas.DrawFocusRect(AdvStringGrid1.CellRect(ACol, ARow));
  end;
end;

作者: jayqiang   发布时间: 2011-12-01

热门下载

更多