使用VB.net表单的Tabcontrol和文本放置

问题描述 投票:0回答:1

我正在尝试构建一个左侧有选项卡的应用程序,但我希望文本是水平的而不是垂直的。我见过WPF和C#的很多论坛帖子,但没有特别针对VB.net。

是否有一个特定的属性可以让文本从垂直变为水平?如何实施此类更改?我知道这似乎是新手喜欢问,但我觉得我碰到了一堵砖墙。任何帮助将不胜感激。

vb.net tabcontrol
1个回答
0
投票

我能够在Microsoft的.Net资源页面上找到以下内容。

https://docs.microsoft.com/en-us/dotnet/framework/winforms/controls/how-to-display-side-aligned-tabs-with-tabcontrol

我现在希望能够做的唯一项目是在文本中添加填充,使其不对照对话框。如果有人有任何想法,请告知。

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

' Get the item from the collection.
Dim _TabPage As TabPage = TabControl1.TabPages(e.Index)

' Get the real bounds for the tab rectangle.
Dim _TabBounds As Rectangle = TabControl1.GetTabRect(e.Index)

If (e.State = DrawItemState.Selected) Then
    ' Draw a different background color, and don't paint a focus rectangle.
    _TextBrush = New SolidBrush(Color.Red)
    g.FillRectangle(Brushes.Gray, e.Bounds)
Else
    _TextBrush = New System.Drawing.SolidBrush(e.ForeColor)
    e.DrawBackground()
End If

' Use our own font.
Dim _TabFont As New Font("Arial", 10.0, FontStyle.Bold, GraphicsUnit.Pixel)

' Draw string. Center the text.
Dim _StringFlags As New StringFormat()
_StringFlags.Alignment = StringAlignment.Center
_StringFlags.LineAlignment = StringAlignment.Center
g.DrawString(_TabPage.Text, _TabFont, _TextBrush, _TabBounds, New StringFormat(_StringFlags))
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.