开发者

Detect adding control to form

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜