我有自定义' combobox'而且我使用的是阿拉伯语,我需要从右到左,默认情况下使用“组合框”#39;我可以从属性中更改它,但在此自定义' Combobox'它没有改变,所以如何修改类使其从右到左?
这就是我正在使用的:
Class AdvancedComboBox
Inherits ComboBox
Public Shadows Property DrawMode() As System.Windows.Forms.DrawMode
Get
Return m_DrawMode
End Get
Set
m_DrawMode = Value
End Set
End Property
Private Shadows m_DrawMode As System.Windows.Forms.DrawMode
Public Property HighlightColor() As Color
Get
Return m_HighlightColor
End Get
Set
m_HighlightColor = Value
End Set
End Property
Private m_HighlightColor As Color
Public Sub New()
MyBase.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
Me.HighlightColor = Color.Orange
AddHandler Me.DrawItem, New DrawItemEventHandler(AddressOf AdvancedComboBox_DrawItem)
End Sub
Private Sub AdvancedComboBox_DrawItem(sender As Object, e As DrawItemEventArgs)
If e.Index < 0 Then
Return
End If
Dim combo As ComboBox = TryCast(sender, ComboBox)
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
e.Graphics.FillRectangle(New SolidBrush(HighlightColor), e.Bounds)
Else
e.Graphics.FillRectangle(New SolidBrush(combo.BackColor), e.Bounds)
End If
e.Graphics.DrawString(combo.Items(e.Index).ToString(), e.Font, New SolidBrush(combo.ForeColor), New Point(e.Bounds.X, e.Bounds.Y))
e.DrawFocusRectangle()
End Sub
End Class
答案 0 :(得分:3)
目前还不清楚为什么RightToLeft属性在属性框中不适合你,但由于你是自定义绘图,你应该使用右对齐属性。此外,最好使用TextRenderer而不是DrawString来匹配其他控件使用的渲染器:
'e.Graphics.DrawString(combo.Items(e.Index).ToString(), e.Font,
' New SolidBrush(combo.ForeColor), New Point(e.Bounds.X, e.Bounds.Y))
TextRenderer.DrawText(e.Graphics, combo.Items(e.Index).ToString, e.Font, e.Bounds,
combo.ForeColor, Color.Empty,
TextFormatFlags.Right Or TextFormatFlags.RightToLeft)
答案 1 :(得分:0)
如果它始终是从右到左,那么您可以在AdvancedComboBox
构造函数中执行此操作:
MyBase.RightToLeft = Windows.Forms.RightToLeft.Yes