Tab Controls..

  • Thread starter Thread starter VJ
  • Start date Start date
V

VJ

I am looking to have 2 Tab Controls on a Windows Forms.. One with Tabs on
Top and another with Tabs on the side... I want them both to occupy the
entire area of the form, but I need the Tab Headers to be visible for both
of them .. at all times... How do I accomplish this?

Also can One Tab control have Tab Headers on Top and Side.. at the same
time?..That might solve this problem easily :-)

Thanks
Vijay
 
* "VJ said:
I am looking to have 2 Tab Controls on a Windows Forms.. One with Tabs on
Top and another with Tabs on the side... I want them both to occupy the
entire area of the form, but I need the Tab Headers to be visible for both
of them .. at all times... How do I accomplish this?

Also can One Tab control have Tab Headers on Top and Side.. at the same
time?..That might solve this problem easily :-)

Set the tabcontrol's 'Alignment' property to a value <> 'Top' and then
reset it to 'Top'. This will show the tabs in multiple rows if required.
 
Yea that part I get it.. But I won't have the Top and Side tabs visible at
the same time?.. Or did I miss something?

Vijay
 
* "VJ said:
Yea that part I get it.. But I won't have the Top and Side tabs visible at
the same time?.. Or did I miss something?

AFAIK, that's not supported.
 
VJ,
I would add two tab controls to the form, one with alignment Top & one with
alignment Left (or Right). I would either size both controls so only the
tabs were visible, or attempt to overlay & offset one control on top of the
other. Depending on what is being displayed in the center (what "Tab pages"
were being displayed.

If I went with overlaying & offset controls, I would handle the
Tabcontrol.Clicked event to bring that control to the front.

Something like:

Public Class TabbedForm
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.
Private WithEvents TabControl1 As System.Windows.Forms.TabControl
Private WithEvents TabPage1 As System.Windows.Forms.TabPage
Private WithEvents TabPage2 As System.Windows.Forms.TabPage
Private WithEvents TabControl2 As System.Windows.Forms.TabControl
Private WithEvents TabPage3 As System.Windows.Forms.TabPage
Private WithEvents TabPage4 As System.Windows.Forms.TabPage
Private WithEvents Label1 As System.Windows.Forms.Label
Private WithEvents Label2 As System.Windows.Forms.Label
Private WithEvents Label3 As System.Windows.Forms.Label
Private WithEvents Label4 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.TabControl1 = New System.Windows.Forms.TabControl
Me.TabPage1 = New System.Windows.Forms.TabPage
Me.Label1 = New System.Windows.Forms.Label
Me.TabPage2 = New System.Windows.Forms.TabPage
Me.Label2 = New System.Windows.Forms.Label
Me.TabControl2 = New System.Windows.Forms.TabControl
Me.TabPage3 = New System.Windows.Forms.TabPage
Me.Label3 = New System.Windows.Forms.Label
Me.TabPage4 = New System.Windows.Forms.TabPage
Me.Label4 = New System.Windows.Forms.Label
Me.TabControl1.SuspendLayout()
Me.TabPage1.SuspendLayout()
Me.TabPage2.SuspendLayout()
Me.TabControl2.SuspendLayout()
Me.TabPage3.SuspendLayout()
Me.TabPage4.SuspendLayout()
Me.SuspendLayout()
'
'TabControl1
'
Me.TabControl1.Controls.Add(Me.TabPage1)
Me.TabControl1.Controls.Add(Me.TabPage2)
Me.TabControl1.Location = New System.Drawing.Point(32, 8)
Me.TabControl1.Name = "TabControl1"
Me.TabControl1.SelectedIndex = 0
Me.TabControl1.Size = New System.Drawing.Size(256, 248)
Me.TabControl1.TabIndex = 0
'
'TabPage1
'
Me.TabPage1.Controls.Add(Me.Label1)
Me.TabPage1.Location = New System.Drawing.Point(4, 25)
Me.TabPage1.Name = "TabPage1"
Me.TabPage1.Size = New System.Drawing.Size(248, 219)
Me.TabPage1.TabIndex = 0
Me.TabPage1.Text = "TabPage1"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(72, 80)
Me.Label1.Name = "Label1"
Me.Label1.TabIndex = 0
Me.Label1.Text = "Label1"
'
'TabPage2
'
Me.TabPage2.Controls.Add(Me.Label2)
Me.TabPage2.Location = New System.Drawing.Point(4, 25)
Me.TabPage2.Name = "TabPage2"
Me.TabPage2.Size = New System.Drawing.Size(248, 219)
Me.TabPage2.TabIndex = 1
Me.TabPage2.Text = "TabPage2"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(72, 80)
Me.Label2.Name = "Label2"
Me.Label2.TabIndex = 0
Me.Label2.Text = "Label2"
'
'TabControl2
'
Me.TabControl2.Alignment = System.Windows.Forms.TabAlignment.Left
Me.TabControl2.Controls.Add(Me.TabPage3)
Me.TabControl2.Controls.Add(Me.TabPage4)
Me.TabControl2.Location = New System.Drawing.Point(8, 32)
Me.TabControl2.Multiline = True
Me.TabControl2.Name = "TabControl2"
Me.TabControl2.SelectedIndex = 0
Me.TabControl2.Size = New System.Drawing.Size(280, 224)
Me.TabControl2.TabIndex = 1
'
'TabPage3
'
Me.TabPage3.Controls.Add(Me.Label3)
Me.TabPage3.Location = New System.Drawing.Point(25, 4)
Me.TabPage3.Name = "TabPage3"
Me.TabPage3.Size = New System.Drawing.Size(251, 216)
Me.TabPage3.TabIndex = 0
Me.TabPage3.Text = "TabPage3"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(72, 80)
Me.Label3.Name = "Label3"
Me.Label3.TabIndex = 0
Me.Label3.Text = "Label3"
'
'TabPage4
'
Me.TabPage4.Controls.Add(Me.Label4)
Me.TabPage4.Location = New System.Drawing.Point(25, 4)
Me.TabPage4.Name = "TabPage4"
Me.TabPage4.Size = New System.Drawing.Size(251, 216)
Me.TabPage4.TabIndex = 1
Me.TabPage4.Text = "TabPage4"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(72, 80)
Me.Label4.Name = "Label4"
Me.Label4.TabIndex = 0
Me.Label4.Text = "Label4"
'
'TabbedForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
Me.ClientSize = New System.Drawing.Size(292, 260)
Me.Controls.Add(Me.TabControl2)
Me.Controls.Add(Me.TabControl1)
Me.Name = "TabbedForm"
Me.Text = "TabbedForm"
Me.TabControl1.ResumeLayout(False)
Me.TabPage1.ResumeLayout(False)
Me.TabPage2.ResumeLayout(False)
Me.TabControl2.ResumeLayout(False)
Me.TabPage3.ResumeLayout(False)
Me.TabPage4.ResumeLayout(False)
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub TabControl1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TabControl1.Click, TabControl2.Click
Dim tc As TabControl = DirectCast(sender, TabControl)
tc.BringToFront()
End Sub

End Class

Hope this helps
Jay
 
Hi..

Thanks for the information. I have got a idea... Just still not sure how to
get the height of just the top tab area... I am able to do that in the
DrawItem event, and not outside of it.

Thanks
Vijay
 
Nice Solution.
In addition set Tabcontrols Anchor to Left + Top + Right + Bottom

Then Add The Following:
\\\
Private Sub Form_Resize(ByVal sender As Object, ByVal e As EventArgs) _
Handles MyBase.Resize
TabControl1.Top = 0
TabControl1.Left = TabControl2.SelectedTab.Left - 2
TabControl1.Width = Me.ClientSize.Width - TabControl1.Left
TabControl1.Height = Me.ClientSize.Height

TabControl1.Left = 0
TabControl2.Top = TabControl1.SelectedTab.Top - 2
TabControl2.Width = Me.ClientSize.Width
TabControl2.Height = Me.ClientSize.Height - TabControl2.Top
End Sub
///
 
Mick,
I would either set the Anchor, or I would add your code to the Layout event.

I would not code both as you are "competing" with each other, The form will
resize the Tab Controls, then you resize the tab controls.

Hope this helps
Jay

"Mick Doherty"
 
You're right. You should set Anchor to None.
I originally put the code in the layout event but then discovered that the
location needed to change when an extra row was added (Tabcontrol2, being
side aligned, is multiline whether we like it or not).

In fact the solution does not work as expected since the rowcount also
changes on resize so as tabcontrol2 is resized the rowcount may change but
the location of TabControl1 has already been set and vice-versa. A better
solution is needed, but I'm off to bed. If nobody comes up with one I'll
look at it tomorrow.
 
a bit of a hack, but it's the best I could come up with:

\\\
'Tabcontrol does not have a selectedtab and controls has not set zOrder
until
'the form is visible. The resize event does fire before the form is visible
though.
'So this is to fix the null reference problems.
Private LayingOut As Boolean = True

Private Sub TabbedForm_Load(ByVal sender As Object, ByVal e As EventArgs) _
Handles MyBase.Load
LayingOut = False
'Now that the forms visible let's force a resize to align the tabcontrols
Me.Width += 1
Me.Width -= 1
End Sub

Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
MyBase.OnResize(e)

If LayingOut Then Return

Dim TC1zOrder, TC2zOrder As Integer
TC1zOrder = Me.Controls.GetChildIndex(TabControl1)
TC1zOrder = Me.Controls.GetChildIndex(TabControl2)

If TC1zOrder > TC2zOrder Then
RePositionTabControl(TabControl2)
RePositionTabControl(TabControl1)
RePositionTabControl(TabControl2)
Else
RePositionTabControl(TabControl1)
RePositionTabControl(TabControl2)
RePositionTabControl(TabControl1)
End If

End Sub

Private Sub RePositionTabControl(ByVal tc As TabControl)

If tc Is TabControl1 Then
tc.Top = 0
tc.Left = TabControl2.SelectedTab.Left - 2
tc.Width = Me.ClientSize.Width - tc.Left
tc.Height = Me.ClientSize.Height
Else
tc.Left = 0
tc.Top = TabControl1.SelectedTab.Top - 2
tc.Width = Me.ClientSize.Width
tc.Height = Me.ClientSize.Height - tc.Top
End If

End Sub
///
 
Mick,
Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
MyBase.OnResize(e)

If LayingOut Then Return
You do realize that the Control.Layout event itself is "protected" by an
internal LayingOut flag. That you can use Control.SuspendLayout &
Control.ResumeLayout to control when the Control.Layout event is raized,
further you can use Control.PerformLayout to raise the Control.Layout event.

I would put all your code in the Layout event, then call PerformLayout in
the Load event, and possible the Resize Event if the Tab Control is not
playing nice with the Layout event.

Hope this helps
Jay


"Mick Doherty"
 
You're right again.
I didn't know that, but I do now. Thanks for that.

There is no need to call PerformLayout at Load() since it's already done by
the means of SuspendLayout() and ResumeLayout() in InitializeComponent()
It does appear to be necessary in Resize() though.
 
Back
Top