求拖拽打开文件的C#代码 一个Win Form上有一个PictureBox,从资源管理器里把一个图片文件拖拽到这个Form上,PictureBox就显示这个图片。请问用C#如何实现,最好有详细代码,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.mscourse.com/blog/u/Kayetyusha/archives/2007/160.html 给PictureBox添加如下的两个事件代码试试看,应该没有问题:protected override void OnLoad(EventArgs e){ base.OnLoad(e); this.pictureBox1.AllowDrop = true;//这句话直接写.}private void pictureBox1_DragOver(object sender, DragEventArgs e){ if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) { e.Effect = DragDropEffects.Link; }}private void pictureBox1_DragDrop(object sender, DragEventArgs e){ string[] items = (object)e.Data.GetData("FileNameW") as string[]; if (items.Length == 1) { Image img = Image.FromFile(items[0]); this.pictureBox1.Image = img; }} 可以的呀,我直接用hbxtlhx(平民百姓) 的代码就成功了 WPF 手写输入 Message="尝试读取或写入受保护的内存。这通常指示其他内存已损坏。" 请问换行,是咋整的? 有关C#中作成excel文档 c# 正则表达式 替换 DataGridView 与数据库同步更新问题!(100分) 读取Xml得问题,高人请进? 100分求助 HttpWebResponse 返回的Headers内location带有中文的编码问题 发邮件 DevExpress 17.x版本下的汉化发现网上有2种,zh-CHS和zh-Hans Duwamish 7.0是否能安装在sql server 2005上 为什么datagridview控件的列头的文字没法中间对齐?
{
base.OnLoad(e);
this.pictureBox1.AllowDrop = true;//这句话直接写.
}
private void pictureBox1_DragOver(object sender, DragEventArgs e)
{
if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link)
{
e.Effect = DragDropEffects.Link;
}
}private void pictureBox1_DragDrop(object sender, DragEventArgs e)
{
string[] items = (object)e.Data.GetData("FileNameW") as string[];
if (items.Length == 1)
{
Image img = Image.FromFile(items[0]);
this.pictureBox1.Image = img;
}
}