用StringGrid如何合并标题头,像这样(性别占两格):
_______________
|____性别_____|
|__男__|__女__|
|______|______|

解决方案 »

  1.   

    要用实现楼主的功能,用用StringGrid不行吧
    找一个第三方控件试试了
      

  2.   

    delphi7下安装EhLib 3.0老提示某个pas文件找不到
    其实在common目录下是有的
    听说要吧common目录添加到编译目录中,有谁知道怎么加吗
    谢谢
      

  3.   

    是GridEH吧。用StringGrid怎么不能实现?一种是设计其的,另一种是你Draw Cell啊。----------------------------------------------------------
    事太多、心太乱
        
      

  4.   

    ihihonline(小小) :
    用StringGrid可以实现合并标题头?怎么做可以说说吗,谢谢
      

  5.   

    是StringGrid的Draw Cell方法吗?
    请讲详细一点,多谢了
      

  6.   

    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
      if (ACol=x) and (ARow=y) then
      begin
        StringGrid1.Canvas..... // 在这里把这个 Rect 分为两部分
      end;
    end;
      

  7.   

    alexzhang00(badguy):
    你说的DM控件全名叫什么,哪有下
      

  8.   

    我曾做过类似的表格,方法很笨,就是用两个StringGrid重叠起来,记得我是用5个StringGrid叠在一起组成了一个更复杂的表。
      

  9.   

    当然可以使用 TStringGrid 控件, 只是需要把固定列的线设为空, 然后自己画线和画标题即可, 不过有点麻烦.
      

  10.   

    delphi7下安装EhLib 3.0老提示某个pas文件找不到
    其实在common目录下是有的
    听说要吧common目录添加到编译目录中,有谁知道怎么加吗
    谢谢
    --------------
    我实验过,只要把common目录下的所有文件拷贝到delphi7那个文件夹下就可以了。
      

  11.   

    delphi菜单tools/Environment Options/Library里把common目录加入就行了不过Ehlib不能添加列标题啊
      

  12.   

    object Form1: TForm1
      Left = 192
      Top = 107
      Width = 394
      Height = 312
      Caption = 'Form1'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      OldCreateOrder = False
      OnCreate = FormCreate
      PixelsPerInch = 96
      TextHeight = 13
      object StringGrid1: TStringGrid
        Left = 0
        Top = 0
        Width = 386
        Height = 285
        Align = alClient
        ColCount = 2
        FixedCols = 0
        FixedRows = 2
        Options = [goVertLine, goHorzLine, goRangeSelect, goColSizing]
        TabOrder = 0
        OnDrawCell = StringGrid1DrawCell
        ColWidths = (
          111
          109)
      end
    end
      

  13.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      Grids;type
      TForm1 = class(TForm)
        StringGrid1: TStringGrid;
        procedure FormCreate(Sender: TObject);
        procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
                      ARect: TRect; AState: TGridDrawState);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
    begin
       with StringGrid1 do
       begin
          Cells[0, 0] := '性';
          Cells[1, 0] := '别';
          Cells[0, 1] := '男';
          Cells[1, 1] := '女';
       end;
    end;procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
                ARect: TRect; AState: TGridDrawState);
    var
       strValue: String;
       intMargin, intHeight, intWidth: Integer;
    begin
       with TStringGrid(Sender) do
       begin
          // 画背景
          if gdFixed in AState then
             Canvas.Brush.Color := FixedColor
          else
             Canvas.Brush.Color := Color;
          Canvas.FillRect(ARect);      // 计算显示在矩形框中的左上角位置
          strValue := Cells[ACol, ARow];
          Canvas.Font := Font;
          intWidth := Canvas.TextWidth(strValue);
          if (ARow = 0) and (ACol = 0) then
             intMargin := ARect.Right - ARect.Left - intWidth - 6
          else if (ARow = 0) and (ACol = 1) then
             intMargin := 6
          else
          begin
             intMargin := (ARect.Right - ARect.Left - intWidth) div 2;
             if intMargin < 0 then
                intMargin := 0;
          end;      // 在矩形框中写值
          intHeight := (ARect.Bottom - ARect.Top - Canvas.TextHeight(strValue)) div 2;
          Canvas.TextRect(ARect, ARect.Left + intMargin, ARect.Top + intHeight, strValue);      // 画线
          if gdFixed in AState then
          begin
             Canvas.Pen.Mode := pmCopy;
             Canvas.Pen.Style := psSolid;
             Canvas.Pen.Width := 1;         // 上边和左边线
             Canvas.Pen.Color := clWhite;
             Canvas.PenPos := Point(ARect.Right, ARect.Top);
             Canvas.LineTo(ARect.Left, ARect.Top);
             if (ARow <> 0) or (ACol <> 1) then
                Canvas.LineTo(ARect.Left, ARect.Bottom);         // 下边和右边线
             Canvas.Pen.Color := clBtnShadow;
             Canvas.PenPos := Point(ARect.Left, ARect.Bottom);
             Canvas.LineTo(ARect.Right, ARect.Bottom);
             if (ARow <> 0) or (ACol <> 0) then
                Canvas.LineTo(ARect.Right, ARect.Top);
          end;
       end;
    end;end.
      

  14.   

    DM下载地址
    http://www.2ccc.com