draw.mode中的VB Tab控件

时间:2012-10-09 20:42:59

标签: vb.net tabcontrol

我正在尝试将标签水平显示在表单的右侧。由于文本的显示方式,我无法使用工具箱中的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!

tab Example

2 个答案:

答案 0 :(得分:0)

您可以将TabControl的.Alignment属性设置为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

答案 1 :(得分: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/