1、修改 StringGrid 单元的默认宽与高;
2、添加行和列;
3、确认当前单元并赋值.
运行效果图:
//本例代码:
unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls, ExtCtrls, Grids;typeTForm1 = class(TForm)StringGrid1: TStringGrid;Panel1: TPanel;Button1: TButton;Button2: TButton;Button3: TButton;procedure Button1Click(Sender: TObject);procedure StringGrid1Click(Sender: TObject);procedure Button2Click(Sender: TObject);procedure Button3Click(Sender: TObject);end;varForm1: TForm1;implementation{$R *.dfm}{修改单元宽度与高度}
procedure TForm1.Button1Click(Sender: TObject);
beginStringGrid1.DefaultColWidth := 56;StringGrid1.DefaultRowHeight := 18;TButton(Sender).Caption := '宽与高';
end;{添加一行}
procedure TForm1.Button2Click(Sender: TObject);
beginStringGrid1.RowCount := StringGrid1.RowCount + 1;TButton(Sender).Caption := '加一行';
end;{添加一列}
procedure TForm1.Button3Click(Sender: TObject);
beginStringGrid1.ColCount := StringGrid1.ColCount + 1;TButton(Sender).Caption := '加一列';
end;{当前单元}
procedure TForm1.StringGrid1Click(Sender: TObject);
varc,r: Integer;
beginc := StringGrid1.Col; {当前列}r := StringGrid1.Row; {当前行}StringGrid1.Cells[c,r] := Format('列:%d;行:%d', [c,r]);
end;end.