【问题标题】:Programmatically drawing the lines in a delphi drawgrid and merge cells以编程方式在delphi drawgrid中绘制线条并合并单元格
【发布时间】:2013-06-26 18:43:40
【问题描述】:

我想禁用 drawgrid 中的网格线并自己为其他列绘制网格线。不需要行。

我想合并固定区域中的两个单元格,使其看起来像一列,如下图所示:

我已将此代码添加到 drawgrid 的 ondrawcell 事件中以实现此目的:

procedure Tbookings3_Frm.bgridDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  CellIndex: Integer;
    s:string;
  x:integer;
begin
  CellIndex := (ARow * bgrid.ColCount) + ACol;

  if gdFixed in State then
  begin
    bgrid.Canvas.Brush.Color := clskyblue;
  end
  else if (State * [gdSelected, gdHotTrack]) <> [] then
  begin
    bgrid.Canvas.Brush.Color := clHighlight;
  end
  else
  begin
    bgrid.Canvas.Brush.Color := Cells[CellIndex].BkColor;
  end;



  bgrid.Canvas.FillRect(Rect);

  if gdFixed in State then
    Frame3D(bgrid.Canvas, Rect, clHighlight, clBtnShadow, 1);

  if gdFocused in State then
    bgrid.Canvas.DrawFocusRect(Rect);

//---------------

  with (Sender as TDrawGrid).Canvas do
  begin
     // set font
    Font.Color := CLblack;
    FillRect(Rect);

    if ARow = 2 then
    begin
        x := (Rect.Right - Rect.Left - TextWidth(days_h[ACol])) div 2;
        TextOut(Rect.Left + x, Rect.Top + 2, days_h[ACol]);
    end;
  if ARow = 1 then
     begin
       x := (Rect.Right - Rect.Left - TextWidth(sun_mon[ACol])) div 2;
       TextOut(Rect.Left + x, Rect.Top + 2, sun_mon[ACol]);

     end;
  if ARow = 0 then
     begin
        x := (Rect.Right - Rect.Left - TextWidth(mon[ACol])) div 2;
        TextOut(Rect.Left + x, Rect.Top + 2, mon[ACol]);
      end;

  if (Acol = 0) and (ARow > 2) then
     begin
        s:=rooms[Arow];
        x := (Rect.Right - Rect.Left - TextWidth(s)) div 2;
        TextOut(Rect.Left + x, Rect.Top + 2, s);
     end;

//-------------------------------------------------



  end; //end canvas
//----------------
  if gdFocused in State then
    bgrid.Canvas.DrawFocusRect(Rect);
end;

【问题讨论】:

  • 请将图片直接嵌入问题中。不要让每个人都使用下载服务来获取图像。至少,使用真正的图像托管服务,这样我们就可以在不单独下载的情况下查看图像。
  • 我为他嵌入了图片。
  • 感谢您的信息。下次

标签: delphi delphi-xe2 pascal


【解决方案1】:

您需要禁用网格的原生网格线,然后您可以根据需要在OnDrawCell 事件中围绕每个单元格绘制自己的网格线。 TRect 代表正在绘制的单元格的内部区域,但您也可以在该 Rect 之外绘制。要使两个单元格看起来合并,您根本不需要在它们之间绘制网格线。

【讨论】:

  • 我对这个领域很陌生。能否请您提供一些示例代码
猜你喜欢
  • 2014-05-24
  • 2019-09-02
  • 1970-01-01
  • 1970-01-01
  • 2014-05-06
  • 1970-01-01
  • 2016-07-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多