Solved

Using colors in ComboBox

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2016 VB code 9 102
Specify ip address in my connection string for sas 2 54
Macro which automatically sends attachment to Outlook 14 61
VB6 Compile Compatibility Issue 4 88
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

911 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

16 Experts available now in Live!

Get 1:1 Help Now