D
D King
Hi. I have a Tab control on my form. I used an image list for icons for my
tabs. Then I decide I wanted to make the tabs look a little better so I set
the DrawMode to OwnerDrawFixed, wrote some code to the TabControls DrawItem
event and now I have the selected tab with a nice gradient blue backcolor.
Problem is, I dont' know how to write the code to draw my icons. Does anyone
know or have any examples? Thanks in advance....
Private Sub TabControlMain_DrawItem(ByVal sender As Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles TabControlMain.DrawItem
Dim myFont As Font
Dim backBrush, foreBrush As Brush
If e.Index = Me.TabControlMain.SelectedIndex Then
myFont = New Font(e.Font, FontStyle.Bold)
'== make the selected tab have a gradient blue background
backBrush = New System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds,
Color.Blue, Color.DeepSkyBlue,
System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal)
foreBrush = Brushes.PowderBlue
Else
myFont = e.Font
'== dim the font of the non selected tabs
backBrush = New SolidBrush(SystemColors.Control)
foreBrush = New SolidBrush(Color.DimGray)
End If
Dim tabName As String = Me.TabControlMain.TabPages(e.Index).Text
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
e.Graphics.FillRectangle(backBrush, e.Bounds)
Dim r As RectangleF = New RectangleF(e.Bounds.X, e.Bounds.Y + 4,
e.Bounds.Width, e.Bounds.Height - 4)
e.Graphics.DrawString(tabName, myFont, foreBrush, r, sf)
sf.Dispose()
If e.Index = Me.TabControlMain.SelectedIndex Then
myFont.Dispose()
backBrush.Dispose()
Else
backBrush.Dispose()
foreBrush.Dispose()
End If
End Sub
tabs. Then I decide I wanted to make the tabs look a little better so I set
the DrawMode to OwnerDrawFixed, wrote some code to the TabControls DrawItem
event and now I have the selected tab with a nice gradient blue backcolor.
Problem is, I dont' know how to write the code to draw my icons. Does anyone
know or have any examples? Thanks in advance....
Private Sub TabControlMain_DrawItem(ByVal sender As Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles TabControlMain.DrawItem
Dim myFont As Font
Dim backBrush, foreBrush As Brush
If e.Index = Me.TabControlMain.SelectedIndex Then
myFont = New Font(e.Font, FontStyle.Bold)
'== make the selected tab have a gradient blue background
backBrush = New System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds,
Color.Blue, Color.DeepSkyBlue,
System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal)
foreBrush = Brushes.PowderBlue
Else
myFont = e.Font
'== dim the font of the non selected tabs
backBrush = New SolidBrush(SystemColors.Control)
foreBrush = New SolidBrush(Color.DimGray)
End If
Dim tabName As String = Me.TabControlMain.TabPages(e.Index).Text
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
e.Graphics.FillRectangle(backBrush, e.Bounds)
Dim r As RectangleF = New RectangleF(e.Bounds.X, e.Bounds.Y + 4,
e.Bounds.Width, e.Bounds.Height - 4)
e.Graphics.DrawString(tabName, myFont, foreBrush, r, sf)
sf.Dispose()
If e.Index = Me.TabControlMain.SelectedIndex Then
myFont.Dispose()
backBrush.Dispose()
Else
backBrush.Dispose()
foreBrush.Dispose()
End If
End Sub