gpt4 book ai didi

vb.net - 组合框文本从右到左对齐?

转载 作者:行者123 更新时间:2023-12-04 20:51:06 25 4
gpt4 key购买 nike

我有这个代码来改变组合框的填充颜色,一切都很完美但我需要使组合框文本从右到左对齐,请提供任何帮助。

这是我的代码:

Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
If e.Index < 0 Then Exit Sub
Dim rect As Rectangle = e.Bounds
If e.State And DrawItemState.Selected Then
e.Graphics.FillRectangle(Brushes.LightSeaGreen, rect) 'change the selected color you like
Else
e.Graphics.FillRectangle(SystemBrushes.Window, rect)
End If
Dim colorname As String = ComboBox1.Items(e.Index)
Dim ba As New SolidBrush(Color.FromName(colorname))
Dim b2 As Brush = Brushes.Black 'add one
e.Graphics.DrawString(colorname, Me.ComboBox1.Font, b2, rect.X, rect.Y)
End Sub

Private Sub combo_colors1()
Me.ComboBox1.DrawMode = DrawMode.OwnerDrawFixed
Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
Me.ComboBox1.BeginUpdate()
ComboBox1.EndUpdate()
End Sub

最佳答案

尝试使用 TextRenderer.DrawText 方法的格式化标志:

'e.Graphics.DrawString(colorname, Me.ComboBox1.Font, Brushes.Black, rect.X, rect.Y)
TextRenderer.DrawText(e.Graphics, colorname, Me.ComboBox1.Font, e.Bounds, _
Color.Black, Color.Empty, _
TextFormatFlags.Right Or TextFormatFlags.VerticalCenter)

关于vb.net - 组合框文本从右到左对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29125477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com