Imports System
Imports System.Data
Imports System.Windows.Forms
Imports System.Drawing
Public Class Form1
Private tabArea As Rectangle
Private tabTextArea As RectangleF
Private deleteArea As RectangleF
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Button1.Location = New Point(TabControl1.TabCount * 100 + TabControl1.Location.X, TabControl1.Location.Y)
Button1.Height = 28
Button1.Width = 24
End Sub
Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem
Dim drawFont As New Font("Verdana", 7, FontStyle.Italic)
Dim drawBrush As New SolidBrush(Color.White)
Dim g As Graphics = e.Graphics
Dim p As Graphics = e.Graphics
tabArea = TabControl1.GetTabRect(e.Index)
deleteArea.Height = 11
deleteArea.Width = 10
deleteArea.X = tabArea.X + 5
deleteArea.Y = tabArea.Y + 2
g.FillRectangle(Brushes.Blue, deleteArea)
g.DrawString("X", drawFont, drawBrush, tabArea.X + 5, tabArea.Y + 1)
drawFont.Dispose()
drawBrush.Dispose()
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If TabControl1.TabCount < 10 Then
TabControl1.TabPages.Add(New TabPage)
TabControl1.SelectTab(TabControl1.TabCount - 1)
End If
Button1.Location = New Point(TabControl1.TabCount * TabControl1.ItemSize.Width + TabControl1.Location.X, TabControl1.Location.Y)
If TabControl1.TabCount * 100 > TabControl1.Width - Button1.Width Then
Dim divide As Size = New Size(((TabControl1.Width - Button1.Width) / TabControl1.TabCount), TabControl1.ItemSize.Height)
TabControl1.ItemSize = divide
Button1.Location = New Point(TabControl1.Width + TabControl1.Location.X - Button1.Width, TabControl1.Location.Y)
End If
End Sub
Function getTabAt(ByVal tc As TabControl, ByVal pt As Point) As TabPage
For i As Integer = 0 To tc.TabCount - 1
If tc.GetTabRect(i).Contains(pt) Then
Return tc.TabPages(i)
End If
Next
Return Nothing
End Function
Private Sub TabControl1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseClick
'If e.Button = Windows.Forms.MouseButtons.Right Then
'Dim tp As TabPage = getTabAt(sender, e.Location)
'TabControl1.TabPages.Remove(tp)
'End If
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim tp As TabPage = getTabAt(sender, e.Location)
tabArea = TabControl1.GetTabRect(TabControl1.TabPages.IndexOf(tp))
Dim delArea As RectangleF
delArea.Height = 11
delArea.Width = 10
delArea.X = tabArea.X + 5
delArea.Y = tabArea.Y + 2
If delArea.Contains(e.Location) And TabControl1.TabCount > 1 Then
TabControl1.TabPages.Remove(tp)
If TabControl1.TabCount * 100 > TabControl1.Width - Button1.Width Then
Dim divSize As Size = New Size(((TabControl1.Width - Button1.Width) / TabControl1.TabCount), TabControl1.ItemSize.Height)
TabControl1.ItemSize = divSize
Else
TabControl1.ItemSize = New Size(100, 25)
End If
Button1.Location = New Point(TabControl1.TabCount * TabControl1.ItemSize.Width + TabControl1.Location.X, TabControl1.Location.Y)
End If
End If
End Sub
End Class