1: WPF不支持直接实例化TTF文件。TTF 字体需要先安装到系统中。(想让程序自晌衫动装TTF请看这里http://blog.csdn.net/nickwar/article/details/5174259)
2:然后把装好的字体名称放入资源中。
3:参考我给出的代码设置FontFamily属性:
。。。。。。。。。。。。。。。。。。
public MainWindow(){
InitializeComponent()
FontFamily family=GetFontFamily("Your installed TTF font name")
宴弊腔 this.FontFamily = family ?? this.FontFamily
}
private FontFamily GetFontFamily(String resourceKey)
{
if (String.IsNullOrEmpty(resourceKey))
{
return null
}
卜没 FontFamily fontFamily = null
Object ttfName = this.TryFindResource(resourceKey)
if (ttfName != null)
{
fontFamily = new FontFamily(ttfName.ToString())
}
return fontFamily
}
。。。。。。。。。。。。。。。。。。。
string fileDir = Environment.CurrentDirectoryConsole.WriteLine("当前程序目录:"+fileDir)
//一个文件目录
string filePath = "C:\\bin\\files\\test.xml"
Console.WriteLine("该文件的目录:"+filePath) string str = "获取文件的全路径:" + Path.GetFullPath(filePath) //-->C:\bin\files\test.xmlConsole.WriteLine(str)
str = "获取文件所在的目录:" + Path.GetDirectoryName(filePath)//-->C:\碧余bin\filesConsole.WriteLine(str)
str = "获取文件的名称含有后缀:" + Path.GetFileName(filePath) //-->test.xmlConsole.WriteLine(str)
str = "获取文件的顷乱名称没有后缀:" + Path.GetFileNameWithoutExtension(filePath)//-->testConsole.WriteLine(str)
str = "获取路径的后缀扩展雀慧档名称:" + Path.GetExtension(filePath)//-->.xmlConsole.WriteLine(str)
str = "获取路径的根目录:" + Path.GetPathRoot(filePath)//-->C:\Console.WriteLine(str)
Console.ReadKey()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)