【问题标题】:Get the text under the mouse pointer in windows in any application在任何应用程序的窗口中获取鼠标指针下的文本
【发布时间】:2023-03-04 02:02:01
【问题描述】:

在我添加这个问题之前,我已经在这个网站上搜索了我的问题 - 根据网站的发布规则 - 我找到了这些链接,但它没有帮助我:

  1. Get word under mouse pointer
  2. get the text under the mouse pointer
  3. Getting the text under the mouse pointer

我的问题是: 我正在编写一本地质词典,它现在可供用户使用,但我想添加一个功能,让用户在特定时间段内将鼠标移到特定单词上时可以看到特定单词的翻译,并且该单词可能在任何像 MS Word、IE、Firefox 或任何其他应用程序(如果你知道的话,我从 Easy Lingo 词典中引用了这个想法),然后应用程序将在数据库中执行查询并以工具提示或其他方式将结果返回给用户就像在鼠标的位置一样。 那么,我怎样才能得到鼠标指针下的单词,是 API 还是什么?
请你帮帮我好吗?

【问题讨论】:

标签: c# vb.net


【解决方案1】:

几乎每个视觉控件(如文本框或标签)都有 MouseHover 事件。

private void label1_MouseHover(object sender, EventArgs e)
{
  // get text by mouse-over
  string textOfTheLabel = ((Label) sender).Text;
  string translatedText = GetTranslationFromDB(textOfTheLabel);

  // tooltip
  System.Windows.Forms.ToolTip toolTip1 = new System.Windows.Forms.ToolTip();
  toolTip1.SetToolTip((Label) sender, translatedText);
}

【讨论】:

  • 这适用于您自己的 .NET 应用程序中带有单个单词的标签 - 但 Ahmed 要求它“在任何应用程序(如 MS Word、IE、Firefox 或任何其他应用程序)中工作” .想象一下,您将鼠标悬停在由我在 SO 上输入的树突状排水(Dendritic Drainage)字样上,然后弹出一个带有定义的工具提示。
  • 谢谢迈克尔先生,但这只能通过我的应用程序工作,我想将其公开(从任何应用程序)。
猜你喜欢
  • 1970-01-01
  • 2011-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多