本文介绍了我该怎么做 ?在Window中获取光标下的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码只能从文本框中获取我想进入窗口,例如weppage或文本文件如何?



My code only get from textbox I want to get on window such as a weppage or text file HOW ?

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 = targetTextBox.GetCharIndexFromPosition(e.Location);
    var wordRegex = new Regex(@"(\w+)");
    var words = wordRegex.Matches(targetTextBox.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(targetTextBox, currentWord);
}

推荐答案


这篇关于我该怎么做 ?在Window中获取光标下的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 22:07