Remove/Edit TabControl Padding for TabPages

守給你的承諾、 提交于 2019-12-01 21:51:27

问题


I was using System.Windows.Forms.TabControl to list custom pages, but there seems be a Hardcoded Padding of 3 pixels on all sides of Tabcontrol.

How I can remove that. One point here is I dont want to remove Tabs on Top

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

I found above MSDN link whick does removes margins from all sides including TabItems on top which I dont want.

Thanks in advance!


回答1:


This is the only way I can modify that padding.

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


来源:https://stackoverflow.com/questions/6705698/remove-edit-tabcontrol-padding-for-tabpages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!