0

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. I want to add the UI control to the base form so all the child forms can also have that control. 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. 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. What am I missing here?

Eddy221
  • 55
  • 1
  • 2
  • 7
  • Must be the "UI Control" you mentioned. Do you mean it's a `UserControl`? Or what... – DonBoitnott Jun 30 '16 at 12:52
  • Why dont you just add the button on the design of the parent? – Aimnox Jun 30 '16 at 12:53
  • @Aimnox Read: "What I have done so far: Added the control to the designer of baseFrom.cs" – DonBoitnott Jun 30 '16 at 12:54
  • @DonBoitnott: Yes, UserControl – Eddy221 Jun 30 '16 at 12:54
  • You'll probably have to post some UC code, or at least the ctor and Load() stuff. Controls should do exactly what you expect, so something's broken. – DonBoitnott Jun 30 '16 at 12:55
  • The designer is the ´Form1.Designer.cs´, a code tab that's autogenerated. Do you mean that or the visual design tab? – Aimnox Jun 30 '16 at 12:55
  • Do you create the base form using designer or using the code? If you are using designer, it would be simply putting a control from toolbox on the form surface. But if you are using code, take a look at the answer for this question: [Can't view designer when coding a form in C#](http://stackoverflow.com/questions/32298865/cant-view-designer-when-coding-a-form-in-c-sharp) – Reza Aghaei Jun 30 '16 at 13:02
  • I just added this line to the constructor and it worked for some reason: this.Controls.Add(cp_Button); – Eddy221 Jun 30 '16 at 13:04
  • If adding `this.Controls.Add(cp_Button);` solved your problem, it means you had forgotten to add the control to the form. You should not manipulate the codes in designer.cs manually. In fact you don't need to use code to create your base form. You can use designer like you use for other forms. – Reza Aghaei Jun 30 '16 at 13:09
  • Does your child form constructor call the base constructor? – JamesFaix Jun 30 '16 at 13:11
  • @JamesFaix You do not need to explicitly call the base constructor, it will be implicitly called. – Reza Aghaei Jun 30 '16 at 13:40

1 Answers1

0

after you add control to base form you need to build solution and then control will appear in inherited forms

Giorgi_Mdivani
  • 373
  • 1
  • 5
  • 12