如何将选定的文本复制到剪贴板 [英] How to copy selected text to the clipboard

查看:76
本文介绍了如何将选定的文本复制到剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.我有个问题.我需要复制在任何应用程序(无论是Web浏览器还是记事本)中选择的文本,并将其复制到剪贴板.

Hello. I have a problem. I need to copy the text selected in any application (whether web-browser or notepad) and copy it to the clipboard. Who than can help please!

推荐答案

在没有一些p/invoke的情况下,这在C#中是无法完成的.您需要使用Win32 API调用来查找焦点窗口并向其询问文本.
That can''t be done in C# without some p/invoke. You need to use Win32 API calls to find the focused window and ask it for it''s text.


此问题仅对以下情况有意义:将任何应用程序中的操作复制到C#应用程序中,然后使用剪贴板中的内容.

我能想到的解决方案的唯一方法是实现GlobalSystemHook:请参见George Mamaladze [
This question makes sense to me only if: you are going to return focus after a copy operation in any application to your C# application, and then use the clipboard contents.

The only way I can imagine a solution is by implementing a GlobalSystemHook: see "Processing Global Mouse and Keyboard Hooks in C#" by George Mamaladze[^] which will notify/invoke your C# application in the case of a control-c event.

When notified of that event, you will, then, have to examine the clipboard contents to filter for text-only content ... I assume.


作为使用Windows notepad.exe的替代方法您是否考虑过将记事本克隆嵌入到您的应用程序中.为此,我在C#中创建了记事本的精确副本.您可以在此处找到源代码:
http://www.simplygoodcode.com/2012/04/notepad-clone- in-net-winforms.html [ ^ ]
As an alternative to using windows notepad.exe have you considered embedding a notepad clone into your application. I created an exact clone of notepad in C# for exactly this purpose. You can find the source code here:
http://www.simplygoodcode.com/2012/04/notepad-clone-in-net-winforms.html[^]


这篇关于如何将选定的文本复制到剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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