Windows窗体应用程序中带有C#的字体对话框 [英] Font Dialog with C# in windows forms application

查看:191
本文介绍了Windows窗体应用程序中带有C#的字体对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows窗体应用程序和一个datagridview。

我想更改用户单击按钮时设置的列文本大小并设置字体对话框属性。当用户在字体对话框中设置字体大小时,datagridview中文本的大小将根据用户的选择大小而改变。

请帮助我。

我有通过按钮点击事件完成了这么多:

  public   void  Link_Font_Change_LinkClicked( object  sender,LinkLabelLinkClickedEventArgs e)
{
FontDialog FntDlg = new FontDialog();
FntDlg.ShowDialog();

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

}
}



现在我想将列文本大小设置为字体对话框的选择。

请帮帮我。

解决方案

您可以使用新字体计算新的字符串大小:



  if (FntDlg.ShowDialog()== DialogResult.OK)
{
System.Drawing.Graphics g = this .CreateGraphics();
System.Drawing.SizeF size = g.MeasureString( 您当前的字符串值, FntDlg.Font);
// 使用计算出的大小执行某些操作;
// ...之后记得释放资源。
}


访问这里..



http://msdn.microsoft.com/en-us/library/ system.windows.forms.fontdialog.apply.aspx?cs-save-lang = 1& cs-lang = csharp#code-snippet-2 [ ^ ]

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();
            FntDlg.ShowDialog();

            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.

解决方案

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.
}


visit here..

http://msdn.microsoft.com/en-us/library/system.windows.forms.fontdialog.apply.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2[^]


这篇关于Windows窗体应用程序中带有C#的字体对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆