Solved

Owner Drawn Combobox Selection Color

Posted on 2004-08-13
8
1,201 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
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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