I posted a bit of VB code the other day, http://discussion.autodesk.com/thread.jspa?messageID=5265316, to show how to put colors into a combobox, but the poster was wanting only the ACAD colors to appear. The other day another poster, http://discussion.autodesk.com/thread.jspa?threadID=509236, was looking, I think, to do something similar so I decided to alter the code a bit to have it work with the 255 ACAD colors.
Here is the code in case any of you want to play with it yourself. Might be useful? Might not.
Public Class Form1
Private ACADcolors() As String
Private a As Integer
Private r As Integer
Private g As Integer
Private b As Integer
Private i As Integer
Private Saved As String
Private SavedColor As Drawing.Color
Private Sub InitializeComboBox()
Me.ComboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable
ACADcolors = New String() {"RED", "YELLOW", "GREEN", "CYAN", "BLUE", "MAGENTA", "WHITE", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "123", "124", "125", "126", "127", "128", "129", "130", "131", "132", "133", "134", "135", "136", "137", "138", "139", "140", "141", "142", "143", "144", "145", "146", "147", "148", "149", "150", "151", "152", "153", "154", "155", "156", "157", "158", "159", "160", "161", "162", "163", "164", "165", "166", "167", "168", "169", "170", "171", "172", "173", "174", "175", "176", "177", "178", "179", "180", "181", "182", "183", "184", "185", "186", "187", "188", "189", "190", "191", "192", "193", "194", "195", "196", "197", "198", "199", "200", "201", "202", "203", "204", "205", "206", "207", "208", "209", "210", "211", "212", "213", "214", "215", "216", "217", "218", "219", "220", "221", "222", "223", "224", "225", "226", "227", "228", "229", "230", "231", "232", "233", "234", "235", "236", "237", "238", "239", "240", "241", "242", "243", "244", "245", "246", "247", "248", "249", "250", "251", "252", "253", "254", "255"}
Me.ComboBox1.DataSource = ACADcolors
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim c As Autodesk.AutoCAD.Colors.Color
c = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, ComboBox1.SelectedIndex + 1)
a = c.ColorValue.A.ToString
r = c.ColorValue.R.ToString
g = c.ColorValue.G.ToString
b = c.ColorValue.B.ToString
i = c.ColorIndex.ToString
Me.ComboBox1.BackColor = Drawing.Color.FromArgb(a, r, g, b)
End Sub
Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
Dim myFont As System.Drawing.Font
Dim myColor As New System.Drawing.Color
Dim c As Autodesk.AutoCAD.Colors.Color
c = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, e.Index + 1)
a = c.ColorValue.A.ToString
r = c.ColorValue.R.ToString
g = c.ColorValue.G.ToString
b = c.ColorValue.B.ToString
i = c.ColorIndex.ToString
myColor = Drawing.Color.FromArgb(a, r, g, b)
e.DrawBackground()
Dim rectangle As Drawing.Rectangle = New Drawing.Rectangle(2, e.Bounds.Top + 2, e.Bounds.Height + 20, e.Bounds.Height - 4)
e.Graphics.FillRectangle(New Drawing.SolidBrush(myColor), rectangle)
myFont = New Drawing.Font("arial", 10, Drawing.FontStyle.Regular)
e.Graphics.DrawString(ACADcolors(e.Index), myFont, System.Drawing.Brushes.Black, New Drawing.RectangleF(e.Bounds.X + rectangle.Width, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
e.DrawFocusRectangle()
End Sub
Private Sub ComboBox1_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.DropDown
Saved = ComboBox1.Text
SavedColor = ComboBox1.BackColor
Me.ComboBox1.BackColor = Drawing.Color.White
End Sub
Private Sub ComboBox1_DropDownClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.DropDownClosed
If ComboBox1.Text = Saved Then
ComboBox1.BackColor = SavedColor
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call InitializeComboBox()
Me.ComboBox1.Text = ""
Me.ComboBox1.BackColor = Drawing.Color.White
End Sub
End Class