Set the Form property allowDrop = True;
In the Form event C # tutorial
private void Form1_DragDrop(object sender, DragEventArgs e)
{
string localFilePath = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();//Full path of the file
GetExtension(localFilePath);//file suffix name
if (extension == ".cbd")
{
//todo you code
}
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
string localFilePath = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
string extension = System.IO.Path.GetExtension(localFilePath);
if (string.Compare(extension, ".cds", true) == 0)
{
e.Effect = DragDropEffects.Move;
}
else
{
e.Effect = DragDropEffects.None;
}
}
Read More:
- How to Solve IntelliJ IDEA Error: Cannot determine path to ‘tools.jar‘ library for 17 (C:\Program Files\Java\jd…
- How to Use filechannel to copy files
- JAVA: How to Use Multipartfile to upload Files
- How to Solve RAR Files Extract Error with sevenzipjbinding (Multithread Processing)
- Java: How to Find the Minimum Value from a Random Array by Bubble Sort Method
- How to Solve Springboot Upload Files Error: The field XXX exceeds its maximum permitted size of 1048576 bytes
- [Solved] Kafka in Windows error:java. nio. file. Filesystemexception: this file is in use by another program and cannot be accessed by the process
- How to Solve Errors encountered by maven
- Caused by: java.lang.IllegalStateException (How to Fix)
- How to Close the Current Form in JAVA Swing
- How to Solve c3p0 error (Cause & Solution)
- How to Solve Image Upload Error: Uncaught (in promise) DOMException: Failed to execute ‘put‘ on ‘IDBObjectStore‘
- How to Fix Error Caused by: java.util.MissingResourceException: Can‘t find bundle for base name xxx, locale zh_CN
- The principle and return value of get() function in C language
- How to Converte Java objects to jsonnode in Jackson (Four Methods)
- Mybatis single parameter pass in exception (How to Fix)
- How to Solve Error executing DDL in JPA
- SpringCloud Use openFeign Multipartfile to Upload Files Error: Current request is not a multipart request
- The @value annotation of springboot adds the default value to solve the startup error caused by the non-existent key
- How to compare the time in two TimeStamp format?