Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Owner Drawn Combobox Selection Color

Posted on 2004-08-13
8
Medium Priority
?
1,207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 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