Get Component's Parent Form

后端 未结 10 1011
再見小時候
再見小時候 2020-12-03 01:40

I have a non-visual component which manages other visual controls.

I need to have a reference to the form that the component is operating on, but i don\'t know how

10条回答
  •  执笔经年
    2020-12-03 01:43

    Try This ....

    private Form GetParentForm(Control parent)
    {
        if (parent is Form)
            return parent as Form;
    
        return parent.FindForm();
    }
    

    Call GetParentForm(this.Parent) from component

提交回复
热议问题