如何在vb.net中选择选定的选项卡标题颜色 [英] How to chnage the selected tab header color in vb.net
本文介绍了如何在vb.net中选择选定的选项卡标题颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我选择TabControl的TabPage时,我只想更改vb.net中所选标签的唯一标题文本颜色
解决方案
设置DrawMode = OwnerDrawFixed
[TabControl]
并使用DrawItem
绘制标签标题,如图所示。
私有 Sub TabControl1_DrawItem( ByVal sender 作为 对象, ByVal e As System.Windows.Forms.DrawItemEventArgs)句柄 TabControl1.DrawItem
Dim tabctl As TabControl = DirectCast (sender,TabControl)
Dim g As Graphics = e.Graphics
Dim font As Font = tabctl.Font
Dim brush As 新 SolidBrush(Color.Black)
Dim tabTextArea As RectangleF = RectangleF.op_Implicit(tabctl.GetTabRect(e.Index))
如果 tabctl.SelectedIndex = e.Index 那么
font = 新字体(font,FontStyle.Bold)
brush = 新 SolidBrush(Color.Red)
结束 如果
g.DrawString(tabctl.TabPages(e.Index).Text,font ,brush,tabTextArea)
结束 Sub
很棒的帖子!我通过对齐,颜色和背景颜色做了一些修改。给我一个糟糕的英语。我说的是葡萄牙语。
(Otimo post!Fiz algumas modificacoes de alinhamento,core e cor do fundo.Perdoe-me o meu Ingles ruim.Falo Portugues)
' cor do tabcontrole
私有 Sub TabControl_DrawItem( ByVal 发件人作为 对象, ByVal e As System.Windows.Forms.DrawItemEventArgs)句柄 ContasTabControl.DrawItem
Dim tabContas As TabControl = DirectCast (sender,TabControl)
Dim sTexto As 字符串 = tabContas.TabPages(e.Index).Text
Dim g As Graphics = e.Graphics
Dim fonte As 字体= tabContas.Font
Dim format = 新 System.Drawing.StringFormat
< span class =code-comment>' 在此处更改...
format.Alignment = StringAlignment.Center
格式。 LineAlignment = StringAlignment.Center
Dim pincel As 新 SolidBrush(Color.Black)
' RENEMED VARIEBLE HERE ...
Dim retangulo As RectangleF = Rectan gleF.op_Implicit(tabContas.GetTabRect(e.Index))
如果 tabContas.SelectedIndex = e.Index 那么
fonte = 新字体(fonte,FontStyle.Bold)
pincel = 新 SolidBrush(Color.Black)
' 在这里改变背景颜色......
g.FillRectangle(Brushes.White,retangulo)
结束 如果
g.DrawString(sTexto,fonte,pincel,retangulo,format)
结束 Sub
When I select the TabPage of TabControl I just want to change the only Header Text Color of Selected Tab in vb.net
解决方案
SetDrawMode = OwnerDrawFixed
[of TabControl]
and useDrawItem
to draw the tab headers as shown.
Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem Dim tabctl As TabControl = DirectCast(sender, TabControl) Dim g As Graphics = e.Graphics Dim font As Font = tabctl.Font Dim brush As New SolidBrush(Color.Black) Dim tabTextArea As RectangleF = RectangleF.op_Implicit(tabctl.GetTabRect(e.Index)) If tabctl.SelectedIndex = e.Index Then font = New Font(font, FontStyle.Bold) brush = New SolidBrush(Color.Red) End If g.DrawString(tabctl.TabPages(e.Index).Text, font, brush, tabTextArea) End Sub
Great post! I did some modifications by alignment, colors and background color. For give me my bad English. I'm speak Portuguese.
(Otimo post! Fiz algumas modificacoes de alinhamento, cores e cor do fundo. Perdoe-me o meu Ingles ruim. Falo Portugues)
'cor do tabcontrole Private Sub TabControl_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ContasTabControl.DrawItem Dim tabContas As TabControl = DirectCast(sender, TabControl) Dim sTexto As String = tabContas.TabPages(e.Index).Text Dim g As Graphics = e.Graphics Dim fonte As Font = tabContas.Font Dim format = New System.Drawing.StringFormat 'CHANGES HERE... format.Alignment = StringAlignment.Center format.LineAlignment = StringAlignment.Center Dim pincel As New SolidBrush(Color.Black) 'RENEMED VARIEBLE HERE... Dim retangulo As RectangleF = RectangleF.op_Implicit(tabContas.GetTabRect(e.Index)) If tabContas.SelectedIndex = e.Index Then fonte = New Font(fonte, FontStyle.Bold) pincel = New SolidBrush(Color.Black) 'CHANGED BACKGROUN COLOR HERE... g.FillRectangle(Brushes.White, retangulo) End If g.DrawString(sTexto, fonte, pincel, retangulo, format) End Sub
这篇关于如何在vb.net中选择选定的选项卡标题颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文