C# Mono Linux - Grab contents of global clipboard

半腔热情 提交于 2020-01-14 03:20:12

问题


I am trying to simply "grab" text from the clipboard and put into a variable. I'm having a lot of trouble doing this. I've tried to use

Gtk.Clipboard.Get(Gdk.Atom.Intern("PRIMARY", true))

The code that I have so far, just returns "Gtk.Clipboard" to TextBox entry1.

Gtk.Clipboard clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("PRIMARY", true));
string textClip = clipboard.ToString ();

entry1.Text = textClip;

So I am unable to do anything productive with this.


回答1:


Try this piece of code to get text from system clipboard;

Gtk.Clipboard clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
var text = clipboard.WaitForText();

For more information mono documentation



来源:https://stackoverflow.com/questions/27740792/c-sharp-mono-linux-grab-contents-of-global-clipboard

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