Solved

Change font on combobox

Posted on 2008-10-08
4
1,000 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

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Read top line from CSV file 14 60
EF5 How do I stop pre-compiled views? 8 57
How do you think this website does searches? 5 36
Javascript function 3 23
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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

752 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