Solved

Change font on combobox

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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 …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 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