本例功能:
1、修改 StringGrid 单元的默认宽与高;
2、添加行和列;
3、确认当前单元并赋值.
运行效果图:
1、修改 StringGrid 单元的默认宽与高;
2、添加行和列;
3、确认当前单元并赋值.
运行效果图:
//本例代码: 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; procedure Button1Click(Sender: TObject); procedure StringGrid1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} {修改单元宽度与高度} procedure TForm1.Button1Click(Sender: TObject); begin StringGrid1.DefaultColWidth := 56; StringGrid1.DefaultRowHeight := 18; TButton(Sender).Caption := '宽与高'; end; {添加一行} procedure TForm1.Button2Click(Sender: TObject); begin StringGrid1.RowCount := StringGrid1.RowCount + 1; TButton(Sender).Caption := '加一行'; end; {添加一列} procedure TForm1.Button3Click(Sender: TObject); begin StringGrid1.ColCount := StringGrid1.ColCount + 1; TButton(Sender).Caption := '加一列'; end; {当前单元} procedure TForm1.StringGrid1Click(Sender: TObject); var c,r: Integer; begin c := StringGrid1.Col; {当前列} r := StringGrid1.Row; {当前行} StringGrid1.Cells[c,r] := Format('列:%d;行:%d', [c,r]); end; end.