VB.NET中tabcontrol添加关闭标签

    Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem
        Try
            Dim mytabrect As New Rectangle
            mytabrect = Me.TabControl1.GetTabRect(e.Index)
            e.Graphics.DrawString(TabControl1.TabPages(e.Index).Text, Me.Font, SystemBrushes.ControlText, mytabrect.X + 5, mytabrect.Y + 5)
            Dim p As New Pen(Brushes.White)
            mytabrect.Offset(mytabrect.Width - 15, 2)
            mytabrect.Width = 12
            mytabrect.Height = 12
            e.Graphics.DrawRectangle(p, mytabrect)
            Dim objpen As New Pen(Brushes.Black)
            Dim P1 As New Point(mytabrect.X + 3, mytabrect.Y + 3)
            Dim p2 As New Point(mytabrect.X + mytabrect.Width - 3, mytabrect.Y + mytabrect.Height - 3)
            e.Graphics.DrawLine(objpen, P1, p2)
            Dim p3 As New Point(mytabrect.X + 3, mytabrect.Y + mytabrect.Height - 3)
            Dim p4 As New Point(mytabrect.X + mytabrect.Width - 3, mytabrect.Y + 3)
            e.Graphics.DrawLine(objpen, p3, p4)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Sub TabControl1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Dim x = e.X, y = e.Y
            Dim MyTabRect As New Rectangle
            MyTabRect = TabControl1.GetTabRect(TabControl1.SelectedIndex)
            MyTabRect.Offset(MyTabRect.Width - 15, 2)
            MyTabRect.Width = 12
            MyTabRect.Height = 12
            If x >= MyTabRect.X And x < MyTabRect.Right And y > MyTabRect.Y And y < MyTabRect.Height Then
                TabControl1.TabPages.Remove(TabControl1.SelectedTab)
            End If
        End If
    End Sub


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值