• 大小: 0.05M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-04-28
  • 语言: C#
  • 标签: 名称  获取  拖拽  文件  C#  

资源简介


资源截图

代码片段和文件信息

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;

namespace 拖拽获取文件名
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
                this.AllowDrop = true;
        }

        private void Form1_DragDrop(object sender DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
                e.Effect = DragDropEffects.All;
            else
                e.Effect = DragDropEffects.None;
        }

        private void Form1_DragEnter(object sender DragEventArgs e)
        {
            if (radioButton1.Checked)
            {
                //单文件
                listBox1.Items.Clear();
                string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
                textBox1.Text = path;
            }
            else if (radioButton2.Checked)
            {
                //多文件
                textBox1.Text=““;
                String[] fileNames = (String[])e.Data.GetData(DataFormats.FileDrop);
                int j = listBox1.Items.Count + 1;
                for (int i = 0; i < fileNames.Length; i++)
                {
                    listBox1.Items.Add(String.Format(“{0:D3} “ i + j) + fileNames[i]);
                }
            }
           
        }

        private void button1_Click(object sender EventArgs e)
        {
            MessageBox.Show(“VBA/VSTO/.NET交流分享群【675166879】“ “Savetime友情提示“ MessageBoxButtons.OK);
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-10-25 04:55  .vs\
     目录           0  2020-10-25 04:55  .vs\拖拽获取文件名\
     目录           0  2020-10-25 04:55  .vs\拖拽获取文件名\v16\
     文件       16896  2020-10-25 05:25  .vs\拖拽获取文件名\v16\.suo
     目录           0  2020-10-25 04:55  bin\
     目录           0  2020-10-25 05:02  bin\Debug\
     文件       49664  2020-10-25 05:24  bin\Debug\拖拽获取文件名.exe
     文件       34304  2020-10-25 05:24  bin\Debug\拖拽获取文件名.pdb
     文件        1834  2020-10-25 05:24  Form1.cs
     文件        7117  2020-10-25 05:24  Form1.Designer.cs
     文件       63235  2020-10-25 05:24  Form1.resx
     目录           0  2020-10-25 04:55  obj\
     目录           0  2020-10-25 05:24  obj\Debug\
     文件         208  2020-10-25 04:55  obj\Debug\.NETframeworkVersion=v4.0.AssemblyAttributes.cs
     文件         819  2020-10-25 04:55  obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6905  2020-10-25 04:57  obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2020-10-25 04:55  obj\Debug\TempPE\
     文件          42  2020-10-25 05:02  obj\Debug\拖拽获取文件名.csproj.CoreCompileInputs.cache
     文件         973  2020-10-25 05:02  obj\Debug\拖拽获取文件名.csproj.FileListAbsolute.txt
     文件        1012  2020-10-25 05:24  obj\Debug\拖拽获取文件名.csproj.GenerateResource.cache
     文件         424  2020-10-25 05:11  obj\Debug\拖拽获取文件名.csprojAssemblyReference.cache
     文件       49664  2020-10-25 05:24  obj\Debug\拖拽获取文件名.exe
     文件       38644  2020-10-25 05:24  obj\Debug\拖拽获取文件名.Form1.resources
     文件       34304  2020-10-25 05:24  obj\Debug\拖拽获取文件名.pdb
     文件         180  2020-10-25 05:02  obj\Debug\拖拽获取文件名.Properties.Resources.resources
     文件         502  2020-10-25 04:55  Program.cs
     目录           0  2020-10-25 04:55  Properties\
     文件        1334  2020-10-25 04:55  Properties\AssemblyInfo.cs
     文件        2855  2020-10-25 04:55  Properties\Resources.Designer.cs
     文件        5612  2020-10-25 04:55  Properties\Resources.resx
     文件        1108  2020-10-25 04:55  Properties\Settings.Designer.cs
............此处省略3个文件信息

评论

共有 条评论