本例功能:
1、调整单元宽度;
2、调整单元高度.

运行效果图:


//本例代码:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Panel1: TPanel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{单元宽+}
procedure TForm1.Button1Click(Sender: TObject);
begin
  TButton(Sender).Caption := '单元宽+';
  with StringGrid1 do
    ColWidths[Col] := ColWidths[Col] * 2;
end;

{单元宽-}
procedure TForm1.Button2Click(Sender: TObject);
begin
  TButton(Sender).Caption := '单元宽-';
  with StringGrid1 do
    ColWidths[Col] := ColWidths[Col] div 2;
end;

{单元高+}
procedure TForm1.Button3Click(Sender: TObject);
begin
  TButton(Sender).Caption := '单元高+';
  with StringGrid1 do
    RowHeights[Row] := RowHeights[Row] * 2;
end;

{单元高-}
procedure TForm1.Button4Click(Sender: TObject);
begin
  TButton(Sender).Caption := '单元高-';
  with StringGrid1 do
    RowHeights[Row] := RowHeights[Row] div 2;
end;

end.

posted on 2008-03-05 14:58  万一  阅读(5677)  评论(2编辑  收藏  举报