我在 WPF Richtextbox 上启用了拼写功能,并且希望在显示带有拼写建议的上下文菜单之前获取当前插入符号位置处拼写错误的单词。
新方式
void richTextBox1_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Back)
{
TextPointer start = richTextBox1.CaretPosition;
string text1 = start.GetTextInRun(LogicalDirection.Backward);
TextPointer end = start.GetNextContextPosition(LogicalDirection.Backward);
string text2 = end.GetTextInRun(LogicalDirection.Backward);
richTextBox1.Selection.Select(start, end);
richTextBox1.Selection.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Black);
richTextBox1.Selection.Select(start, start);
//e.Handled = true;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)