实例4
本例功能:
1、给每个单元格赋值
2、调整当前单元格位置:上下左右;
运行效果图:
type
TForm12 = class(TForm)
StringGrid1: TStringGrid;
StringColumn1: TStringColumn;
StringColumn2: TStringColumn;
StringColumn3: TStringColumn;
StringColumn4: TStringColumn;
StringColumn5: TStringColumn;
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form12: TForm12;
implementation
{赋值}
procedure TForm12.FormCreate(Sender: TObject);
var
i,j: Integer;
begin
with StringGrid1 do
for i := 0 to ColumnCount - 1 do
for j := 0 to RowCount - 1 do
Cells[i,j] := Format('%d%d',[i,j]);
end;
procedure TForm12.Button1Click(Sender: TObject);
begin
if StringGrid1.ColumnIndex < StringGrid1.ColumnCount-1 then
StringGrid1.ColumnIndex := StringGrid1.ColumnIndex + 1;
Button1.Text:='单元格右移';
end;
procedure TForm12.Button2Click(Sender: TObject);
begin
if StringGrid1.ColumnIndex > 0 then
StringGrid1.ColumnIndex := StringGrid1.ColumnIndex- 1;
Button2.Text:='单元格左移';
end;
procedure TForm12.Button3Click(Sender: TObject);
begin
if StringGrid1.Selected< StringGrid1.RowCount-1 then
StringGrid1.Selected := StringGrid1.Selected+ 1;
Button3.Text:='单元格上移';
end;
procedure TForm12.Button4Click(Sender: TObject);
begin
if StringGrid1.Selected > 0 then
StringGrid1.Selected := StringGrid1.Selected- 1;
Button4.Text:='单元格下移';
end;
end.
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步