C# Winform 拖放图片文件到界面
作者:C/S框架网  发布日期:2018-07-23 19:13:15
  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;
   }
}

//来源:C/S框架网(www.csframework.com) QQ:23404761





贴图图片
上一篇 下一篇