| Код | Dim names() As String Dim values As Array
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click names = [Enum].GetNames(GetType(System.Drawing.KnownColor)) values = [Enum].GetValues(GetType(System.Drawing.KnownColor)) Dim i As Integer With ComboBox1 .DrawMode = DrawMode.OwnerDrawFixed AddHandler .DrawItem, AddressOf PaintColor For i = 0 To names.Length - 1 .Items.Add(String.Format("{0} = {1}", names(i), CInt(values.GetValue(i)))) Next End With End Sub
Private Sub PaintColor(ByVal sender As Object, ByVal e As DrawItemEventArgs) Dim g As Graphics = e.Graphics e.DrawBackground() Dim rectangle As Rectangle = New Rectangle(2, e.Bounds.Top + 2, _ e.Bounds.Height, e.Bounds.Height - 4) e.Graphics.FillRectangle(New SolidBrush(System.Drawing.Color.FromName(names(e.Index))), rectangle) e.Graphics.DrawString(names(e.Index), e.Font, System.Drawing.Brushes.Black, _ New RectangleF(e.Bounds.X + rectangle.Width, e.Bounds.Y, _ e.Bounds.Width, e.Bounds.Height)) e.DrawFocusRectangle() End Sub
| |