Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
Hello Experts,

I have Combo box and I want to change the color of it. After searching in google, I found this.

http://stackoverflow.com/questions/13212179/changing-the-color-of-combobox-highlighting[^]

Now I am stuck with how to use this class. I just created a class with the code as mentioned in above link. But how do I call/ execute that class for a combobox I want to.

Please help me in understanding this.
Posted

1 solution

You need to use this class AdvancedComboBox : ComboBox instead of your ComboBox Control. This method is called "Subclassing" and you can take a look how to do it:
Quote:
How to subclass windows in Windows Forms by using Visual Basic .NET
[^]

I would rather simply use a place holder in the WinForm and create a control in the source code like this:

VB
Dim oCmbBox As AdvancedComboBox = New AdvancedComboBox()


Then you can move it on the right place using the coordinates of the place holder ...
 
Share this answer
 
v5
Comments
sudevsu 19-May-15 9:47am    
I get an Error in line Me.DrawItem += New DrawItemEventHandler(AddressOf AdvancedComboBox_DrawItem)

from


Public Sub New()
MyBase.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
Me.HighlightColor = Color.Gray
Me.DrawItem += New DrawItemEventHandler(AddressOf AdvancedComboBox_DrawItem)
End Sub

Error is: public Event DrawItem is an event and cannot be called directly. Use a Raise Event statement to Raise

Could you please help in this? How do I use RaiseEvent for this?
Richard Deeming 19-May-15 10:00am    
Your converter is producing incorrect code - that line should be:
AddHandler Me.DrawItem, AddressOf AdvancedComboBox_DrawItem
sudevsu 19-May-15 10:05am    
Even after adding the line which was mentioned above, it doesn't go into the function
Private Sub AdvancedComboBox_DrawItem(ByVal sender As Object, ByVal e As DrawItemEventArgs)

Leo Chapiro 19-May-15 10:03am    
Sure you get an error: the source code is C# and you try to directly use it in VB.NET without to adjust it!
So use AddHandler rather then += New !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900