Results 1 to 9 of 9

Thread: Colorful combo box

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2005
    Location
    Minnesota
    Posts
    46

    Colorful combo box

    I am making a program to calculate the resistance of a resistor. If you do not know resistors have a color code by the rings of colors. I made a combo box with all the colors printed on it but I’m looking for a way to change the colors of the text so that the text Red will be in a red font. I need every color to be different in the same combo box. Is this possible? If so how?

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Colorful combo box

    yea it's possible. You need to search for "owner drawn combo box" and read some basic articles. You have to change the DrawMode property of your combo box and do the drawing manually. Search on www.codeproject.com perhaps
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2005
    Location
    Minnesota
    Posts
    46

    Re: Colorful combo box

    I can’t seem to find any thing related to visual basic. A lot of C# and C++.

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Colorful combo box

    don't have time right now otherwise I'd just do it
    a quick search... see if it helps
    http://www.devx.com/dotnet/Article/8014/0/page/3
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2005
    Location
    Minnesota
    Posts
    46

    Re: Colorful combo box

    Ok I am a beginner to visual basic or programming in general. I have never done an owner drawn combo box before. This is all new to me. I have a list of colors I need. I do like the link you gave me but I just don’t understand it.

    The colors I need are:
    Black, Brown, Red, Orange, Yellow, Green, Blue, Violet, Grey, White. I would prefer it to be in this order, because the index number works well with the math. But I can do it other ways.

    If anyone can find me a better example, or have time to write some code I would greatly apprentice it.

  6. #6
    Lively Member
    Join Date
    Jun 2005
    Posts
    76

    Re: Colorful combo box

    VB Code:
    1. Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    2.  
    3. Dim cboSender As ComboBox
    4. cboSender = CType(sender, ComboBox)
    5.  
    6. Select Case cboSender.SelectedIndex
    7.     Case Color.Black
    8.         cboSender.BackColor = System.Drawing.Color.Black
    9.     Case Color.Brown
    10.         cboSender.BackColor = System.Drawing.Color.Brown
    11.     Case Color.Red
    12.         cboSender.BackColor = System.Drawing.Color.Red
    13.     Case Color.Orange
    14.         cboSender.BackColor = System.Drawing.Color.Orange
    15.     Case Color.Yellow
    16.         cboSender.BackColor = System.Drawing.Color.Yellow
    17.  
    18.     'rest of the cases
    19.  
    20. End Select
    21. End Sub
    22.  
    23. Private Enum Color
    24.              Black
    25.     Brown
    26.     Red
    27.     Orange
    28.     Yellow
    29.     Green
    30.     Blue
    31.     Violet
    32.     Gray
    33.     White
    34. End Enum

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2005
    Location
    Minnesota
    Posts
    46

    Re: Colorful combo box

    I hope I’m not being too picky, what I really want is the text color to change for every item when you pull it down, not after you select an item. But I do like the ideal of changing the back color meboz. I can use that for another program.

    I guess it is not that important, it would be nice if we could get it to work that way, and it doesn’t serve any practical purpose just for looks.

  8. #8
    Lively Member
    Join Date
    Jun 2005
    Posts
    76

    Re: Colorful combo box

    For the text color to be different for each item you need to do what MrPolite has suggested : )

    PS. If we weren't picky, we wouldn't be programmers...

  9. #9

    Thread Starter
    Member
    Join Date
    Jan 2005
    Location
    Minnesota
    Posts
    46

    Re: Colorful combo box

    Ok, that makes me feel better, but can any one explain to me how I can do this in a better way then the site does. Code with comments would be great.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width