本文整理自网络,侵删。
实例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.
来源:https://www.cnblogs.com/lingzhiwen/p/3322570.html
相关阅读 >>
Delphi opendialog1 savedialog1 默认路径
Delphi api 函数中使用 pchar 参数的几种方法
Delphi 2009 之 tcategorypanelgroup[2]: headeralignment、gradientdirection
Delphi winapi: getactivewindow - 获取当前活动窗口的句柄
更多相关阅读请进入《Delphi》频道 >>