Question Problem in inherited form (VS.Net 2010, WinForms).

priyamtheone

Well-known member
Joined
Sep 20, 2007
Messages
96
Programming Experience
Beginner
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 to my project from MyForm, its Text property remains blank by default. I even tried to set it in MyForm's constructor, yet it isn't working. How to solve this?
 
Unless you've overridden the property in some way this should be as easy as

Dim form2 As Class1 = New Class1
form2.Text = "Hello"
form2.Show()

Works for me, anyway.
 
When I add an inherited form to my project from MyForm through the 'Add New Item' dialog box, I enter the name of the form that I want to add in the 'Name' TextBox of the 'Add New Item' dialog box and click 'Add'. Now when a new standard form is added to a project in the same way, its Text property holds the name of the form itself by default. That's what is not happening when I add the new form based on MyForm. Hope I'm more clear this time.
 
The naming of forms is done by the design IDE. It is not part of the Form Class.

Dim form2 As Class1 = New Class1
form2.Name = "MyForm"
form2.Text = form2.Name
form2.Show()
 
Yeah, I figured that out. 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. Thanks Dunfiddlin.
 
Back
Top