0

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

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

合并列的网格

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

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;
4

1 回答 1

1

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

于 2013-06-26T19:11:36.253 回答