2011-07-15 10 views
3

System.Windows.Forms.TabControlを使用してカスタムページを一覧表示していましたが、Tabcontrolの全面に3ピクセルのハードコーディングされたパディングがあるようです。TabControlのTabControlパディングの削除/編集

どのように削除できますか。ここでの一つのポイントは、私は私がいけない上にTabItemsを含むすべての側面からの余白を削除しwhick MSDNのリンクの上に見つかっトップ

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

のタブを削除したくないです。

ありがとうございます!

+0

が重複する可能性[私はWinFormsのコンテナコントロールの境界線のパディングを削除するにはどうすればよい?](http://stackoverflow.com/questions/4968267/how-can-i-remove-the-border-paddingコンテナ内のコンテナコントロール) –

+0

上記の質問の回答はここでは当てはまりません。誰もが興味を持って質問に有効な回答が見つかりました!ここにそれを掲示する! – CodeWrite

答えて

3

これは、パディングを変更できる唯一の方法です。

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 
+0

TCM_ADJUSTRECTメッセージがTabPage RectangleでTabControlに送信され、これを変更してTabControlに再送信できます – CodeWrite