TabControl Round 2

SharkBait
03-27-2006, 02:34 PM
Alright I did this a while ago and here is the thread:

http://www.xtremevbtalk.com/showthread.php?t=231738&highlight=Tabcontrol

This is the code:

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

'********************************************************************* ***************
' Creates a pseudo Transparent looking set of tabs based on the colour
' that was choosen as a background
'********************************************************************* ***************

Dim iLp As Integer
Dim rect As Rectangle
Dim rect2 As Rectangle
Dim gr As Graphics = TabControl1.CreateGraphics
Dim sFormat As New StringFormat(StringFormatFlags.DirectionVertical)

'find the area not filled with tabs and color
rect = TabControl1.GetTabRect(TabControl1.TabCount - 1)

rect2 = New Rectangle((rect.X - 5), 0, (rect.Width + 5), TabControl1.Height)
'** Match empty space with background's color
gr.FillRectangle(New System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(CType(51, Byte), CType(102, Byte), CType(204, Byte))), rect2)

For iLp = 0 To TabControl1.TabCount - 1

rect = TabControl1.GetTabRect(iLp)

If (iLp <> TabControl1.SelectedIndex) Then
'** Not currently used tabs
gr.FillRectangle(Brushes.Gainsboro, rect)
gr.DrawString(TabControl1.TabPages(iLp).Text, TabControl1.Font, Brushes.Gray, rect.X + 2, rect.Y + 2, sFormat)
Else
gr.FillRectangle(New System.Drawing.SolidBrush(System.Drawing.SystemColors.Control), rect)
gr.DrawString(TabControl1.TabPages(iLp).Text, TabControl1.Font, Brushes.Black, rect.X + 2, rect.Y + 2, sFormat)
End If

Next iLp

gr = Nothing

End Sub

Now I've noticed that when a user is moving between tabs or using any other controls on the form, that there is flicker when the form redraws the leftside tabs.

Is there away around the flicker?

Also I am using the following for the text format of the TabControls


dim sFormat as new StringFormat(StringFormatFlags.DirectionVertical)


Is there a way to mirror the text? I want to be able to mirror it on the X axis and not sure how to go about that.

Monsoon
03-28-2006, 07:09 AM
Hello Sharkbait,

I believe your problem is here:
gr.FillRectangle(NewSystem.Drawing.SolidBrush(System.Drawing.Color.Fro mArgb(CType(51,Byte),CType(102,Byte),CType(204,Byte))),rect2)

and here:
gr.FillRectangle(Brushes.Gainsboro, rect)

You fill the entire tab area twice and it causes the flicker. When it really looks like you only want the area where the tabs will be inserted to be colored differently, not the entire tab area. If you want the entire tab are, then I guess you might have to live with the flicker.

Try this:
rect2 = _
New Rectangle((rect.X - 5), 0, (rect.Width + 5),TabControl1.Height)
with this:
rect2 = _
New Rectangle(rect.X, rect.Y + rect.Width * 3, rect.Width,rect.Height)

As for the text, Not sure sorry.

Monsoon
03-29-2006, 07:49 AM
Sorry for the confusion (if there was any) but what I intended to say was:

Replace this:
rect2 = _
New Rectangle((rect.X - 5), 0, (rect.Width + 5),TabControl1.Height)

with this:
rect2 = _
New Rectangle(rect.X, rect.Y + rect.Width * 3, rect.Width,rect.Height)

To stop the flicker and only color the area where the new tabs will be added.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum