简体   繁体   English

C#子窗体从父窗体继承控件

[英]C# Child Form Inheriting a Control from Parent Form

The way my application is organized is I have a base form and multiple child forms that inherit from it. 应用程序的组织方式是,我有一个基本表单和多个继承自它的子表单。 I also have a button defined as a UI control. 我也有一个定义为UI控件的按钮。 I want to add the UI control to the base form so all the child forms can also have that control. 我想将UI控件添加到基本表单中,以便所有子表单也可以具有该控件。 However, I don't want to mess with all the individual child forms because the control should be the same for all of them. 但是,我不想弄乱所有子窗体,因为所有窗体的控件都应该相同。 What I have done so far: Added the control to the designer of baseFrom.cs, which in turn created a InitializeComponent() function in the base form that listed all the properties of the control. 到目前为止,我已经做的事情:将控件添加到baseFrom.cs的设计器中,后者又以基本形式创建了InitializeComponent()函数,该函数列出了控件的所有属性。 I have tried calling the InitializeComponent in the base form's constructor but that still does not make the control appear in any of the child forms. 我试过在基本窗体的构造函数中调用InitializeComponent,但这仍然不能使控件出现在任何子窗体中。 What am I missing here? 我在这里想念什么?

在将控件添加到基本表单后,您需要构建解决方案,然后控件将以继承的形式出现

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM