Winform vb.net - 如何更改选项卡的颜色?

发布于 2024-08-21 09:34:59 字数 40 浏览 7 评论 0原文

如何更改选项卡页标题的颜色,即显示在选项卡始终可见的部分上的文本?

How can I change the color of the Tab Page Header, the text that appears on the part of the Tab that is always visible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

东京女 2024-08-28 09:34:59

也许不是最优雅的解决方案,但是.. 将 TabControl 的 DrawMode 更改为 OwnerDrawFixed 并自己处理绘图。查看 MSDN 获取示例。

Maybe not the most elegant solution but.. Change the DrawMode of the TabControl to OwnerDrawFixed and handle the drawing yourself. Check MSDN for examples.

你曾走过我的故事 2024-08-28 09:34:59

除了对 DrawItem 事件进行编码之外,还可以根据需要跟踪此事件以更改选项卡页文本。

    Private Sub ChangeTabPageTextColor(ByVal TabPageIndex As Integer, ByVal ForeColor As Color)
    '  Get the area of the header of this TabPage
    Dim HeaderRect As Rectangle = TabControl1.GetTabRect(TabPageIndex)
    '  Identify which TabPage is currently selected
    Dim SelectedTab As TabPage = TabControl1.TabPages(TabPageIndex)
    '  Create a Brush to paint the Text
    Dim TextBrush As New SolidBrush(ForeColor)
    '  Declare the text alignment variable
    Dim sf As New StringFormat()
    '  Set the Horizontal Alignment of the Text
    sf.Alignment = StringAlignment.Center
    '  Set the Verticle Alignment of the Text
    sf.LineAlignment = StringAlignment.Near
    ' Declare a Font
    Dim newfont As New Font(TabControl1.Font.Name, TabControl1.Font.Size, FontStyle.Regular)
    ' Draw the text
    TabControl1.CreateGraphics().DrawString(SelectedTab.Text, newfont, TextBrush, HeaderRect, sf)
    '  Job done - dispose of the Brush
    TextBrush.Dispose()
End Sub

In addition to coding the DrawItem Event, followup with this event to change the tabpage text whenever you want to.

    Private Sub ChangeTabPageTextColor(ByVal TabPageIndex As Integer, ByVal ForeColor As Color)
    '  Get the area of the header of this TabPage
    Dim HeaderRect As Rectangle = TabControl1.GetTabRect(TabPageIndex)
    '  Identify which TabPage is currently selected
    Dim SelectedTab As TabPage = TabControl1.TabPages(TabPageIndex)
    '  Create a Brush to paint the Text
    Dim TextBrush As New SolidBrush(ForeColor)
    '  Declare the text alignment variable
    Dim sf As New StringFormat()
    '  Set the Horizontal Alignment of the Text
    sf.Alignment = StringAlignment.Center
    '  Set the Verticle Alignment of the Text
    sf.LineAlignment = StringAlignment.Near
    ' Declare a Font
    Dim newfont As New Font(TabControl1.Font.Name, TabControl1.Font.Size, FontStyle.Regular)
    ' Draw the text
    TabControl1.CreateGraphics().DrawString(SelectedTab.Text, newfont, TextBrush, HeaderRect, sf)
    '  Job done - dispose of the Brush
    TextBrush.Dispose()
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文