不知道为何.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; }
本文介绍如何使用C#实现PictureBox控件的拖放功能,包括设置PictureBox允许接收拖放操作、处理文件拖放事件以及判断拖放数据的有效性。
2384

被折叠的 条评论
为什么被折叠?



