我该怎么做 ?在Window中获取光标下的单词 [英] How can I do it ? Get the word under the cursor in Window

查看:94
本文介绍了我该怎么做 ?在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);
}

推荐答案

如果没有真诚的努力,你所要求的几乎是不可能的。

请记住,由于您的程序与首先呈现单词的目标应用程序(您的浏览器,记事本等)完全没有关联,因此您必须采用不同的策略而不仅仅是简单的鼠标悬停事件。

我的建议是尝试捕获鼠标下的区域然后应用OCR。

我无法想到可以做任何其他方式。
What you are asking for is close to impossible without sincere effort.
Remember that since your program will have absolutely no connection with the target application which has rendered the word in the first place (your browser, notepad etc), you have to resort to different tactics than just a simple mouse hover event.
My suggestion is to try to capture the area under the mouse and then applying OCR.
I can''t think of any other way this can be done.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆