C#检索fontdialog的样式,名称和大小值 [英] C# retrieve the style, name, and size value of a fontdialog
本文介绍了C#检索fontdialog的样式,名称和大小值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我的问题在标题中...
我可以得到名字,大小,但不是风格。你想念我的是什么?
谢谢
我尝试过:
< pre lang =c#>
FontDialog类DLG =新FontDialog类
{
ShowColor =假,
ShowApply =假,
ShowEffects =假,
ShowHelp =假,
// AllowVerticalFonts = false,
// AllowScriptChange = false,
// FixedPitchOnly = true,
MinSize = 9,
MaxSize = 16
};
如果(Dlg.ShowDialog()== DialogResult.OK)
{
串的fontName = Dlg.Font.Name;
fontStyle = Dlg.Font.Style; //这段代码不起作用....
float fontSize = Dlg.Font.Size;
TxtPolice.Text = fontName;
TxtStyle.Text = fontStyle; //这段代码不起作用....
TxtFont.Text =+ fontSize;
}
解决方案
<预郎= C#> fontStyle = Dlg.Font.Style;你在这里使用了一个
fontStyle
变量,它似乎没有声明。请尝试System.Drawing.FontStyle fontStyle = Dlg.Font.Style;。您还可以导入
System.Drawing
命名空间,以便您可以更短的方式引用FontStyle
枚举。
你好,
谢谢你,但我已经解决了我的故事....
这是完整的代码:
FontDialog Dlg = new FontDialog
{
ShowColor = false ,
ShowApply = false ,
ShowEffects = false ,
ShowHelp = false ,
// AllowVerticalFonts = false,
// AllowScriptChange =假,跨度>
<跨度类= 代码注释 > // 跨度> <跨度类= 代码注释> FixedPi tchOnly = true,
MinSize = 9 ,
MaxSize = 16
};
if (Dlg.ShowDialog()== DialogResult.OK)
{
string fontName = Dlg.Font.Name;
Object fontStyle = Dlg.Font.Style;
float fontSize = Dlg.Font.Size;
TxtPolice.Text = fontName;
TxtStyle.Text = fontStyle.ToString();
TxtFont.Text = + fontSize;
}
FontDialog Dlg = new FontDialog
{
ShowColor = false ,
ShowApply = false ,
ShowEffects = false ,
ShowHelp = false ,
'跨度类= 代码注释> // 跨度> <跨度类= 代码注释> AllowVerticalFonts =假,跨度>
<跨度类= 代码注释> / / AllowScriptChange = false,
// FixedPitchOnly = true,
MinSize = 9 ,
MaxSize = 16
};
if (Dlg.ShowDialog()== DialogResult.OK)
{
string fontName = Dlg.Font.Name;
FontStyle fontStyle = Dlg.Font.Style;
float fontSize = Dlg.Font.Size;
TxtPolice.Text = fontName;
TxtStyle.Text = fontStyle.ToString();
TxtFont.Text = + fontSize;
}
Hello, My question is in the title ... I can get the name, the size, but not the Style..What do you miss me? Thank you
What I have tried:
<pre lang="c#"> FontDialog Dlg = new FontDialog { ShowColor = false, ShowApply = false, ShowEffects = false, ShowHelp = false, // AllowVerticalFonts = false, // AllowScriptChange = false, // FixedPitchOnly = true, MinSize = 9, MaxSize = 16 }; if (Dlg.ShowDialog() == DialogResult.OK) { string fontName = Dlg.Font.Name; fontStyle = Dlg.Font.Style; // This code does not work .... float fontSize = Dlg.Font.Size; TxtPolice.Text = fontName; TxtStyle.Text = fontStyle; // This code does not work .... TxtFont.Text = "" + fontSize; }
解决方案
fontStyle = Dlg.Font.Style;You are using here a
fontStyle
variable which it seems you did not declare. TrySystem.Drawing.FontStyle fontStyle = Dlg.Font.Style;instead. You can also import
System.Drawing
namespace so that you can reference theFontStyle
enumeration in a shorter way.
Hello, Thank you, but I have solved my story .... Here is the complete code:
FontDialog Dlg = new FontDialog { ShowColor = false, ShowApply = false, ShowEffects = false, ShowHelp = false, // AllowVerticalFonts = false, // AllowScriptChange = false, // FixedPitchOnly = true, MinSize = 9, MaxSize = 16 }; if (Dlg.ShowDialog() == DialogResult.OK) { string fontName = Dlg.Font.Name; Object fontStyle = Dlg.Font.Style; float fontSize = Dlg.Font.Size; TxtPolice.Text = fontName; TxtStyle.Text = fontStyle.ToString(); TxtFont.Text = "" + fontSize; }
FontDialog Dlg = new FontDialog { ShowColor = false, ShowApply = false, ShowEffects = false, ShowHelp = false, // AllowVerticalFonts = false, // AllowScriptChange = false, // FixedPitchOnly = true, MinSize = 9, MaxSize = 16 }; if (Dlg.ShowDialog() == DialogResult.OK) { string fontName = Dlg.Font.Name; FontStyle fontStyle = Dlg.Font.Style; float fontSize = Dlg.Font.Size; TxtPolice.Text = fontName; TxtStyle.Text = fontStyle.ToString(); TxtFont.Text = "" + fontSize; }
这篇关于C#检索fontdialog的样式,名称和大小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文