Solved

Owner Drawn Combobox Selection Color

Posted on 2004-08-13
8
1,197 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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
is there anythign i can do to get the index of the current dropdown entry that is highlighted
0
 

Author Comment

by:BangorCC
Comment Utility
what is happening is the control is only drawing the highlighted entry how can i force it to redraw all entries
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 28

Expert Comment

by:iboutchkine
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 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

13 Experts available now in Live!

Get 1:1 Help Now