Change font in ListBox

I want to have different style of font in ListBox like italic, bold and normal. How do I do that in .net CF

Answer this question

Change font in ListBox

  • MMDG

    Is this also possible to due in ASP.NET, not windows forms I would really love to figure out how to change the font and color of individual lines in the listboxes.

  • milicica

    Hi Tan .NetCF,

    to change the font style at runtime, you should reset the font of the control like the following:

    (form1 will have a combobox1 filled with items, and the code below will change the font to Courier with Bold style)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

      ComboBox1.Font = New System.Drawing.Font("Courier New", 9.0!, System.Drawing.FontStyle.Bold)

    End Sub

    good luck

    mario aoun



  • akin_l

    I am using ListBox control, not Combox. I could not find the property to change each individual line.
  • Harry_Leboeuf

    Try looking at the MSDN docs for Listbox. The font property can be found here:

    http://msdn2.microsoft.com/en-us/library/system.windows.forms.listbox.font.aspx

    You can use this with the same code as above except with a listbox.

    Also if you press F1 while you are in Visual Studio a world of knowledge will appear



  • Mike Haro

    JR Lyon,

    Can I set bold for 1st line and italic for 2nd line for example


  • Kinlan

    Hi Tan,

    what you're looking for is an owner-drawn ListBox.

    That could be done with the DrawMode property:

    http://msdn2.microsoft.com/en-us/library/system.windows.forms.listbox.drawmode.aspx

    Unfortunately this property is not supported in the Compact Framework, so a solution

    could be writing your own Custom Control implementing a list of items, each with its own Font.

    Gian Paolo Costantino


  • Change font in ListBox