我啓用了我的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. WPF RichTextBox - 獲取當前行
- 2. richtextbox獲取當前行的文本(插入符號閃爍處)
- 3. 獲取當前位置
- 4. 獲取當前位置
- 5. 獲取當前位置
- 6. 獲取當前位置
- 7. 獲取當前位置android
- 8. 獲取當前位置ImageView
- 9. Android獲取當前位置
- 10. android獲取當前位置
- 11. 在TextBox中獲取插入位置
- 12. CLLocation當前位置獲取位置
- 13. RichTextBox C#設置插入位置winforms
- 14. 插入rtf字符串時的RichTextBox插入符號位置
- 15. WPF,RichTextBox在獲取光標位置的正確textproperties問題
- 16. ckeditor - 獲取當前光標位置的前一個字符
- 17. 如何「恢復」Wpf RichTextBox中的插入位置?
- 18. WPF在插入列表後移動插入位置
- 19. Python:獲取插入位置
- 20. 當AllowTab設置爲false時,將選項卡插入WPF RichTextBox
- 21. 在android中獲取當前位置
- 22. 在當前位置獲取標記
- 23. 在地圖上獲取當前位置
- 24. 在GPS中獲取當前位置?
- 25. 在mysql表中獲取當前位置
- 26. Wpf Richtextbox某個文本的位置
- 27. 在記事本++插件中獲取當前光標位置
- 28. 在RichTextBox光標位置插入字符串
- 29. WPF RichTextBox位置插入符號與給定索引的可見字符
- 30. 在textarea(IE)中獲取插入位置
這是用於wpf – 2011-04-21 08:22:28