Hi
I found code for a customized TabControl to make a dll.
Same as the original there is a disturbing border which i cant remove.
The black border around the whole Tab Control need to be removed.
First i took the backcolor from form for the tabcontrol that the border is
invisible and then paint a new fillrectangel with right size i want. But i am not satisfied with that solution.
when i run the form and a window is over the new painted rectangel the form seems not to be refreshed again.
Is there a property which i can change that the tabpage has the same height then the ClipRectangle?
If not, how can i make the tabpage same hight then the ClipRectangel that the Border disapears?
this is what i have
this is what i want
this the code
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim g As Graphics
Dim rect As System.Drawing.Rectangle
g = e.Graphics
rect = e.ClipRectangle
rect.Height = rect.Height - 8
rect.Width = rect.Width - 8
rect.Location = New Point(rect.Location.X + 2, rect.Location.Y + 4)
g.FillRectangle(Me.BackBrush, e.ClipRectangle) ' background
g.FillRectangle(Me.BackOverBrush, rect)
For i As Integer = 0 To Me.TabPages.Count - 1
Call Me.DrawTabButton(g, i)
Call Me.DrawTabText(g, i)
Next
End Sub
Private Sub DrawTabButton(ByVal g As Graphics, ByVal TabPageIndex As Integer)
Dim r As Rectangle
' get the tab rectangle
r = Me.GetTabRect(TabPageIndex)
' increase its width we dont want the background in between
r.Width = r.Width + 2
' if first tab page
If TabPageIndex = 0 Then
' reduce its height and move it a little bit lower
' since in tab control first tab button is displayed a little
' bit heigher
r.Height = r.Height - 2
r.Y = r.Y + 2
End If
' if given tab button is selected
If Me.SelectedIndex = TabPageIndex Then
' use selected properties
g.FillRectangle(Me.HeaderSelectedBackBrush, r)
' if currently focused then draw focus rectangle
If Me.Focused Then
System.Windows.Forms.ControlPaint.DrawFocusRectangle(g, New Rectangle(r.Left + 2, r.Top + 2, r.Width - 4, r.Height - 5))
End If
Else ' else (not the selected tab page)
g.FillRectangle(Me.HeaderBackBrush, r)
End If
' if first tab button
If TabPageIndex = 0 Then
' draw a line on top
g.DrawLine(Me.HeaderPen, r.Left, r.Top, r.Right, r.Top)
End If
' line at left
g.DrawLine(Me.HeaderPen, r.Left, r.Top, r.Left, r.Bottom - 1)
' line at bottom
g.DrawLine(Me.HeaderPen, r.Left, r.Bottom - 1, r.Right, r.Bottom - 1)
' no line at right since we want to give an effect of
' pages
End Sub
Private Sub DrawTabText(ByVal g As Graphics, ByVal TabPageIndex As Integer)
Dim iX As Integer
Dim iY As Integer
Dim sText As String
Dim sizeText As SizeF
Dim rectTab As Rectangle
' get tab button rectangle
rectTab = Me.GetTabRect(TabPageIndex)
' get text
sText = Me.TabPages(TabPageIndex).Text
' measure the size of text
sizeText = g.MeasureString(sText, Me.HeaderFont)
' check text alignment
Select Case Me.HeaderAlignment
Case ContentAlignment.MiddleLeft, ContentAlignment.BottomLeft, ContentAlignment.TopLeft
iX = rectTab.Left + Me.HeaderPadding.Left
Case ContentAlignment.MiddleRight, ContentAlignment.BottomRight, ContentAlignment.TopRight
iX = rectTab.Right - sizeText.Width - Me.HeaderPadding.Right
Case ContentAlignment.MiddleCenter, ContentAlignment.BottomCenter, ContentAlignment.TopCenter
iX = rectTab.Left + (rectTab.Width - Me.HeaderPadding.Left - Me.HeaderPadding.Right - sizeText.Width) / 2
End Select
Select Case Me.HeaderAlignment
Case ContentAlignment.TopLeft, ContentAlignment.TopCenter, ContentAlignment.TopRight
iY = rectTab.Top + Me.HeaderPadding.Top
Case ContentAlignment.BottomLeft, ContentAlignment.BottomCenter, ContentAlignment.BottomRight
iY = rectTab.Bottom - sizeText.Height - Me.HeaderPadding.Bottom
Case ContentAlignment.MiddleCenter, ContentAlignment.MiddleLeft, ContentAlignment.MiddleRight
iY = rectTab.Top + (rectTab.Height - Me.HeaderPadding.Top - sizeText.Height) / 2
End Select
' if selected tab button
If Me.SelectedIndex = TabPageIndex Then
g.DrawString(sText, Me.HeaderFont, Me.HeaderSelectedForeBrush, iX, iY)
Else
g.DrawString(sText, Me.HeaderFont, Me.HeaderForeBrush, iX, iY)
End If
End Sub
Thanks for any hint