我的錯誤是什麼?我想在網站上發佈textbox2.And抱歉,因爲我的英文不好。 :)獲取光標下的單詞是什麼是我的錯誤?
private void txtHoverWord_MouseMove(object sender, MouseEventArgs e){
if (!(sender is TextBox)) return;
var targetTextBox = sender as TextBox;
if (targetTextBox.TextLength < 1) return;
var currentTextIndex = textBox2.GetCharIndexFromPosition(e.Location);
var wordRegex = new Regex(@"(\w+)");
var words = wordRegex.Matches(textBox2.Text);
if (words.Count < 1) return;
var currentWord = string.Empty;
for (var i = words.Count - 1; i >= 0; i--)
{
if (words[i].Index <= currentTextIndex)
{
currentWord = words[i].Value;
break;
}
}
if (currentWord == string.Empty) return;
toolTip1.SetToolTip(textBox2, currentWord);
}
你收到任何錯誤,任何異常? _我的錯誤是什麼?_不是一個好的方法來問.. – 2013-03-26 13:18:30