【发布时间】:2011-02-01 14:31:04
【问题描述】:
这是我的工作:
Public Class ComboBox
Inherits System.Windows.Forms.ComboBox
Public Sub New()
SetStyle(ControlStyles.OptimizedDoubleBuffer _
Or ControlStyles.UserPaint, True)
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
e.Graphics.FillRectangle(gradient, ClientRectangle)
// The preceding line is a simplification of about 50 lines of code.
If Not String.IsNullOrEmpty(Text) Then
Dim rect As New Rectangle(2, 0, Width - 2, Height)
Using format As New StringFormat()
format.LineAlignment = StringAlignment.Center
Using brush As New SolidBrush(ForeColor)
e.Graphics.DrawString(Text, Font, brush, rect, format)
End Using
End Using
End If
e.Graphics.FillPolygon(Brushes.Black, New Point() { _
New Point(Width - 5, Height \ 2 - 1), _
New Point(Width - 12, Height \ 2 - 1), _
New Point(Width - 9, Height \ 2 + 3)})
End Sub
End Class
我有两个问题:
- 它的高度始终为 24。
- 下拉列表使用难看的 Windows 3.1 字体呈现。
【问题讨论】:
-
你想做什么?为什么不能使用常规的 ComboBox?
-
公司聘请了一位艺术家。他画东西。现在我必须实施它。 (在你问之前:我不能使用 WPF。)
标签: .net winforms combobox custom-controls