粘贴板粘贴目录地址或字符串内容

2017-01-25 17:53:55  访问(1453) 赞(0) 踩(0)


        /// <summary>
        /// 粘贴操作
        /// </summary>
        /// <returns></returns>
        public string ClipbordPasteTextGet()
        {
            IDataObject data = Clipboard.GetDataObject();

            if (data.GetDataPresent(DataFormats.Text))
            {
                return data.GetData(DataFormats.Text).ToString();
            }
            else
            {
                return "";
            }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton_粘贴目录_Click(object sender, EventArgs e)
        {
            try
            {
                StringCollection sc = Clipboard.GetFileDropList();

                

                if (sc != null && sc.Count >0)
                {
                    toolStripComboBox_Dir.Text = sc[0]; 
                    return;
                }

                string str = ClipbordPasteTextGet();

                if (str != null && str.Length > 0)
                {
                    toolStripComboBox_Dir.Text = str;
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }


标签:粘贴板粘贴目录地址或字符串内容 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)