Skip to content

Commit

Permalink
* Support Drag txt File
Browse files Browse the repository at this point in the history
  • Loading branch information
luvletter2333 committed Jun 10, 2019
1 parent 2e3bdf6 commit c31b9fb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ private void btn_DeleteFile_Click(object sender, EventArgs e)

private void btn_import_Click(object sender, EventArgs e)
{
Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
var ofd = new OpenFileDialog();
// ofd.Reset();
ofd.Filter = "Txt File (*.txt)|*.txt|All Files|*.*";
Expand All @@ -225,6 +226,7 @@ private void btn_import_Click(object sender, EventArgs e)
}
}
}
ofd.Dispose();
}

private void lst_File_SelectedIndexChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -324,5 +326,33 @@ private void btn_Clear_Click(object sender = null, EventArgs e = null)
}
#endregion

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

private void Lst_File_DragDrop(object sender, DragEventArgs e)
{
string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);

foreach (string filePath in s)
{
Console.WriteLine(filePath);
if (File.Exists(filePath))
{
if (Path.GetExtension(filePath) != ".txt")
continue;
string fileName = Path.GetFileName(filePath);
if (!lst_File.Items.Contains(fileName))
{
lst_File.Items.Add(fileName);
ST_Files.Add(fileName, filePath);
}
}
}
}
}
}

0 comments on commit c31b9fb

Please sign in to comment.