custom tab control problem

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I have created a simply custom tab.
Here is the class:
<pre class="prettyprint lang-vb Public Class tabctl
Inherits Windows.Forms.TabControl
Const tabhatterszin = 15391691
Const formhatterszin = 15921906
Const tabfejlec_hatter_selected = 10251054
Const tabfejlec_hatter_deselected = 14331266
Const tabfelsovonal1 = 9791540 legteteje
Const tabfelsovonal2 = 12097136 alatta
Const keret = 11246736 bal és jobb oldal
Const alja2 = 13484987 legalja
Const alja1 = 13550002 egyel felette
Const arnyek = 11108441
Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
End Sub
Protected Overrides Sub OnSelectedIndexChanged(ByVal e As System.EventArgs)
MyBase.OnSelectedIndexChanged(e)
Me.Refresh()
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
Dim TabControlArea As Rectangle = Me.ClientRectangle
Dim TabArea As Rectangle = Me.DisplayRectangle
háttér
e.Graphics.FillRectangle(New SolidBrush(Drawing.ColorTranslator.FromOle(tabhatterszin)), TabControlArea)
e.Graphics.FillRectangle(New SolidBrush(Drawing.ColorTranslator.FromOle(formhatterszin)), 0, 0, TabControlArea.Width, TabArea.Location.Y - 1)
bal oldal
Dim p1 As Pen
p1 = New Pen(Drawing.ColorTranslator.FromOle(keret), 1)
e.Graphics.DrawLine(p1, 0, TabArea.Location.Y - 2, 0, TabControlArea.Height)
jobb oldal
e.Graphics.DrawLine(p1, TabControlArea.Width - 1, TabArea.Location.Y - 2, TabControlArea.Width - 1, TabControlArea.Height)
alul
p1 = New Pen(Drawing.ColorTranslator.FromOle(alja2), 1)
e.Graphics.DrawLine(p1, 0, TabControlArea.Height - 1, TabControlArea.Width - 1, TabControlArea.Height - 1)
p1 = New Pen(Drawing.ColorTranslator.FromOle(alja1), 1)
e.Graphics.DrawLine(p1, 1, TabControlArea.Height - 2, TabControlArea.Width - 2, TabControlArea.Height - 2)
felül
p1 = New Pen(Drawing.ColorTranslator.FromOle(tabfelsovonal1), 1)
e.Graphics.DrawLine(p1, 1, TabArea.Location.Y - 2, TabControlArea.Width - 2, TabArea.Location.Y - 2)
p1 = New Pen(Drawing.ColorTranslator.FromOle(tabfelsovonal2), 1)
e.Graphics.DrawLine(p1, 1, TabArea.Location.Y - 1, TabControlArea.Width - 2, TabArea.Location.Y - 1)
tabok régiója
Dim rsaved As Region = e.Graphics.Clip
Dim rreg As Rectangle
Dim nWidth As Integer = TabArea.Width
rreg = New Rectangle(TabArea.Left, TabControlArea.Top, nWidth, TabControlArea.Height)
e.Graphics.SetClip(rreg)
tabok rajzolása
For i As Integer = Me.TabCount - 1 To 0 Step -1
drawtab(e.Graphics, Me.TabPages(i), i)
Next
If Me.SelectedIndex > -1 Then drawtab(e.Graphics, Me.TabPages(SelectedIndex), SelectedIndex)
e.Graphics.Clip = rsaved
End Sub
Private Sub drawtab(ByVal g As Graphics, ByVal tbpage As TabPage, ByVal index As Integer)
Dim recBounds As Rectangle = Me.GetTabRect(index)
recBounds.Size = New Size(recBounds.Width + 18, recBounds.Height)
Dim tabTextArea As RectangleF = RectangleF.op_Implicit(recBounds)
tabTextArea.Size = New Size(tabTextArea.Width - 18, tabTextArea.Height)
Dim bSelected As Boolean = (Me.SelectedIndex = index)
Dim pt As Point() = New Point(6) {}
pt(0) = New Point(recBounds.Left + 8, recBounds.Bottom)
pt(1) = New Point(recBounds.Left + 28, recBounds.Top)
pt(2) = New Point(recBounds.Right, recBounds.Top)
pt(3) = New Point(recBounds.Right, recBounds.Bottom)
pt(4) = New Point(recBounds.Left + 8, recBounds.Bottom)
árnyék poligon
Dim pt1 As Point() = New Point(4) {}
pt1(0) = New Point(recBounds.Left + 18, recBounds.Bottom)
pt1(1) = New Point(recBounds.Left + 18, recBounds.Top + 11)
pt1(2) = New Point(recBounds.Left + 22, 9)
pt1(3) = New Point(recBounds.Left + 22, recBounds.Bottom)
pt1(4) = New Point(recBounds.Left + 18, recBounds.Bottom)
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
If bSelected Then
g.FillPolygon(New SolidBrush(Drawing.ColorTranslator.FromOle(tabfejlec_hatter_selected)), pt)
Else
g.FillPolygon(New SolidBrush(Drawing.ColorTranslator.FromOle(tabfejlec_hatter_deselected)), pt)
If index > 0 Then g.FillPolygon(New SolidBrush(Drawing.ColorTranslator.FromOle(arnyek)), pt1)
felső tető vonal újrarajzolása
Dim p1 = New Pen(Drawing.ColorTranslator.FromOle(tabfelsovonal1), 1)
g.DrawLine(p1, recBounds.Left, recBounds.Bottom, recBounds.Right, recBounds.Bottom)
End If
tbpage.BackColor = Drawing.ColorTranslator.FromOle(tabhatterszin)
szöveg
Dim stringFormat As New StringFormat()
stringFormat.Alignment = StringAlignment.Center
stringFormat.LineAlignment = StringAlignment.Center
Dim br1 As Brush
If bSelected Then
br1 = New SolidBrush(Color.White)
Else
br1 = New SolidBrush(Color.Black)
End If
tabTextArea.Location = New Point(tabTextArea.X + 18, tabTextArea.Location.Y)
g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
g.DrawString(tbpage.Text, New Font("tahoma", 9), br1, tabTextArea, stringFormat)
End Sub
End Class[/code]
My problem is, if I add one new tab in the design mode and then build the app, I get the error: "the file form2.vb cannot be modified in the designer while building or debugging"
stack trace: it refers to the drawtab event (line 91) - tbpage.backcolor=....
In run-time, the tab control appears correctly, and after I close the app and hit the ok of button of the error message, the tab control appears correctly too in design mode.
What am I missing here?

View the full article
 
Back
Top