I built a ClassLibrary where I have created my custom form component (let's say MyForm) that inherits from the Form class. I added the ClassLibrary to my actual WinForms project. Now when I add an inherited form based on MyForm to my project through the 'Add New Item' dialog box for the first time, its Text property remains blank by default. But when you add a standard form to a project, its Text is set to its Name by default. This is what my requirement is. I even tried to set the Text property in MyForm's constructor, yet it isn't working. How to solve this?

Recommended Answers

All 3 Replies

From the MSVS 2008 documentation.

Modifications made to the base form at run time have no affect on inherited forms that are already instantiated.

If you make changes to the properties in the Designer at design-time, then the changes can be updated in the derived form. Changes made at run-time, even in a constructor, are not reflected in the derived form. You may need to explicitly call the base-class constructor as the first line of your derived forms constructor.

If you want to set a Default value for your property look into the DefaultValue Attribute.

I assume you want to have a value provided when you first add the form at design-time.

The naming of forms is done by the design IDE. It is not part of the Form Class.
The IDE sets the name of a form to its text by default when it is created from the 'Add New Item' dialog box. But it's not done in case of inherited forms. Seems I have to set a default text in MyForm's constructor.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.