macraee
macraee

Reputation: 75

Changing Font Size for ListView Column in C#

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

Upvotes: 2

Views: 12827

Answers (1)

jlvaquero
jlvaquero

Reputation: 8785

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.

Upvotes: 5

Related Questions