1

我正在尝试使选项卡在表单的右侧水平显示。由于文本的显示方式,我无法使用工具箱中的 tabcontrol。我正在使用我发现可以帮助我的代码。但是在用尽我所有的资源之后,我似乎无法让代码指向 tabPages 集合。我在那里有条目,但选项卡显示为空白。

 Public Sub New()
    tabControl1 = New TabControl()
    Dim tabPage1 As New TabPage()

    ' Sets the tabs to be drawn by the parent window Form1. 
    ' OwnerDrawFixed allows access to DrawItem. 
    tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed

    tabControl1.Controls.Add(tabPage1)
    tabControl1.Location = New Point(25, 25)
    tabControl1.Size = New Size(250, 250)

    tabPage1.TabIndex = 0

    myTabRect = tabControl1.GetTabRect(0)

    ClientSize = New Size(300, 300)
    Controls.Add(tabControl1)

    AddHandler tabControl1.DrawItem, AddressOf OnDrawItem
End Sub!

选项卡示例

4

2 回答 2

0

您可以将.AlignmentTabControl 的属性设置Left为使用水平选项卡。

如果您不喜欢这样,请尝试为每个选项卡使用单独的 TabControl 的 FlowLayoutPanel,例如

Public Class Form1
  Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    Dim flp As New FlowLayoutPanel
    flp.Dock = DockStyle.Left
    flp.AutoSize = True
    flp.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowOnly

    Me.Controls.Add(flp)
    For i As Integer = 0 To 5
      Dim tbc As New TabControl
      Dim tbp As New TabPage("Tab" & i.ToString)
      tbc.TabPages.Add(tbp)
      flp.Controls.Add(tbc)
    Next i
  End Sub
End Class
于 2012-10-10T02:18:07.397 回答
0

我最终从不同的来源编译了这段代码来让它工作,

    Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem
    Dim g As Graphics
    Dim sText As String

    Dim iX As Integer
    Dim iY As Integer
    Dim sizeText As SizeF
    Dim ctlTab As TabControl

    Dim r As New RectangleF(e.Bounds.X, e.Bounds.Y + 2, e.Bounds.Width, e.Bounds.Height - 2)

    ctlTab = CType(sender, TabControl)

    g = e.Graphics

    sText = ctlTab.TabPages(e.Index).Text
    sizeText = g.MeasureString(sText, ctlTab.Font)

    iX = e.Bounds.Left + 6
    iY = e.Bounds.Top + (e.Bounds.Height - sizeText.Height) / 2

    g.DrawString(sText, ctlTab.Font, Brushes.Black, iX, iY)
End Sub

文本不会出现在 RAD 中,但在我调试/运行它时会出现。

非常感谢 LUC001 @ http://www.dreamincode.net/forums/topic/125792-how-to-make-vertical-tabs/

于 2012-10-13T13:25:49.947 回答