Solved

Change font on combobox

Posted on 2008-10-08
4
995 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

20 Experts available now in Live!

Get 1:1 Help Now