Solved

Owner Drawn Combobox Selection Color

Posted on 2004-08-13
8
1,205 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 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
Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

 

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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
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…

617 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