我启用了我的WPF richtextbox上的拼写,并且我想在显示拼写建议的上下文菜单之前,在当前插入符的位置上得到拼写错误的单词。WPF RichTextBox - 在当前插入位置获取整个字
2
A
回答
4
的新途径
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;
}
}
1
检查了这一点 http://www.dotnetfunda.com/articles/article842-spellchecker-in-wpf-.aspx
权在这里似乎讨论一些选项可以帮助您的方案: “在这里我们使用SpellingError类来获取Suggessions CaretIndex返回,其中克拉的索引文本框。GetSpellingError可以返回SpellingError对象仅在当前位置克拉有错误的单词也拼写检查对TextBox启用。“
1
旧的方式
private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Back)
{
var z = this.richTextBox1.SelectionStart;
var r = richTextBox1.Find(" ", 0, z, RichTextBoxFinds.None | RichTextBoxFinds.Reverse);
var q = this.richTextBox1.Text.Substring(r + 1, z - r - 1);
switch (q)
{
case "test":
this.richTextBox1.SelectionStart = r + 1;
this.richTextBox1.SelectionLength = z - r - 1;
this.richTextBox1.SelectionColor = Color.Black;
this.richTextBox1.SelectionStart += this.richTextBox1.SelectionLength;
this.richTextBox1.SelectionLength = 0;
//e.Handled = true;
break;
default:
this.richTextBox1.SelectionStart = z;
break;
}
}
}
+0
'z'? 'r'? 'q'? :O – superjos 2016-06-05 07:59:07
1
以供将来参考:
void richTextBox1_PreviewKeyDown(object sender, KeyEventArgs e)
{
var rtb = (RichTextBox)sender;
var tr = rtb.GetSpellingErrorRange(rtb.CaretPosition);
if(tr != null)
{
string spellingerror = tr.Text;
//Do whatever
}
}
+1
'tr'?也许给变量适当的全名可能有助于其他人到这里寻找答案 – superjos 2016-06-05 08:00:22
相关问题
- 1. richtextbox获取当前行的文本(插入符号闪烁处)
- 2. Android获取当前位置
- 3. android获取当前位置
- 4. 获取当前位置android
- 5. 获取当前位置
- 6. 获取当前位置
- 7. 获取当前位置
- 8. WPF,RichTextBox在获取光标位置的正确textproperties问题
- 9. 如何“恢复”Wpf RichTextBox中的插入位置?
- 10. 当AllowTab设置为false时,将选项卡插入WPF RichTextBox
- 11. 在GPS中获取当前位置?
- 12. 在mysql表中获取当前位置
- 13. 在地图上获取当前位置
- 14. 在WPF中失去焦点时获取插入符号位置
- 15. Wpf Richtextbox某个文本的位置
- 16. WPF RichTextBox位置插入符号与给定索引的可见字符
- 17. 在textarea(IE)中获取插入位置
- 18. 如何将插入符号移动到WPF RichTextBox中的某个位置?
- 19. 在输入列表中获取当前位置
- 20. JavaScript'contenteditable' - 获取/设置插入位置
- 21. 从RichTextBox获取滚动位置?
- 22. 如何获取RichTextBox的滚动位置?
- 23. 获取RichTextBox插入的XY坐标
- 24. blackberry gps获取当前位置地址?
- 25. 从react-router-redux获取当前位置
- 26. 使用CLLocationCoordinate2D获取当前位置
- 27. osmdroid获取当前用户位置
- 28. 如何获取当前的GPS位置?
- 29. Android - 可靠地获取当前位置
- 30. 如何获取当前位置android?
这是用于wpf – 2011-04-21 08:22:28