Solved

Change font on combobox

Posted on 2008-10-08
4
996 Views
Last Modified: 2013-11-26
I want to change the font of the highlighted item in a combo box. So if I click the combo box and hover over an item the font will change to 18 and when I hover over the next item the previous item goes back to 12 and the newly highlighted item goes to 18. So on and so forth. Once I select the item the text will go back to 12 in the combobox.
0
Comment
Question by:cobolinx1
  • 3
4 Comments
 
LVL 14

Expert Comment

by:raja_ind82
ID: 22676157
0
 
LVL 14

Accepted Solution

by:
raja_ind82 earned 500 total points
ID: 22676260
Here is the exact code for you.....

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ComboBox1.Items.Add("Raja")
        ComboBox1.Items.Add("Raja 2")
        ComboBox1.Items.Add("Raja 3 ")
        ComboBox1.Items.Add("Raja 4")
    End Sub

    Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
        Dim c As System.Drawing.Color
        Dim f As Font
        Dim tc As Color
        c = Color.White
        tc = Color.Black
        If e.State = DrawItemState.Selected Then
            f = New System.Drawing.Font("Tahoma", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Else
            f = New System.Drawing.Font("Tahoma", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        End If
        e.Graphics.DrawRectangle(New Pen(c), New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
        e.Graphics.FillRectangle(New SolidBrush(c), New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
        e.Graphics.DrawString(Me.ComboBox1.Items.Item(e.Index), f, New SolidBrush(tc), New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
    End Sub

Regards,
M.Raja
0
 
LVL 14

Expert Comment

by:raja_ind82
ID: 22676542
hey i forgot to add this line in form load or you can change in property page
combobox1.DrawMode=DrawMode.OwnerDrawVariable
0
 

Author Closing Comment

by:cobolinx1
ID: 31504519
once I did OwnerDrawVariable it worked like a charm
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

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

930 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

12 Experts available now in Live!

Get 1:1 Help Now