开发者

Detect adding control to form

开发者 https://www.devze.com 2023-03-04 08:56 出处:网络
Hi I开发者_JAVA技巧 write a component and need to when one control add to form i detect this event and add this control to my component list , is this possible ? (Design time)

Hi I开发者_JAVA技巧 write a component and need to when one control add to form i detect this event and add this control to my component list , is this possible ? (Design time)

excuse me for my poor english tnx


Do you mean System.Windows.Forms.Control.ControlAdded event?

EDIT: The event is raised in DesignTime either.

I created Form2 class:

public partial class Form2 : Form {
    public Form2() {
        InitializeComponent();

        this.ControlAdded += new ControlEventHandler(Form2_ControlAdded);
    }

    void Form2_ControlAdded(object sender, ControlEventArgs e) {
        this.Text += " " + e.Control.Name;
    }
}

And then I created Form3 class derived from Form2 class.

public partial class Form3 : Form2 {
    public Form3() {
        InitializeComponent();
    }
}

After that I recompiled solution, opened designer of Form3 class, added new Button from ToolBox and the Text property of form was changed from "Form3" to "Form3 button1".

0

精彩评论

暂无评论...
验证码 换一张
取 消