private void SynchronzieFontFamilies() { Object obj = null; //显示当前字体 if (RichTextBox1.Selection.IsEmpty) //如果当前没选中文字 { TextRange nearestChar = rtfManager.GetPrevChar(RichTextBox1.CaretPosition); if ((nearestChar != null) && MySuperEditorHelper.IsTwoByteChineseChar(nearestChar.Text)) //是汉字,获取离光标最近字符的字体 obj = nearestChar.GetPropertyValue(TextElement.FontFamilyProperty); else //不是汉字,或者文档为空直接调用RichTextBox默认功能实现 obj = RichTextBox1.Selection.GetPropertyValue(TextElement.FontFamilyProperty); } else //如果当前选中文字 obj = RichTextBox1.Selection.GetPropertyValue(TextElement.FontFamilyProperty); if (obj is FontFamily) //设置字体下拉框选项为当前字体 { String FontName = MySuperEditorHelper.GetLocaliteFontName((FontFamily)obj); //此句居然会引发TabControl的SelectionChanged事件?真是诡异! cboFontFamilies.Text = FontName; } }
private void SynchronzieFontFamilies() { Object obj = null; //显示当前字体 if (RichTextBox1.Selection.IsEmpty) //如果当前没选中文字 { TextRange nearestChar = rtfManager.GetPrevChar(RichTextBox1.CaretPosition); if ((nearestChar != null) && MySuperEditorHelper.IsTwoByteChineseChar(nearestChar.Text)) { //是汉字,获取离光标最近字符的字体 obj = nearestChar.GetPropertyValue(TextElement.FontFamilyProperty); } else { //不是汉字,或者文档为空直接调用RichTextBox默认功能实现 obj = RichTextBox1.Selection.GetPropertyValue(TextElement.FontFamilyProperty); } } else //如果当前选中文字 { obj = RichTextBox1.Selection.GetPropertyValue(TextElement.FontFamilyProperty); } }