Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Horizontal tabs (buttons) on left side
 

Horizontal tabs (buttons) on left side

I am trying to use a Tab Control with Tabs (or Buttons) on the left side and I would like to have horizontal buttons but I cannot find a way to do this. Is it possible?

jzirbes

jzirbes1  Sunday, April 08, 2007 9:20 PM
Mick Doherty  Tuesday, April 10, 2007 9:58 AM
Set the Alignment property to Alignment.Left...
timvw  Monday, April 09, 2007 12:10 AM

Yes, I have done that, but the buttons (tabs) show up vertical and I need them to be horizontal.

jzirbes

jzirbes1  Monday, April 09, 2007 12:49 AM

I am sorry I don't understand what's your meaning.

I think you can set alignment property to left .

Could you please discribe more clearly.Thank you.

Gavin Jin - MSFT  Monday, April 09, 2007 8:22 AM
If i get it right, you're looking for something like: http://www.codeproject.com/cs/miscctrl/csoutlookbar.asp but without the panel between the buttons... ?
timvw  Monday, April 09, 2007 8:35 AM

I'll try to explain it better.

If you drop a tabcontrol on aForm and set the Appearance property to buttons, you will see two buttons labeled tabPage1 andtabPage2displayed at the top in placeof the tabs and they will be displayed as normal Horizontal buttons.

However, if you now change the Allignment property from Top to Left you will see the buttons shifted to the left side of the component and they will be displayed Vertically.

I would llike the buttons to appear in the same Horizontal manner as they are when they are at the top of the component.

I hope this explains what I am trying to do, I don't know how else to describe it.

jzirbes

jzirbes1  Monday, April 09, 2007 9:32 PM
Mick Doherty  Tuesday, April 10, 2007 9:58 AM

Hi jzirbes,

If you are running under XP, then you may have hit the XP theme problem. If this is the case then take a look at ... http://components.skybound.ca/Products/VisualStyles/for a free patch to fix this problem.

Regards

Ron2464.

ron2464  Tuesday, April 10, 2007 9:02 PM

Nothing seems to work. I think I will have to take rkimbals advice and try to find a third party TabControl package.

Thanks for all your efforts!

jzirbes

jzirbes1  Thursday, April 12, 2007 2:11 AM

What doesn't work? You give up far too easily ;-)

I just noticed that you are setting Appearance to Buttons, which makes your solution a little different to that in the post which I linked to.

You still need to create your own TabControl class because you need to fix the DisplayRectangle (the area which the Tabpages occupy).

Code Snippet

Public Class MyTabControl

Inherits TabControl

Public Overrides ReadOnly Property DisplayRectangle() As System.Drawing.Rectangle

Get

Dim tabStripHeight, itemHeight As Int32

If Me.Alignment <= TabAlignment.Bottom OrElse Me.SizeMode = TabSizeMode.Fixed Then

itemHeight = Me.ItemSize.Height

Else

itemHeight = Me.ItemSize.Width

End If

If Me.Appearance = TabAppearance.Normal Then

tabStripHeight = 5 + (itemHeight * Me.RowCount)

Else

tabStripHeight = (3 + itemHeight) * Me.RowCount

End If

Select Case Me.Alignment

Case TabAlignment.Top

Return New Rectangle(4, tabStripHeight, Width - 8, Height - tabStripHeight - 4)

Case TabAlignment.Bottom

Return New Rectangle(4, 4, Width - 8, Height - tabStripHeight - 4)

Case TabAlignment.Left

Return New Rectangle(tabStripHeight, 4, Width - tabStripHeight - 4, Height - 8)

Case TabAlignment.Right

Return New Rectangle(4, 4, Width - tabStripHeight - 4, Height - 8)

End Select

End Get

End Property

End Class

Add an instance of this control to your form and set:

DrawMode to OwnerDrawFixed.

SizeMode to Fixed.

ItemSize will have to be manually edited otherwise it draws the tabs the wrong size. Note that width and height are the wrong way round for left or right aligned tabs.

You can then simply draw the tabtext in the controls DrawItem method:

Code Snippet

Private Sub MyTabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles MyTabControl1.DrawItem

Dim textBrush As New SolidBrush(e.ForeColor)

Dim textFormat As New StringFormat()

textFormat.Alignment = StringAlignment.Center

textFormat.LineAlignment = StringAlignment.Center

e.Graphics.FillRectangle(SystemBrushes.Control, e.Bounds)

e.Graphics.DrawString(MyTabControl1.TabPages(e.Index).Text, e.Font, textBrush, e.Bounds, textFormat)

textBrush.Dispose()

textFormat.Dispose()

End Sub

Mick Doherty  Thursday, April 12, 2007 10:02 AM

You can use google to search for other answers

Custom Search

More Threads

• bring up child control's designer in a UserControl?
• toolbar in vb.net
• UserControls disappear from VS2005 Toolbox
• UITypeEditor for inheritors of DataTable
• Cannot set Anchor property in Designer
• how can i use logical expression
• entering code below the "Windows Form Designer Generated Code" in VB Express 2008
• duplicate items in designer
• Styles in windows controls
• help: Creating Custom ToolStripButton, implementing IButtonControl