Click here to Skip to main content
15,849,130 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have an Windows forms application and a datagridview.
I want to change the columns text size to be set by the user when user clicks a button and sets the font dialog properties. When user will set the font size in the font dialog box the size of the text in the datagridview will change according to user's selection size.
Please help me.
I have done this much with a button click event:
public void Link_Font_Change_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
            FontDialog FntDlg = new FontDialog();

            if (FntDlg.ShowDialog() == DialogResult.OK)
                string fontName;
                fontName = FntDlg.Font.Name;
                float fontSize;
                fontSize = FntDlg.Font.Size;

now i want to set the column text size to font dialog's selection.
Please help me out.
Updated 20-Sep-13 0:38am

You could calculate the new string size using the new font:

if (FntDlg.ShowDialog() == DialogResult.OK)
    System.Drawing.Graphics g = this.CreateGraphics();
    System.Drawing.SizeF size = g.MeasureString( "your current string value" ,FntDlg.Font );
    // do something with the calculated size;
    // ...and after that remember to release the resources.
Share this answer
Share this answer
Jiban jyoti Rana 20-Sep-13 6:03am    
Thanx dear...It worked. but it is changing my total page font size. How i will change the font size of my only datagridview.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900