zoukankan      html  css  js  c++  java
  • 怎样在IDE的MTAThread中使用剪贴板功能

    #region 剪切/复制,粘贴
            
    /// <summary>
            
    /// 写文件到剪贴板
            
    /// </summary>
            
    /// <param name="cut">如果是剪切则为True,如果为复制False</param>        
            void CopyToClipboard(bool cut)
            {
                List
    <ZSFile> files = this.blvDirAndFileList.SelectedFiles;           
                
    if (files != null)
                {
                    clipboardData 
    = new DataObject(typeof(List<ZSFile>).ToString(), files);

                    MemoryStream memo 
    = new MemoryStream(4);
                    
    byte[] bytes = new byte[] { (byte)(cut ? 2 : 5), 000 };
                    memo.Write(bytes, 
    0, bytes.Length);

                    clipboardData.SetData(
    "Preferred DropEffect", memo);

                    Thread staThread 
    = new Thread(new ThreadStart(this.SetClipboard));
                    staThread.SetApartmentState(ApartmentState.STA);
                    staThread.Start();
                    staThread.Join();
                    staThread.Abort();
                }
            }
            
    private IDataObject clipboardData;
            
    public void SetClipboard()
            {
                
    if (clipboardData != null)
                {
                    Clipboard.SetDataObject(clipboardData,
    true);
                }
                
            }
            
    public void GetClipboardContent()
            {            
                clipboardData 
    = Clipboard.GetDataObject();
            }
            
    /// <summary>
            
    /// 粘贴
            
    /// </summary>
            private void tsmiPaste_Click(object sender, EventArgs e)
            {
                Thread sta1Thread 
    = new Thread(new ThreadStart(this.GetClipboardContent));
                sta1Thread.SetApartmentState(ApartmentState.STA);
                sta1Thread.Start();
                sta1Thread.Join();
                staThread.Abort();

                
    //IDataObject clipboardData = Clipboard.GetDataObject();
                if (!clipboardData.GetDataPresent(typeof(List<ZSFile>).ToString()))
                    
    return;

                List
    <ZSFile>  files = (List<ZSFile>)clipboardData.GetData(typeof(List<ZSFile>).ToString());
                MemoryStream stream 
    = (MemoryStream)clipboardData.GetData("Preferred DropEffect"true);
                
    //int flag = stream.ReadByte();
                
    //if (flag != 2 && flag != 5)
                
    //    return;
                
    //bool cut = (flag == 2);
                
    //foreach (string file in files)
                
    //{
                
    //    string dest = homeFolder + "\\" + Path.GetFileName(file);
                
    //    try
                
    //    {
                
    //        if (cut)
                
    //            File.Move(file, dest);
                
    //        else
                
    //            File.Copy(file, dest, false);
                
    //    }
                
    //    catch (IOException ex)
                
    //    {
                
    //        MessageBox.Show(this, "Failed to perform the specified operation:\n\n" + ex.Message, "File operation failed", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                
    //    }
                
    //}

                
    //RefreshView();
            }

            
    /// <summary>
            
    /// 复制
            
    /// </summary>
            private void tsmiCopy_Click(object sender, EventArgs e)
            {
                
                CopyToClipboard(
    false);
            }

            
    /// <summary>
            
    /// 剪切
            
    /// </summary>
            private void tsmiCut_Click(object sender, EventArgs e)
            {
                CopyToClipboard(
    true);
            }
    #endregion
  • 相关阅读:
    深度学习遥感影像(哨兵2A/B)超分辨率
    基于Google Earth Engine的全国地表温度反演
    蚂蚁森林的树木长得如何了?遥感云计算告诉你!!
    基于单分类器的高分辨率遥感影像道路提取
    基于google earth engine 云计算平台的全国水体变化研究
    超大影像栅格转矢量快速实现
    大规模深度学习多通道遥感图像样本增强
    大规模遥感影像匀光匀色的一些思考
    基于深度学习的珠海一号高光谱影像云检测
    全自动多源遥感影像大气校正方法
  • 原文地址:https://www.cnblogs.com/jes_shaw/p/1506447.html
Copyright © 2011-2022 走看看