首页 > Windows开发 > 详细

C# 文件拖放

时间:2017-09-11 17:00:17      阅读:228      评论:0      收藏:0      [点我收藏+]

 

将控件的属性AllowDrop设置为true,然后添加DragDrop、DragEnter时间处理函数

private void FormMain_DragEnter(object sender, DragEventArgs e)
        {
            if(e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                txtSourceBin.Text = "";
                txtGenerateBin.Text = "";
                e.Effect = DragDropEffects.Link;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }

        }

        private void FormMain_DragDrop(object sender, DragEventArgs e)
        {
            string filePath= ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();        
            if (filePath.Substring(filePath.LastIndexOf(".")).ToLower() == ".bin")
            {
                txtSourceBin.Text = filePath;
                SetDefaultFileName(txtSourceBin.Text);
            }
        }

 

C# 文件拖放

原文:http://www.cnblogs.com/ike_li/p/7505532.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!