Getting selected item in active window

谁都会走 提交于 2019-12-13 12:18:52

问题


I am using C# to develop an application that works with the clipboard, an was wondering if its possible to get the contents of what the user has selected in the current window, no matter what window it is (e.g. could be FireFox, notepad, etc.).


回答1:


I'm not sure if you're going to be able to get a general solution for this problem. Take a look at this link;

http://www.eggheadcafe.com/software/aspnet/33899121/get-selected-text-of-active-window-.aspx

The author of this post reports that their solution works in Notepad, but not in Wordpad or Word. I don't know much about this area, but I would guess that this means there are various means through which text selection is implemented - even within Windows.

I think this also extends to Control-C, not just text selection. I believe that there are different ways of handling the copy command depending on the context in which it's used.

For example, if you press Control-C on a dialog box in Windows, it will copy the text without you have to select it manually.

Hopefully the link above is of some use to you. This seems like an interesting problem to overcome.

Edit:

Spoke too soon - just found this link;

http://social.msdn.microsoft.com/Forums/en/winformsapplications/thread/1dc356e6-9441-44de-9eda-247003fa6ef5

Looks like this is exactly what you're after - hope that works.




回答2:


If something was only selected, it won't appear in the Clipboard. But if user copied some object that he had previously selected, then, yes, it will be in the Clipboard.



来源:https://stackoverflow.com/questions/3412703/getting-selected-item-in-active-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!