-->

آخر الأخبار

جاري التحميل ...

Copy or Move multiple files C# windows Forms- drag and drop نسخ ونقل الملفات بالسحب والالقاء

-1-
-2-

 using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;


namespace wfa0021

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }


        private void textBox1_DragDrop(object sender, DragEventArgs e)

        {

            // This just allows you to drop a file into the textbox and display it's path.

            string[] files1 = (string[])e.Data.GetData(DataFormats.FileDrop, false);

            foreach (string file1 in files1)

                textBox1.Text = file1;


        }


        private void textBox1_DragEnter(object sender, DragEventArgs e)

        {

            //Drag and drop effect in windows

            if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)

            {

                e.Effect = DragDropEffects.All;

            }


        }


        private void textBox2_DragDrop(object sender, DragEventArgs e)

        {

            string[] files2 = (string[])e.Data.GetData(DataFormats.FileDrop, false);

            foreach (string file2 in files2)

                textBox2.Text = file2;

        }


        private void textBox2_DragEnter(object sender, DragEventArgs e)

        {

            //Drag and drop effect in windows

            if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)

            {

                e.Effect = DragDropEffects.All;

            }



        }


        private void button1_Click(object sender, EventArgs e)

        {


            try

            {

                string dircopyFrom = textBox1.Text;


                string[] fileEntries1 = Directory.GetFiles(dircopyFrom);

                string dircopyTo = textBox2.Text;


                foreach (string file1 in fileEntries1)

                {

                    string filename1 = Path.GetFileName(file1);


                    File.Copy(file1, dircopyTo + "\\" + filename1, true);

                }

            }

            //catches any errors, stops crashes.

            catch (Exception ex)

            {

                MessageBox.Show(ex.ToString());

            }



        }


        private void button2_Click(object sender, EventArgs e)

        {

            try

            {

                string dircopyFrom = textBox1.Text;


                string[] fileEntries1 = Directory.GetFiles(dircopyFrom);

                string dircopyTo = textBox2.Text;


                foreach (string file1 in fileEntries1)

                {

                    string filename1 = Path.GetFileName(file1);


                    File.Copy(file1, dircopyTo + "\\" + filename1, true);

                    File.Delete(file1);

                }

            }

            //catches any errors, stops crashes.

            catch (Exception ex)

            {

                MessageBox.Show(ex.ToString());

            }

            //All code going in description....


            //Thanks

        }


        private void textBox1_TextChanged(object sender, EventArgs e)

        {


        }

    }

}


-3-
-4-

التعليقات



إذا أعجبك محتوى مدونتنا نتمنى البقاء على تواصل دائم ، فقط قم بإدخال بريدك الإلكتروني للإشتراك في بريد المدونة السريع ليصلك جديد المدونة أولاً بأول ، كما يمكنك إرسال رساله بالضغط على الزر المجاور ...

إتصل بنا

جميع الحقوق محفوظة

مدونة كورس 7

2021