Last active
November 6, 2015 02:49
-
-
Save ichengzi/c2e78097f622dc003c71 to your computer and use it in GitHub Desktop.
文字选择器:动态修改字体,大小,粗细等font属性
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// winForm | |
System.Windows.Forms.FontDialog fontDialog = new System.Windows.Forms.FontDialog(); | |
if (fontDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) | |
{ | |
this.textAnnotation.Font.Size = fontDialog.Font.Size; | |
this.textAnnotation.Font.Name = fontDialog.Font.Name; | |
this.textAnnotation.Font.Underline = fontDialog.Font.Underline; | |
this.textAnnotation.Font.Strikeout = fontDialog.Font.Strikeout; | |
this.textAnnotation.Font.Bold = fontDialog.Font.Bold; | |
this.textAnnotation.Font.Italic = fontDialog.Font.Italic; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://stackoverflow.com/questions/11572636/set-value-to-fontdialog-in-wpf/11572921#11572921 | |
// http://blogs.msdn.com/b/text/archive/2006/11/01/sample-font-chooser.aspx | |
// 微软官方博客的字体选择器例子 | |
//WPF | |
System.Windows.Forms.FontDialog fontDialog = new System.Windows.Forms.FontDialog(); | |
if (fontDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) | |
{ | |
FontFamilyConverter ffc = new FontFamilyConverter(); | |
this.textAnnotation.FontSize = fontDialog.Font.Size; | |
this.textAnnotation.FontFamily =(FontFamily)ffc.ConvertFromString(fontDialog.Font.Name); | |
if (fontDialog.Font.Bold) | |
textAnnotation.FontWeight = FontWeights.Bold; | |
else | |
textAnnotation.FontWeight = FontWeights.Normal; | |
if (fontDialog.Font.Italic) | |
textAnnotation.FontStyle = FontStyles.Italic; | |
else | |
textAnnotation.FontStyle = FontStyles.Normal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment