Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Change font on combobox

Posted on 2008-10-08
4
Medium Priority
?
1,006 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
[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
  • 3
4 Comments
 
LVL 14

Accepted Solution

by:
raja_ind82 earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

721 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