C# Winform 拖放图片文件到界面
C# Winform 拖放图片文件到界面C# Code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
string fileName = (e.Data.GetData(DataFormats.FileDrop, false) as String[])[0];
try
{
this.pictureBox1.ImageLocation = fileName;
}
catch (Exception)
{
MessageBox.Show("文件格式不对");
}
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Link;
else e.Effect = DragDropEffects.None;
}
}