Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Visual Inheritance of Base From With Tab Control
Message
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
00952975
Message ID:
00953957
Views:
16
Hi Joe,

You can inherit from a form and add controls in the tab control from the base class. If your controls are disappearing in the inherited form then that typically means there is a property in the inherited form that doesn't exist in the base class anymore. If there is an error or it can't match up the properties, the control will disappear in the designer.

>I have created a base form with a tab control and a couple of buttons and a datatgrid on it. I want the first page to show a list of records and the second tab will have the detail for the selected record. I have a number of places this would be useful, so I created a base class of this object.
>
>Next, I created a form that inherits from this base class form and added some controls to the tab. The designer allowed me to add these controls and displayed them until I compiled the application. After compilation, I could not see the controls in design or run time mode. However, if I look at the code, I can see that the code for the controls is present.
>
>Is it possible to Inherit a form with a tab control and add controls to the tab? If so, what do I need to do to allow this to happen. I also tried it with a panel and came up with the same results.
>
>I can't imagine what good these container type controls would be on a base form if you can't add controls to them on the derived form.
>
>Below is the code for the base form:
>
>Public Class FormBase2
>    Inherits System.Windows.Forms.Form
>
>#Region " Windows Form Designer generated code "
>
>    Public Sub New()
>        MyBase.New()
>
>        'This call is required by the Windows Form Designer.
>        InitializeComponent()
>
>        'Add any initialization after the InitializeComponent() call
>
>    End Sub
>
>    'Form overrides dispose to clean up the component list.
>    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
>        If disposing Then
>            If Not (components Is Nothing) Then
>                components.Dispose()
>            End If
>        End If
>        MyBase.Dispose(disposing)
>    End Sub
>
>    'Required by the Windows Form Designer
>	Private components As System.ComponentModel.IContainer
>
>    'NOTE: The following procedure is required by the Windows Form Designer
>    'It can be modified using the Windows Form Designer.
>    'Do not modify it using the code editor.
>	Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
>	Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
>	Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
>	Friend WithEvents Panel1 As System.Windows.Forms.Panel
>	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
>		Me.TabControl1 = New System.Windows.Forms.TabControl
>		Me.TabPage1 = New System.Windows.Forms.TabPage
>		Me.TabPage2 = New System.Windows.Forms.TabPage
>		Me.Panel1 = New System.Windows.Forms.Panel
>		Me.TabControl1.SuspendLayout()
>		Me.SuspendLayout()
>		'
>		'TabControl1
>		'
>		Me.TabControl1.Controls.Add(Me.TabPage1)
>		Me.TabControl1.Controls.Add(Me.TabPage2)
>		Me.TabControl1.Location = New System.Drawing.Point(8, 8)
>		Me.TabControl1.Name = "TabControl1"
>		Me.TabControl1.SelectedIndex = 0
>		Me.TabControl1.Size = New System.Drawing.Size(272, 248)
>		Me.TabControl1.TabIndex = 0
>		'
>		'TabPage1
>		'
>		Me.TabPage1.Location = New System.Drawing.Point(4, 22)
>		Me.TabPage1.Name = "TabPage1"
>		Me.TabPage1.Size = New System.Drawing.Size(264, 222)
>		Me.TabPage1.TabIndex = 0
>		Me.TabPage1.Text = "List"
>		'
>		'TabPage2
>		'
>		Me.TabPage2.Location = New System.Drawing.Point(4, 22)
>		Me.TabPage2.Name = "TabPage2"
>		Me.TabPage2.Size = New System.Drawing.Size(264, 222)
>		Me.TabPage2.TabIndex = 1
>		Me.TabPage2.Text = "Detail"
>		'
>		'Panel1
>		'
>		Me.Panel1.Location = New System.Drawing.Point(328, 32)
>		Me.Panel1.Name = "Panel1"
>		Me.Panel1.Size = New System.Drawing.Size(304, 208)
>		Me.Panel1.TabIndex = 1
>		'
>		'FormBase2
>		'
>		Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
>		Me.ClientSize = New System.Drawing.Size(648, 266)
>		Me.Controls.Add(Me.Panel1)
>		Me.Controls.Add(Me.TabControl1)
>		Me.Name = "FormBase2"
>		Me.Text = "FormBase2"
>		Me.TabControl1.ResumeLayout(False)
>		Me.ResumeLayout(False)
>
>	End Sub
>
>#End Region
>
>End Class
>
>
>And here is the code for the derived form:
>
>Public Class InheritsFromBase2
>    Inherits TestDocking.FormBase2
>
>#Region " Windows Form Designer generated code "
>
>    Public Sub New()
>        MyBase.New()
>
>        'This call is required by the Windows Form Designer.
>        InitializeComponent()
>
>        'Add any initialization after the InitializeComponent() call
>
>    End Sub
>
>    'Form overrides dispose to clean up the component list.
>    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
>        If disposing Then
>            If Not (components Is Nothing) Then
>                components.Dispose()
>            End If
>        End If
>        MyBase.Dispose(disposing)
>    End Sub
>
>    'Required by the Windows Form Designer
>	Private components As System.ComponentModel.IContainer
>
>    'NOTE: The following procedure is required by the Windows Form Designer
>    'It can be modified using the Windows Form Designer.
>    'Do not modify it using the code editor.
>	Friend WithEvents Button1 As System.Windows.Forms.Button
>	Friend WithEvents Button2 As System.Windows.Forms.Button
>	Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
>	Friend WithEvents Panel2 As System.Windows.Forms.Panel
>	Friend WithEvents Label1 As System.Windows.Forms.Label
>	Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
>	Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
>	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
>		Me.Button1 = New System.Windows.Forms.Button
>		Me.Button2 = New System.Windows.Forms.Button
>		Me.TextBox2 = New System.Windows.Forms.TextBox
>		Me.Panel2 = New System.Windows.Forms.Panel
>		Me.TextBox1 = New System.Windows.Forms.TextBox
>		Me.Label1 = New System.Windows.Forms.Label
>		Me.CheckBox1 = New System.Windows.Forms.CheckBox
>		Me.Panel2.SuspendLayout()
>		'
>		'Button1
>		'
>		Me.Button1.Location = New System.Drawing.Point(120, 24)
>		Me.Button1.Name = "Button1"
>		Me.Button1.TabIndex = 0
>		Me.Button1.Text = "Button1"
>		'
>		'Button2
>		'
>		Me.Button2.Location = New System.Drawing.Point(104, 32)
>		Me.Button2.Name = "Button2"
>		Me.Button2.TabIndex = 0
>		Me.Button2.Text = "Button2"
>		'
>		'TextBox2
>		'
>		Me.TextBox2.Location = New System.Drawing.Point(72, 72)
>		Me.TextBox2.Name = "TextBox2"
>		Me.TextBox2.TabIndex = 2
>		Me.TextBox2.Text = "TextBox2"
>		'
>		'Panel2
>		'
>		Me.Panel2.Controls.Add(Me.TextBox1)
>		Me.Panel2.Controls.Add(Me.Label1)
>		Me.Panel2.Location = New System.Drawing.Point(32, 80)
>		Me.Panel2.Name = "Panel2"
>		Me.Panel2.Size = New System.Drawing.Size(280, 144)
>		Me.Panel2.TabIndex = 1
>		'
>		'TextBox1
>		'
>		Me.TextBox1.Location = New System.Drawing.Point(40, 56)
>		Me.TextBox1.Name = "TextBox1"
>		Me.TextBox1.TabIndex = 1
>		Me.TextBox1.Text = "TextBox1"
>		'
>		'Label1
>		'
>		Me.Label1.Location = New System.Drawing.Point(48, 24)
>		Me.Label1.Name = "Label1"
>		Me.Label1.TabIndex = 0
>		Me.Label1.Text = "Label1"
>		'
>		'CheckBox1
>		'
>		Me.CheckBox1.Location = New System.Drawing.Point(176, 64)
>		Me.CheckBox1.Name = "CheckBox1"
>		Me.CheckBox1.TabIndex = 0
>		Me.CheckBox1.Text = "CheckBox1"
>		'
>		'InheritsFromBase2
>		'
>		Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
>		Me.ClientSize = New System.Drawing.Size(656, 278)
>		Me.Name = "InheritsFromBase2"
>		Me.Text = "InheritsFromBase2"
>		Me.Panel2.ResumeLayout(False)
>
>	End Sub
>
>#End Region
>
>End Class
>
>
>Thanks,
>Joe
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Reply
Map
View

Click here to load this message in the networking platform