Changing Font Size for ListView Column in C#

11,274

This could help:

// Draws column headers.
private void listView1_DrawColumnHeader(object sender,
    DrawListViewColumnHeaderEventArgs e)
{
    using (StringFormat sf = new StringFormat())
    {
        // Store the column text alignment, letting it default
        // to Left if it has not been set to Center or Right.
        switch (e.Header.TextAlign)
        {
            case HorizontalAlignment.Center:
                sf.Alignment = StringAlignment.Center;
                break;
            case HorizontalAlignment.Right:
                sf.Alignment = StringAlignment.Far;
                break;
        }

        // Draw the standard header background.
        e.DrawBackground();

        // Draw the header text.
        using (Font headerFont =
                    new Font("Helvetica", 10, FontStyle.Bold)) //Font size!!!!
        {
            e.Graphics.DrawString(e.Header.Text, headerFont,
                Brushes.Black, e.Bounds, sf);
        }
    }
    return;
}

See msdn for more info.

Share:
11,274
macraee
Author by

macraee

Updated on June 04, 2022

Comments

  • macraee
    macraee almost 2 years

    I am creating a simple GUI, containing a listView which will be for use with a touch screen monitor. Therefore I require the text to be large, so it is easily readable and selectable. I can change the Font property of my listView to increase its size, although this also increases the column header font size in proportion (making the letters too big for the space).

    Is there a method to change just the font size of the listView items and/or a means of changing the size of the text space of the column to cater for bigger letters?

    I think I can use the ListBox.DrawColumnHeader event for this but I cannot figure out exactly how to piece it together!

    Thanks in advance

  • macraee
    macraee over 12 years
    This is how to do it, thanks! I found the same link with a whole sample code for anyone interested, its here: msdn.microsoft.com/en-us/library/…