其他分享
首页 > 其他分享> > 删除/编辑TabPages的TabControl填充

删除/编辑TabPages的TabControl填充

作者:互联网

我正在使用System.Windows.Forms.TabControl列出自定义页面,但是Tabcontrol的所有面上似乎都有3像素的硬编码填充.

我该如何删除.这里的要点是我不想删除顶部的标签

http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/a8c5bc93-8f76-42e7-b501-b12f8b5bd1eb/

我发现上面的MSDN链接鞭子确实消除了所有边距,包括不需要的顶部TabItems.

提前致谢!

解决方法:

这是我修改该填充的唯一方法.

Imports System.Runtime.InteropServices

Public Class NativeTabControl
    Inherits NativeWindow
    Private Const TCM_FIRST As Int32 = &H1300
    Private Const TCM_ADJUSTRECT As UInt32 = (TCM_FIRST + 40)
Private baseCtrl As TabControl

Public Sub New(ByVal ctrl As TabControl)
    Me.baseCtrl = ctrl
    AddHandler ctrl.HandleDestroyed, AddressOf OnHandleDestroyed
    Me.AssignHandle(ctrl.Handle)
End Sub

Private Sub OnHandleDestroyed(ByVal sender As Object, ByVal e As EventArgs)
    ' Window was destroyed, release hook.
    RemoveHandler baseCtrl.HandleDestroyed, AddressOf OnHandleDestroyed
    Me.ReleaseHandle()
End Sub

Protected Overrides Sub WndProc(ByRef m As Message)
    If (m.Msg = TCM_ADJUSTRECT) Then
        Dim rc As RECT = DirectCast(m.GetLParam(GetType(RECT)), RECT)
        'Adjust these values to suit, dependant upon Appearance
        rc.Left -= 3
        rc.Right += 1
        rc.Top -= 1
        rc.Bottom += 1
        Marshal.StructureToPtr(rc, m.LParam, True)
    End If
    MyBase.WndProc(m)
End Sub

Private Structure RECT
    Public Left, Top, Right, Bottom As Int32
End Structure
End Class

标签:net-2-0,tabcontrol,vb-net,c,winforms
来源: https://codeday.me/bug/20191208/2089406.html