Kinger247
asked on
Form Inheritance Question.
I've created a class (cForm) that Inherits a another form (iForm).
So, the class (cForm) is derived from the (iForm) form ....
When I add controls to the inherited form (cForm) they do not appear at runtime … am I missing something ?
So, the class (cForm) is derived from the (iForm) form ....
When I add controls to the inherited form (cForm) they do not appear at runtime … am I missing something ?
What code are you using to add them ? And where have you put the code ?
ASKER
This is the code thatwas generated in the form when I dropped the controls onto it.
The IMDIForm doesn't have any controls on it, just a few additional procedures.
Public Class frmSearch
Inherits Infinity_MDI.IMDIForm
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Butto n
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(38, 32)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleB ackColor = True
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(52, 78)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(39, 13)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Label1"
'
'frmSearch
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Button1 )
Me.Name = "frmSearch"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Butto n
End Class
The IMDIForm doesn't have any controls on it, just a few additional procedures.
Public Class frmSearch
Inherits Infinity_MDI.IMDIForm
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Butto
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(38, 32)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleB
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(52, 78)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(39, 13)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Label1"
'
'frmSearch
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!,
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Button1
Me.Name = "frmSearch"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Butto
End Class
Hi Kinger247;
If cForm is the startup form then make sure that the Property page for the project, "Startup Form", is set to cForm and not iForm.
Fernando
If cForm is the startup form then make sure that the Property page for the project, "Startup Form", is set to cForm and not iForm.
Fernando
ASKER
There's actually an mdi form that loads a child form.
Its the child form that inherits from another form.
But as well as inheriting from another form, I need to place some controls on the form itself (which are nothing to do with the inherited form) and these controls are not displayed when I run the app.
Its the child form that inherits from another form.
But as well as inheriting from another form, I need to place some controls on the form itself (which are nothing to do with the inherited form) and these controls are not displayed when I run the app.
Can you post the code that loads the child form and displays it?
ASKER
Heres the code that opens the second form:
Dim Form As New frmSearch
Form.MdiParent = Me
Form.Text = "Search"
Form.Name = "Search"
Form.WindowState = FormWindowState.Maximized
Form.Show()
ASKER
Ok, this must be something I'bve missed or don't understand.
I just created a new project :
1. With a default form (Form1).
2. I then create a class (called MainForm) which inherits the main Form1. (this new class is now a subclass of Form1)
3. Change the startup form to (MainForm).
4. Add a button to (MainForm).
5 Run the application.
The MainForm is visible, but the button is not ....
In acutal fact, if I inherit from just "System.Windows.Forms.Form ", I still don't see the button ....
Heres my code:
'//-- CODE ---------------
Public Class MainForm
Inherits System.Windows.Forms.Form
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Butto n
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(34, 54)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleB ackColor = True
'
'MainForm
'
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Button1 )
Me.Name = "MainForm"
Me.ResumeLayout(False)
End Sub
Friend WithEvents Button1 As System.Windows.Forms.Butto n
End Class
Please Help !
I just created a new project :
1. With a default form (Form1).
2. I then create a class (called MainForm) which inherits the main Form1. (this new class is now a subclass of Form1)
3. Change the startup form to (MainForm).
4. Add a button to (MainForm).
5 Run the application.
The MainForm is visible, but the button is not ....
In acutal fact, if I inherit from just "System.Windows.Forms.Form
Heres my code:
'//-- CODE ---------------
Public Class MainForm
Inherits System.Windows.Forms.Form
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Butto
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(34, 54)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleB
'
'MainForm
'
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Button1
Me.Name = "MainForm"
Me.ResumeLayout(False)
End Sub
Friend WithEvents Button1 As System.Windows.Forms.Butto
End Class
Please Help !
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.