1. 程式人生 > >C# 文件拖放

C# 文件拖放

event bstr tin ner substring 設置 logs else present

將控件的屬性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# 文件拖放