开发者

Programmatically add text to the clipboard in C#

开发者 https://www.devze.com 2023-02-01 18:36 出处:网络
Is there a way to programmatically add text to the clipboard in C# (3.5开发者_如何转开发) or javascript ? Does the client machine type make a difference?

Is there a way to programmatically add text to the clipboard in C# (3.5开发者_如何转开发) or javascript ? Does the client machine type make a difference?

Edit: Sorry, forgot to mention am using asp.net.


You can use Clipboard.SetText(string) and Clipboard.GetText() to interact with the clipboard.

See the MSDN article

As long as the client supports .NET, it shouldn't make a difference.


Oh, for the web...

Then use something like this jQuery plugin:
http://plugins.jquery.com/project/clipboard

It will allow you to copy and paste from the clipboard across browsers.


C#: In System.Windows.Forms you have a Clipboard class and a SetText method which probably is what you're looking for. Example:

Clipboard.SetText("My text");

Edit: Since you're looking for a way to set clipboard text on a client computer, here's an updated answer:

There is no browser agnostic way of setting clipboard text. It's possible in Internet Explorer using the following snippet:

window.clipboardData.setData('Text', 'Your text');

In Firefox and Webkit browsers, for security reasons, you need to go via flash to set clipboard text. Zeroclipboard is a nice library for this.


As far as I'm aware in the web world it would be a security issue to access the clipboard without some sort of client side control, i.e. ActiveX control or Flash. So it would prompt for the user to allow the access. Here is something to get you started.


In WinForms there is a static Clipboard class with a SetText method. So you can use

Clipboard.SetText("whatever");

There are some differences to the default text format based on which operating system you are running on: http://msdn.microsoft.com/en-us/library/ydby206k.aspx


You can use Flash.

0

精彩评论

暂无评论...
验证码 换一张
取 消