Form1.cs
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Windows.Forms;
Namespace Filecatalog
{
public partial class Form1:form
{
Public Form1 ()
{
InitializeComponent ();
}
private void Form1_dragenter (object sender, DragEventArgs e)
{
E.effect = dragdropeffects.copy; Set the target placement type to copy in a drag-and-drop operation
String[] Str_drop = (string[]) e.Data.GetData (DataFormats.FileDrop, true);//Retrieves data that is associated with a data format
MessageBox.Show (Str_drop[0]);
}
}
}
Form1.Designer.cs
Namespace Filecatalog
{
Partial class Form1
{
<summary>
The required designer variables.
</summary>
Private System.ComponentModel.IContainer components = null;
<summary>
Clean up all the resources that are in use.
</summary>
<param name= "disposing" > True if the managed resource should be disposed, otherwise false. </param>
protected override void Dispose (bool disposing)
{
if (disposing && (components = null))
{
Components. Dispose ();
}
Base. Dispose (disposing);
}
#region the code generated by the Windows Forms Designer
<summary>
The designer supports the required method-do not
Use the Code Editor to modify the contents of this method.
</summary>
private void InitializeComponent ()
{
This. SuspendLayout ();
//
Form1
//
This. AllowDrop = true;
This. Autoscaledimensions = new System.Drawing.SizeF (6F, 12F);
This. AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
This. ClientSize = new System.Drawing.Size (292, 99);
This. Name = "Form1";
This. Text = "Get file directory";
This. DragEnter + = new System.Windows.Forms.DragEventHandler (this. Form1_dragenter);
This. ResumeLayout (FALSE);
}
#endregion
}
}
Program.cs
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Windows.Forms;
Namespace Filecatalog
{
Static Class Program
{
<summary>
The main entry point for the application.
</summary>
[STAThread]
static void Main ()
{
Application.enablevisualstyles ();
Application.setcompatibletextrenderingdefault (FALSE);
Application.Run (New Form1 ());
}
}
}
C # get file directory