六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 34|回复: 0

C#把外部文件拖入PictureBox中

[复制链接]

升级  85%

884

主题

884

主题

884

主题

探花

Rank: 6Rank: 6

积分
2700
 楼主| 发表于 2013-1-26 14:19:23 | 显示全部楼层 |阅读模式
不知道为何.net编辑器无法自动识别PictureBox的AllowDrop,属性列表中也没有,实际上他确实可以用。
private void Form1_Load(object sender, EventArgs e)        {            //这句代码不会抱错,但是需要手动输入,.net编辑器无法自动识别AllowDrop            this.pictureBox1.AllowDrop = true;        }                 private void pictureBox1_DragDrop(object sender, DragEventArgs e)        {            string fileName = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();            this.pictureBox1.Image = Image.FromFile(fileName);        }        private void pictureBox1_DragEnter(object sender, DragEventArgs e)        {            if (e.Data.GetDataPresent(DataFormats.FileDrop))                e.Effect = DragDropEffects.Link;            else e.Effect = DragDropEffects.None;         }
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表