User Tools

Site Tools

blog:2022-05-01_c_drag_and_drop_files_into_an_application



2022-05-01 C#: Drag and drop files into an application

  • The drag and drop files into an application for the C# application is offen used in many application area.

Setting

Codes

  •         private void Form1_DragEnter(object sender, DragEventArgs e)
            {
                // 當滑鼠拖曳進視窗,改變鼠標
                if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
            }
    
            private void Form1_DragDrop(object sender, DragEventArgs e)
            {
                // 當拖曳進來檔案放開滑鼠按鍵時,呼叫本函式
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
                foreach (string file in files) Console.WriteLine(file);
            }

TAGS

  • 160 person(s) visited this page until now.

Permalink blog/2022-05-01_c_drag_and_drop_files_into_an_application.txt · Last modified: 2022/05/01 10:37 by jethro

oeffentlich