我作了一个小程序,可以在窗体上动态生成一些控件,现在我想修改他的属性,比如在程序运行时双击该控件,弹出一个窗体,可以在里面修改他的属性,如大小,颜色等等.请问编程思路是什么样子,属性窗体应该怎么处理?

解决方案 »

  1.   

    属性窗体就是一个普通的form,你在里边添加需要的控件,编制需要的代码。
    关键是你双击动态生成的那个控件时,要把控件的信息传递给属性窗体,然它知道是在对谁修改。
      

  2.   

    1、你必须为动态生成的控件定义 OnClick事件;
    2、在OnClick事件中,调出一个编辑窗体,在窗体上做一些Edit,比如 EditColor,EditWidth...;
    ...
      procedure proClick(sender;Tobject);
    ...
    Var
      AEdit:TEdit;
    begin
      Aedit:=Tedit.Create(self);
      Aedit.Clicked:=proClick;
    ...
    end;procedure proClick (sender:Tobject);
    begin
      Application.create(Tform1,form1);
      if form1.showmodal=mrok then 
        begin
        aedit.width:=strtoint(form1.editwidth.text);
        ...
        end;
      form1.free;
    end;
      

  3.   

    给你个刚写的例子,你可以参考:form1是主窗体,点button1生成新的BUTTON按钮BT,点击BT可以调出form2,form2上有一个label1,当form2调出的时候,label1显示BT的信息。unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
      private    procedure btOnclick(sender : tobject);
      public  end;var
      Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.btOnclick(sender: tobject);
    begin   form2.Label1.Caption := inttostr((sender as TButton).Left);
       Form2.ShowModal;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
    bt : TButton;
    begin
        bt := TButton.Create(nil);
        bt.Parent := Form1;
        bt.Left := 100;
        bt.Top :=100;
        bt.Width := 50;
        bt.Height := 50;
        bt.OnClick := btOnclick;
    end;end.
      

  4.   

    改变动态生成的窗体的颜色
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        ColorDialog1: TColorDialog;
        procedure Button1Click(Sender: TObject);
        procedure MyFormDblClick(Sender: TObject);
        procedure aButtonClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      MyForm:TForm;
    implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      MyForm:=TForm.Create(self);
      MyForm.OnDblClick:=MyFormDblClick;
      MyForm.Show;
    end;procedure TForm1.aButtonClick(Sender: TObject);
    begin
     if ColorDialog1.Execute then
      MyForm.Color:=ColorDialog1.Color;
    end;procedure TForm1.MyFormDblClick(Sender: TObject);
    var aForm:TForm;
        aButton:TButton;
    begin
      aForm:=TForm.Create(self);
      aForm.Caption:='改变动态生成的窗体的颜色';
      aForm.Position:=poDesktopCenter;
      aButton:=TButton.Create(aForm);
      aButton.Parent:=aForm;
      aButton.Caption:='改变颜色';
      aButton.Left:=120;
      aButton.Top:=80;
      aButton.OnClick:=aButtonClick;
      aForm.Show;
    end;end.
      

  5.   

    正如wudi_1982所说,在确定属性窗体修改哪个控件是遇到麻烦.这部分是自己写代码还是用消息或其他方法.