您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Clipboard.GetText返回null(空字符串)

Clipboard.GetText返回null(空字符串)

您只能从STA线程访问剪贴板。Rick Brewster在Paint.NET中通过对常规Edit-> Paste命令进行一些重构来解决此问题。

码:

IDataObject idat = null;
Exception threadEx = null;
Thread staThread = new Thread(
    delegate ()
    {
        try
        {
            idat = Clipboard.GetDataObject();
        }

        catch (Exception ex) 
        {
            threadEx = ex;            
        }
    });
staThread.SetApartmentState(ApartmentState.STA);
staThread.Start();
staThread.Join();
// at this point either you have clipboard data or an exception

代码来自里克。http://forums.getpaint.net/index.php?/topic/13712-/page__view__findpost__p__226140

贾森·海涅取得加入一个好点()delegate,以固定的暧昧方法错误

其他 2022/1/1 18:19:22 有341人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶