Public Class Form1
Dim MyTabControl As New TabControl
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With MyTabControl
.DrawMode = TabDrawMode.OwnerDrawFixed
.Dock = DockStyle.Fill
.SizeMode = TabSizeMode.Fixed
.ItemSize = New Size(200, 30)
.Controls.Add(New TabPage("Page1"))
.Controls.Add(New TabPage("Page2"))
.Controls.Add(New TabPage("Page3"))
AddHandler .DrawItem, AddressOf MyTabcontrol_DrawItem
AddHandler .MouseClick, AddressOf MyTabcontrol_MouseClick
End With
Me.Controls.Add(MyTabControl)
End Sub
Public Sub MyTabcontrol_DrawItem(ByVal sender As System.Object, ByVal e As DrawItemEventArgs)
Dim TC As TabControl = CType(sender, TabControl)
Dim TabRec As Rectangle = TC.GetTabRect(e.Index)
Dim Clr As Color = If(e.State = DrawItemState.Selected, Color.White, Color.LightGray)
e.Graphics.FillRectangle(New SolidBrush(Clr), TabRec)
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
sf.FormatFlags = StringFormatFlags.NoWrap
If e.State = DrawItemState.Selected Then
Dim BTNRec As New Rectangle(TabRec.X + TabRec.Width - 30, 8, 18, 18)
e.Graphics.FillRectangle(Brushes.Red, BTNRec)
e.Graphics.DrawRectangle(Pens.DarkRed, BTNRec)
e.Graphics.DrawString("X", New Font(Me.Font.FontFamily, 8, FontStyle.Bold), Brushes.Black, BTNRec, sf)
End If
e.Graphics.DrawString(TC.TabPages(e.Index).Text, Me.Font, Brushes.Black, TabRec, sf)
TabRec.Inflate(-3, -3)
Dim Pn As Pen = If(e.State = DrawItemState.Selected, New Pen(Color.Green, 2), New Pen(Color.Red, 1))
e.Graphics.DrawRectangle(Pn, TabRec)
e.DrawFocusRectangle()
End Sub
Private Sub MyTabcontrol_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim TC As TabControl = CType(sender, TabControl)
Dim Rec As Rectangle = MyTabControl.GetTabRect(MyTabControl.SelectedIndex)
Dim HitTest As New Rectangle(Rec.X + Rec.Width - 30, 8, 18, 18)
If HitTest.Contains(New Point(e.X, e.Y)) Then
If Not TC.TabPages.Count = 1 Then
TC.TabPages.Remove(TC.SelectedTab)
End If
End If
End Sub
End Class
26 Eylül 2019 Perşembe
VB.Net Tabcontrol Tabpages close button without image
Kaydol:
Kayıt Yorumları (Atom)
Bu yorum bir blog yöneticisi tarafından silindi.
YanıtlaSil