Solved

Using colors in ComboBox

Posted on 2004-10-20
5
574 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now