unit4.pas

来自「通过一个界面实例」· PAS 代码 · 共 70 行

PAS
70
字号
unit Unit4;

interface

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

type
  TForm4 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    StringGrid1: TStringGrid;
    BitBtn1: TBitBtn;
    procedure addbutton;
    procedure FormShow(Sender: TObject);
    procedure ButtonClick(Sender:Tobject);
  private
    { Private declarations }
  public
    { Public declarations }
    MyButton:array of TButton;
    n:integer;//试题总数
    r,c:integer;//当前行号,列号
  end;

var
  Form4: TForm4;

implementation

{$R *.dfm}

procedure TForm4.addbutton;
begin
//动态生成按键
  mybutton[c]:=Tbutton.Create(form4.StringGrid1);
  mybutton[c].Parent:=form4.StringGrid1;
  mybutton[c].Name:='B'+inttostr(c);
  mybutton[c].ParentToClient(form4.StringGrid1.BoundsRect.TopLeft);
  mybutton[c].Left:=StringGrid1.ColWidths[1]+StringGrid1.ColWidths[1]+StringGrid1.ColWidths[1];
  mybutton[c].Top:=form4.StringGrid1.RowHeights[c-1];
  mybutton[c].Caption:='查看';
  mybutton[c].Width:=form4.StringGrid1.ColWidths[4];
  mybutton[c].OnClick:=form4.ButtonClick;
end;

procedure TForm4.ButtonClick(Sender: Tobject);
begin
//
end;

procedure TForm4.FormShow(Sender: TObject);
var l,m:integer;
begin
//
  l:=form4.StringGrid1.RowCount-1;
  SetLength(MyButton,l);
  for m:=1 to l do
  begin
    c:=m+1;
    form4.addbutton;
  end;


end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?