Solved

Using colors in ComboBox

Posted on 2004-10-20
5
589 Views
Last Modified: 2013-12-26
I am making a program that displays the value of a resistor when the user enters the colors labeled on the resistor.  I want to use a combobox to allow the user to dropdown the different colors that appear on a resistor and select the appropriate color.  However, i want only the colors to display, not the word "green, Yellow,ect."  Or the color and the text would work.  

how do i select different colors in a combobox??

i have tried ComboBox1.Items.Add(Color.Black), and VB accepts this, but when running the program, it doesn't work properly

thanks
0
Comment
Question by:ssalem33
5 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 500 total points
ID: 12366501
The VB combobox cannot do this.

vbAccelerator.com has a control written in VB6 which is a combobox with added features - one of which is a color picker.
http://www.vbaccelerator.com/home/VB/Code/Controls/Combo_and_List_Boxes/Owner_Draw_Combo_and_List_Box/article.asp

To try it out, download and register these 2 files:

http://www.vbaccelerator.com/home/VB/Code/Controls/Combo_and_List_Boxes/Owner_Draw_Combo_and_List_Box/VB6_Owner_Draw_Combo_List_Control.zip

=and=

http://www.vbaccelerator.com/home/VB/Code/Libraries/Subclassing/SSubTimer/VB6_SSubTmr_Binary.zip

Once unzipped, copy the 2 files to your windows\system32 directory

From the command window, register the 2 files:

regsvr32 SSubTmr.DLL

=and=

regsvr32 vbalODCL6.ocx

Now you can add the control to your project.  From the menu: Project->Components select "vbaccelerator Owner Draw Combo..."

And then to test it our in your form:

Private Sub Form_Load()

With OwnerDrawComboList1

'Set the combo style
.ClientDraw = ecdColourPickerNoNames

'Add the colors
.AddItemAndData "Blk", , , , RGB(8, 8, 8)
.AddItemAndData "Brn", , , , RGB(128, 64, 16)
.AddItemAndData "Red", , , , RGB(200, 32, 32)
.AddItemAndData "Orn", , , , RGB(240, 148, 32)
.AddItemAndData "Yel", , , , RGB(240, 240, 32)
.AddItemAndData "Grn", , , , RGB(32, 200, 32)
.AddItemAndData "Blu", , , , RGB(32, 32, 200)
.AddItemAndData "Vil", , , , RGB(200, 32, 240)
.AddItemAndData "Gra", , , , RGB(128, 128, 128)
.AddItemAndData "Wht", , , , RGB(250, 250, 250)

.ListIndex = 0

'...

'Good Luck
0
 
LVL 6

Expert Comment

by:mmusante
ID: 12367483
You can try using the imagecombo control ...
0
 
LVL 6

Expert Comment

by:mmusante
ID: 12367559
Try this you need a form with a imagecombo, a picture box (make it small) and a imagelist control


Private Sub Form_Load()
   
    Dim Ci As ComboItem
   
    With Picture1
        .BackColor = vbRed
        ImageList1.ListImages.Add , "RED", .Image
        .BackColor = vbBlue
        ImageList1.ListImages.Add , "BLUE", .Image
        .BackColor = vbGreen
        ImageList1.ListImages.Add , "GREEN", .Image
    End With
   
    Set ImageCombo1.ImageList = ImageList1
    With ImageCombo1.ComboItems
        Set Ci = .Add(, "RED", "RED", "RED")
        Set Ci = .Add(, "BLUE", "BLUE", "BLUE")
        Set Ci = .Add(, "GREEN", "GREEN", "GREEN")
    End With
End Sub
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 12376801
Have you seen the way it was done here:

http://www.mbarron.net/Resistor
0
 
LVL 8

Expert Comment

by:Ashutosh Vyas
ID: 12421368
Image Combo Box control does exactly the same thing that you want to. Try searching MSDN for ImageCombo Control

try this
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_other/html/dtlrfImageComboControlVisualBasic6.asp
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question