Link to home
Start Free TrialLog in
Avatar of Kinger247
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 ?
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

What code are you using to add them ? And where have you put the code ?
Avatar of Kinger247
Kinger247

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.Button
        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.UseVisualStyleBackColor = 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.Button
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
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.
Can you post the code that loads the child form and displays it?

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()

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.Button
        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.UseVisualStyleBackColor = 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.Button
End Class


Please Help !
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial