简体   繁体   中英

Why Clipboard.SetText doesn't work?

I have problem with copy some text to clipboard. My code looks like this:

    using System;
    using System.Windows;
    namespace namespace
    {
        public class Class1
        {
            public void Method1()
            {
                Clipboard.SetText("some text");
            }
        }
}

but on line Clipboard.SetText("..."); There is error message

CS0103 The name 'Clipboard' does not exist in the current context

What am I doing wrong?

Clipboard class is in the PresentationCore assembly, so you need to add a reference to PresentationCore.dll and use the appropriate namespace:

System.Windows.Clipboard.SetText("some text");

Or (as you are already doing):

using System.Windows;
.
.
.
Clipboard.SetText("some text");

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