简体   繁体   中英

Ctrl+C Store Clipboard to Variable C#

I could use Sendkeys.Send("^c") to copy to clipboard.

How do I store the contents of the clipboard to a variable?

Depending on format:

if (Clipboard.ContainsAudio())
{
    var audio = Clipboard.GetAudioStream();
    [..]
}

if (Clipboard.ContainsFileDropList())
{
    var list = Clipboard.GetFileDropList();
    [..]
}

if (Clipboard.ContainsImage())
{
    var image = Clipboard.GetImage();
    [..]
}


if (Clipboard.ContainsText(TextDataFormat.Html))
{
    var text = Clipboard.GetText(TextDataFormat.Html);
    [..]
}
 string setText = "somedata"; 
 Clipboard.SetText(setText);//copy text from variable to Clipboard
 string getText=Clipboard.GetText();// copy text from Clipboard to variable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM