简体   繁体   中英

How to send the clipboard my own content after clicking ctrl+C using C#?

How can I replace the copied text on the clipboard with my own?

When I'm clicking CTRL + C , my clipboard still consists of marked text, but not with "Hello there".

if(Keyboard.IsKeyDown(Key.C) && Keyboard.IsKeyDown(Key.LeftCtrl))
{
     Clipboard.SetDataObject("Hello there");
}

PS, MessageBox works normally.

Try key event handler like this.

private void KeyDownEvent(object sender, KeyEventArgs e)
{
    if (e.Key == Key.C && Keyboard.Modifiers == ModifierKeys.Control)
    {
        Clipboard.SetDataObject("Hello there");
    }
}

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