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

priyamtheone

Well-known member
Joined
Sep 20, 2007
Messages
94
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?
 

Dunfiddlin

Well-known member
Joined
Jun 15, 2012
Messages
253
Programming Experience
5-10
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.
 

priyamtheone

Well-known member
Joined
Sep 20, 2007
Messages
94
Programming Experience
Beginner
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.
 

Dunfiddlin

Well-known member
Joined
Jun 15, 2012
Messages
253
Programming Experience
5-10
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()
 

priyamtheone

Well-known member
Joined
Sep 20, 2007
Messages
94
Programming Experience
Beginner
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.
 
Top Bottom