TabControl_DrawItem选项卡的颜色从右到左

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

我正在尝试通过OwnerDrawFixed更改选项卡控件选项卡的颜色,并且此代码在下面可以正常工作,但是我有多种语言的应用程序,因此我需要根据应用程序语言从右向左更改布局,从右向右更改布局,当RightToLiftLayout = true时,我需要帮助使此代码从右向左沉睡,而当它为false时,则需要从左向右沉睡(当前代码)。

谢谢。

'Firstly we'll define some parameters.
Dim CurrentTab As TabPage = TabControl1.TabPages(e.Index)
Dim ItemRect As Rectangle = TabControl1.GetTabRect(e.Index)
Dim FillBrush As New SolidBrush(Color.Red)
Dim TextBrush As New SolidBrush(Color.White)
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center

'If we are currently painting the Selected TabItem we'll 
'change the brush colors and inflate the rectangle.
If CBool(e.State And DrawItemState.Selected) Then
    FillBrush.Color = Color.White
    TextBrush.Color = Color.Red
    ItemRect.Inflate(2, 2)
End If

'Set up rotation for left and right aligned tabs
If TabControl1.Alignment = TabAlignment.Left Or TabControl1.Alignment = TabAlignment.Right Then
    Dim RotateAngle As Single = 90
    If TabControl1.Alignment = TabAlignment.Left Then RotateAngle = 270
    Dim cp As New PointF(ItemRect.Left + (ItemRect.Width \ 2), ItemRect.Top + (ItemRect.Height \ 2))
    e.Graphics.TranslateTransform(cp.X, cp.Y)
    e.Graphics.RotateTransform(RotateAngle)
    ItemRect = New Rectangle(-(ItemRect.Height \ 2), -(ItemRect.Width \ 2), ItemRect.Height, ItemRect.Width)
End If

'Next we'll paint the TabItem with our Fill Brush
e.Graphics.FillRectangle(FillBrush, ItemRect)

'Now draw the text.
e.Graphics.DrawString(CurrentTab.Text, e.Font, TextBrush, RectangleF.op_Implicit(ItemRect), sf)

'Reset any Graphics rotation
e.Graphics.ResetTransform()

'Finally, we should Dispose of our brushes.
FillBrush.Dispose()
TextBrush.Dispose()
vb.net tabcontrol right-to-left
1个回答
0
投票
这未经测试,但我认为您应该可以更改此:

Dim sf As New StringFormat

至此:

Dim sf = If(RightToLeft, New StringFormat(StringFormatFlags.DirectionRightToLeft), New StringFormat)

您可能需要使用RightToLeftLayout而不是RightToLeft。我不确定,因为这不是我做过的事情。
© www.soinside.com 2019 - 2024. All rights reserved.