Solved

Using colors in ComboBox

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

830 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