欢迎来到传世资源网!
加载中...
正在加载,请耐心等待...
本站为收藏、学习站,如有侵权,请联系管理员删除!

C# 拖拽照片到winform窗体并自动显示照片

介绍 评论 失效链接反馈

直接拖拉照片显示
C# 拖拽照片到winform窗体并自动显示照片 C#语言基础-第1张
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace photos{ public partial class Form1 : Form { string fileName = string.Empty; public Form1() { InitializeComponent(); this.Load = new EventHandler(Form1_Load); this.DragEnter = new DragEventHandler(Form1_DragEnter); this.DragDrop = new DragEventHandler(Form1_DragDrop); } void Form1_Load(object sender, EventArgs e) { this.AllowDrop = true; } void Form1_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.All; else e.Effect = DragDropEffects.None; } void Form1_DragDrop(object sender, DragEventArgs e) { //获取第一个文件名 fileName = (e.Data.GetData(DataFormats.FileDrop, false) as String[])[0]; try { this.pictureBox1.ImageLocation = fileName; } catch (Exception) { MessageBox.Show("文件格式不对"); } } }}

下载声明:

本站资源均有第三方用户自行上传分享推荐,非本站自制,仅供玩家做交流学习之用!切勿用于商业用途!游戏作品版权归原作者享有,如有版权问题,请附带版权证明至邮件,本平台将应您的要求删除。
相关推荐:

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复