Click here to Skip to main content
11,496,146 members (1,124 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
See more: VB.NET
hello
am trying to build a custom tab control in visual basic.net
i have a problem in fixing a simple problem. the code runs ok
but when i select a tab i no longer see the text that was suppose to be on the tab
and when i select an other tab i no see it but i can't see the text on the tab i selected.

please give me a help

here is my code

Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class TC1

Inherits Windows.Forms.TabControl

Public Sub New()
SetStyle(Windows.Forms.ControlStyles.AllPaintingInWmPaint Or Windows.Forms.ControlStyles.ResizeRedraw Or Windows.Forms.ControlStyles.UserPaint Or Windows.Forms.ControlStyles.OptimizedDoubleBuffer, True)
DoubleBuffered = True
SizeMode = Windows.Forms.TabSizeMode.Fixed
ItemSize = New Size(44, 136)
End Sub
Protected Overrides Sub CreateHandle()
MyBase.CreateHandle()
Alignment = Windows.Forms.TabAlignment.Left
End Sub
Function ToPen(ByVal color As Color) As Pen
Return New Pen(color)
End Function
Function ToBrush(ByVal color As Color) As Brush
Return New SolidBrush(color)
End Function
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim DB As New Bitmap(Width, Height)
Dim DG As Graphics = Graphics.FromImage(DB)
Try : SelectedTab.BackColor = Color.White
Catch
End Try
DG.Clear(Color.White)
DG.FillRectangle(New SolidBrush(Color.FromArgb(239, 239, 242)), New Rectangle(0, 0, ItemSize.Height + 4, Height))
DG.DrawLine(New Pen(Color.FromArgb(170, 187, 204)), New Point(ItemSize.Height + 3, 0), New Point(ItemSize.Height + 3, 999))
For i = 0 To TabCount - 1
If i = SelectedIndex Then
Dim x4 As Rectangle = New Rectangle(New Point(GetTabRect(i).Location.X - 2, GetTabRect(i).Location.Y - 2), New Size(GetTabRect(i).Width + 3, GetTabRect(i).Height - 1))
Dim _mblend As New ColorBlend()
_mblend.Colors = {Color.FromArgb(0, 122, 204), Color.FromArgb(0, 122, 204), Color.FromArgb(0, 122, 204)}
_mblend.Positions = {0.0F, 0.5F, 1.0F}
Dim _lgBrush As New LinearGradientBrush(x4, Color.Black, Color.Black, 90.0F)
_lgBrush.InterpolationColors = _mblend
DG.FillRectangle(_lgBrush, x4)
DG.DrawRectangle(New Pen(Color.FromArgb(170, 187, 204)), x4)
DG.SmoothingMode = SmoothingMode.HighQuality

Dim p() As Point = {New Point(ItemSize.Height - 3, GetTabRect(i).Location.Y + 20),
New Point(ItemSize.Height + 4, GetTabRect(i).Location.Y + 14), New Point(ItemSize.Height + 4, GetTabRect(i).Location.Y + 27)}
DG.FillPolygon(Brushes.White, p)
DG.DrawPolygon(New Pen(Color.FromArgb(170, 187, 204)), p)
If ImageList IsNot Nothing Then
Try
If ImageList.Images(TabPages(i).ImageIndex) Is Nothing Then
DG.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x4.Location.X + 8, x4.Location.Y + 6))
DG.DrawString(" " & TabPages(i).Text, Font, Brushes.Black, x4, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
Else
DG.DrawString(TabPages(i).Text, New Font(Font.FontFamily, Font.Size, FontStyle.Regular), Brushes.Black, x4, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
End If
Catch ex As Exception
DG.DrawString(TabPages(i).Text, New Font(Font.FontFamily, Font.Size, FontStyle.Regular), Brushes.Black, x4, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})


End Try
Else
'DG.DrawString(TabPages(i).Text, New Font(Font.FontFamily, Font.Size, FontStyle.Regular, Brushes.White, x4, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center}))
End If
DG.DrawLine(New Pen(Color.FromArgb(200, 200, 250)), New Point(x4.Location.X - 1, x4.Location.Y - 1), New Point(x4.Location.X, x4.Location.Y))
DG.DrawLine(New Pen(Color.FromArgb(200, 200, 250)), New Point(x4.Location.X - 1, x4.Bottom - 1), New Point(x4.Location.X, x4.Bottom))
Else
Dim x4 As Rectangle = New Rectangle(New Point(GetTabRect(i).Location.X - 2, GetTabRect(i).Location.Y - 2), New Size(GetTabRect(i).Width + 3, GetTabRect(i).Height + 1))
DG.FillRectangle(New SolidBrush(Color.FromArgb(239, 239, 242)), x4)
DG.DrawLine(New Pen(Color.FromArgb(170, 187, 204)), New Point(x4.Right, x4.Top), New Point(x4.Right, x4.Bottom))
If ImageList Is Nothing Then
Try
If ImageList.Images(TabPages(i).ImageIndex) Is Nothing Then
DG.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x4.Location.X + 8, x4.Location.Y + 6))
DG.DrawString("" & TabPages(i).Text, Font, Brushes.Black, x4, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
Else
DG.DrawString(TabPages(i).Text, Font, Brushes.White, x4, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})

End If
Catch ex As Exception
DG.DrawString(TabPages(i).Text, Font, Brushes.Black, x4, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
End Try
Else
DG.DrawString(TabPages(i).Text, Font, Brushes.White, x4, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})

End If
End If
Next
e.Graphics.DrawImage(DB.Clone, 0, 0)
DG.Dispose() : DB.Dispose()
End Sub

Private Sub InitializeComponent()
Me.SuspendLayout()
Me.ResumeLayout(False)

End Sub
End Class
Posted 25-May-13 17:39pm
sean871507

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Dnyaneshwar@Pune 692
1 RyanDev 230
2 CHill60 208
3 Sascha Lefèvre 195
4 Sergey Alexandrovich Kryukov 124
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 25 May 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100