首页 > 其他 > 详细

将文件拖到控件中获得文件路径

时间:2015-03-11 16:21:35      阅读:266      评论:0      收藏:0      [点我收藏+]

    文件拖过来的代码为:

(System.Array)e.Data.GetData(DataFormats.FileDrop)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Security.Cryptography;  

namespace WindowsFormsApplication1
{
    public partial class MD5 : Form
    {
        public MD5()
        {
            InitializeComponent();
       
        }
         private void MD5_Load(object sender, EventArgs e)
        {
            SetCtrlDrag.SetCtrlDragEvent(this.textBox1);
        }
     }
    public class SetCtrlDrag
    {

        public static void SetCtrlDragEvent(Control ctrl)
        {

            if (ctrl is TextBox)
            {

                TextBox tb = ctrl as TextBox;

                tb.AllowDrop = true;

                tb.DragEnter += (sender, e) =>
                {

                    e.Effect = DragDropEffects.Link;//拖动时的图标

                };

                tb.DragDrop += (sender, e) =>
                {

                    ((TextBox)sender).Text = "文件路径:"+((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();

                };

            }

        }

    }
 }

 技术分享

将文件拖到控件中获得文件路径

原文:http://www.cnblogs.com/qh123/p/4329796.html

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