积极答复者
RichTextBox改变字体

问题
答案
-
参考:
http://www.codeproject.com/KB/miscctrl/WPFRichTextEditor.aspx?msg=3323368
你说的没法加粗的原因是你的rtb认为你的中文编辑还没有结束,自己处理一下就好了
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 zhengkk 2011年4月15日 7:55
全部回复
-
没有这个问题啊,你的代码是什么样的呢?我这边做了一个简单的Demo,WPF窗体程序版,希望能对你有所帮助。
首先前台像楼主一样添加ComboBox和RichTextBox
<ComboBox Name="cbbFont" Margin="12,20,395,265" SelectionChanged="cbbFont_SelectionChanged" /> <RichTextBox Name="rtb" Height="100" HorizontalAlignment="Left" Margin="194,20,0,0" VerticalAlignment="Top" Width="200" />
public MainWindow() { InitializeComponent(); List<string> names = new List<string>(); foreach (FontFamily f in Fonts.SystemFontFamilies) { names.Add(GetFamilyName(f)); } names.Sort(); cbbFont.ItemsSource = names; }
public static string GetFamilyName(FontFamily fontFamily) { XmlLanguage key = XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag); if (fontFamily.FamilyNames.ContainsKey(key)) return fontFamily.FamilyNames[key]; else return fontFamily.Source; }
然后再在ComboBox的选择事件进行如下处理:
private void cbbFont_SelectionChanged(object sender, SelectionChangedEventArgs e) { FontFamily f = new FontFamily(e.AddedItems[0].ToString()); rtb.Document.FontFamily = f; }
- 已建议为答案 About-.NET 2011年4月15日 5:00
-
参考:
http://www.codeproject.com/KB/miscctrl/WPFRichTextEditor.aspx?msg=3323368
你说的没法加粗的原因是你的rtb认为你的中文编辑还没有结束,自己处理一下就好了
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 zhengkk 2011年4月15日 7:55