Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Owner Drawn Combobox Selection Color

Posted on 2004-08-13
8
Medium Priority
?
1,212 Views
Last Modified: 2008-03-06
I have an owner drawn combobox when you dropdown the combobox and highlight an entry the color of the text is black and the hightlight box is also very dark so it makes it hard to see whats inder the selection.  How can i invert the color below the selection box so that it is more visible?
0
Comment
Question by:BangorCC
  • 6
  • 2
8 Comments
 
LVL 28

Accepted Solution

by:
iboutchkine earned 2000 total points
ID: 11795352
set the DrawMode to   DrawMode.OwnerDrawFixed

Private Sub cmb_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles cmb.DrawItem
        e = New System.Windows.Forms.DrawItemEventArgs(e.Graphics, _
                   e.Font, e.Bounds, e.Index, DrawItemState.None, Color.FromArgb(255, 0, 0), Color.FromArgb(255, 255, 255))
        e.DrawBackground()


        Dim sf As StringFormat = StringFormat.GenericDefault   ' Manipulate the stringformat as required
        Dim brsh As SolidBrush

        If e.Index = 2 Then'index of the item i want to change the color
            brsh = New SolidBrush(Color.Blue)
            e.Graphics.DrawString(cmb.Items(e.Index), e.Font, brsh, RectangleF.op_Implicit(e.Bounds), sf)
        Else'index of the rest of the items
            brsh = New SolidBrush(Color.Black)
            e.Graphics.DrawString(cmb.Items(e.Index), e.Font, brsh, RectangleF.op_Implicit(e.Bounds), sf)
        End If
    End Sub

0
 

Author Comment

by:BangorCC
ID: 11795716
ok that works to change the color when i highlight it but when i move the highlight away it stays the same color and doesnt changed back
0
 

Author Comment

by:BangorCC
ID: 11795749
is there anythign i can do to get the index of the current dropdown entry that is highlighted
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

Author Comment

by:BangorCC
ID: 11795803
what is happening is the control is only drawing the highlighted entry how can i force it to redraw all entries
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 11795923
i = cmb.SelectedIndex ; - that will give you the index of selected item. You can check if Item is not selected then change color back

>>what is happening is the control is only drawing the highlighted entry how can i force it to redraw all entries

you can do it in a loop
for i = 0 to cmb.Items.Count-1
  e.Index = i
 .... do the rest
next
0
 

Author Comment

by:BangorCC
ID: 11796565
ok this is what i have

    Protected Shadows Sub DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles MyBase.DrawItem
        Dim brsh As Brush
        e.DrawBackground()
        For x As Integer = 0 To ARList.Count - 1
            If e.Index = x Then
                brsh = Brushes.White
            Else
                brsh = Brushes.Black
            End If

            e.Graphics.DrawString(ARList(e.Index), Me.Font, brsh, _
                    New RectangleF(0, e.Bounds.Y, _
                    e.Bounds.Width, e.Bounds.Height))

        Next


        ' Draw the focus rectangle if the mouse hovers over an item.

        e.DrawFocusRectangle()

    End Sub

what is wrong with this it still doesn't change the selected ones back once i move the highlight box
0
 

Author Comment

by:BangorCC
ID: 11810336
Am i even going in the right direction to highlight the selection right under the cursor by changing the text color it seems that if you change the highlighted field then when the color changes to only part of the dropdown that gets redrawn is the selection directly under the highlight rectangle
0
 

Author Comment

by:BangorCC
ID: 11810836
e.index is the current row being drawn this property is read only is there any way to draw each e.index each time ondrawitem is called.  OnDrawItem is called when you move the focusrectangle over another item in the combobox however it seems that it only draws the e.index that has been highlighted by the focus.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

783 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