tabpages

  • Thread starter Thread starter ahmeddc
  • Start date Start date
A

ahmeddc

Guest
I found this class to design a tab bage
But I have several problems
1- I could not move from right to left

1323015.png

2- Place a image in the first tab with a cloth button in end width

1323018.jpg3- header style 1 -border fixed = none and style lick

1323019.png

4- remove cloth button from last tab and smalist it and put +

class

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D

Namespace TabControlZ

Public Class TabControlZ
Inherits System.Windows.Forms.TabControl

Private nonactive_color1 As Color = Color.LightGreen

Private nonactive_color2 As Color = Color.DarkBlue

Private active_color1 As Color = Color.Yellow

Private active_color2 As Color = Color.DarkOrange

Public forecolore As Color = Color.Navy

Private color1Transparent As Integer = 150

Private color2Transparent As Integer = 150

Private angle As Integer = 90

Private closebuttoncolor As Color = Color.Red
Private _Image As Image
Private _ImageSize As Size


'Create Properties to read values
Public Property ActiveTabStartColor As Color
Get
Return Me.active_color1
End Get
Set(value As Color)
Me.active_color1 = value
Invalidate()
End Set
End Property

Public Property ActiveTabEndColor As Color
Get
Return Me.active_color2
End Get
Set(value As Color)
Me.active_color2 = value
Invalidate()
End Set
End Property

Public Property NonActiveTabStartColor As Color
Get
Return Me.nonactive_color1
End Get
Set(value As Color)
Me.nonactive_color1 = value
Invalidate()
End Set
End Property

Public Property NonActiveTabEndColor As Color
Get
Return Me.nonactive_color2
End Get
Set(value As Color)
Me.nonactive_color2 = value
Invalidate()
End Set
End Property

Public Property Transparent1 As Integer
Get
Return Me.color1Transparent
End Get
Set(value As Integer)
Me.color1Transparent = value
If (Me.color1Transparent > 255) Then
Me.color1Transparent = 255
Invalidate()
Else
Invalidate()
End If

End Set
End Property

Public Property Transparent2 As Integer
Get
Return Me.color2Transparent
End Get
Set(value As Integer)
Me.color2Transparent = value
If (Me.color2Transparent > 255) Then
Me.color2Transparent = 255
Invalidate()
Else
Invalidate()
End If

End Set
End Property

Public Property GradientAngle As Integer
Get
Return Me.angle
End Get
Set(value As Integer)
Me.angle = value
Invalidate()
End Set
End Property

Public Property TextColor As Color
Get
Return Me.forecolor
End Get
Set(value As Color)
Me.forecolor = value
Invalidate()
End Set
End Property

Public Property _CloseButtonColor As Color
Get
Return Me.closebuttoncolor
End Get
Set(value As Color)
Me.closebuttoncolor = value
Invalidate()
End Set
End Property
' image property add by me
Property Image() As Image
Get
Return _Image
End Get
Set(ByVal value As Image)
If value Is Nothing Then
_ImageSize = Size.Empty
Else
_ImageSize = value.Size
End If

_Image = value
Invalidate()
End Set
End Property

Protected ReadOnly Property ImageSize() As Size
Get
Return _ImageSize
End Get
End Property


Public Sub New()
MyBase.New()
Me.DrawMode = TabDrawMode.OwnerDrawFixed
Me.Padding = New System.Drawing.Point(22, 4)
End Sub

Protected Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
MyBase.OnPaint(pe)
End Sub

'method for drawing tab items
Protected Overrides Sub OnDrawItem(ByVal e As DrawItemEventArgs)
MyBase.OnDrawItem(e)
Dim rc As Rectangle = GetTabRect(e.Index)
'if tab is selected
If Me.SelectedIndex = e.Index Then
Dim c1 As Color = Color.FromArgb(Me.color1Transparent, Me.active_color1)
Dim c2 As Color = Color.FromArgb(Me.color2Transparent, Me.active_color2)
Dim br As LinearGradientBrush = New LinearGradientBrush(rc, c1, c2, Me.angle)
e.Graphics.FillRectangle(br, rc)
Else
Dim c1 As Color = Color.FromArgb(Me.color1Transparent, Me.nonactive_color1)
Dim c2 As Color = Color.FromArgb(Me.color2Transparent, Me.nonactive_color2)
Dim br As LinearGradientBrush = New LinearGradientBrush(rc, c1, c2, Me.angle)
e.Graphics.FillRectangle(br, rc)
End If

Me.TabPages(e.Index).BorderStyle = BorderStyle.None
Me.TabPages(e.Index).ForeColor = SystemColors.ControlText
'draw close button on tabs
Dim paddedBounds As Rectangle = e.Bounds
paddedBounds.Inflate(-5, -4)
e.Graphics.DrawString(Me.TabPages(e.Index).Text, Me.Font, New SolidBrush(Me.forecolor), paddedBounds)
Dim pad As Point = Me.Padding
'drawing close button to tab items

e.Graphics.DrawString("X", New Font("Microsoft YaHei UI", 10, FontStyle.Bold), New SolidBrush(Me.closebuttoncolor), (e.Bounds.Right + (1 - 18)), (e.Bounds.Top _
+ (pad.Y - 2)))
e.DrawFocusRectangle()
End Sub




'action for when mouse click on close button
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
MyBase.OnMouseDown(e)
Dim i As Integer = 0
Do While (i < Me.TabPages.Count - 1)
Dim r As Rectangle = Me.GetTabRect(i)
Dim closeButton As Rectangle = New Rectangle((r.Right + (1 - 15)), (r.Top + 4), 12, 12)
If closeButton.Contains(e.Location) Then
'If (MessageBox.Show("Do you want to Close this Tab ?", "Close or Not", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes) Then
Me.TabPages.RemoveAt(i)
End If

i = (i + 1)
Loop

End Sub
End Class
End Namespace

Continue reading...
 
Back
Top