我说的是由用户自己上传,写到这里没有报错,但是运行时候有问题。
PicName = openFileDialog2.FileName;
openFileDialog2.Filter = "*.jpg(jpg)|*.jpg|*.png(png)|*.png";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.BackgroundImage = Image.FromFile(Path.GetDirectoryName(openFileDialog2.FileName));
}
PicName = openFileDialog2.FileName;
openFileDialog2.Filter = "*.jpg(jpg)|*.jpg|*.png(png)|*.png";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.BackgroundImage = Image.FromFile(Path.GetDirectoryName(openFileDialog2.FileName));
}
解决方案 »
- C#里面的我不懂的问题,真的是汗流啊
- C#连接mysql抛出异常出错!
- 请教datagridview中数据更新 winfrom-webserver-DB怎么操作?
- C# Label,TextBox復合控件
- C# a继承b c继承b a与c怎么转换
- 自定义控件的属性中,EditorBrowsable有什么用啊
- C# 求控件问题
- 我在asp.net中访问access,为什么只能查询,不能删除修改和增加记录?
- 关于C#组件的部署问题.
- java 与 c# 那个有钱前途???????????????????????????
- 将图片保存到本地磁盘上
- window.showModelDialog 打开新窗口后 在新窗口中无法实现下载功能
openFileDialog2.Filter = "*.jpg(jpg)|*.jpg|*.png(png)|*.png";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.BackgroundImage = Image.FromFile(Path.GetDirectoryName(openFileDialog2.FileName));
}楼主弄那么多openFileDialog干吗, if (openFileDialog1.ShowDialog() == DialogResult.OK)这里的openFileDialog1改为openFileDialog2吧
这样 你可能是copy的时候没有改完PicName = openFileDialog2.FileName;
openFileDialog2.Filter = "*.jpg(jpg)|*.jpg|*.png(png)|*.png";
if (openFileDialog2.ShowDialog() == DialogResult.OK)
{
this.BackgroundImage = Image.FromFile(Path.GetDirectoryName(openFileDialog2.FileName));
}
************* 异常文本 **************
System.IO.FileNotFoundException: C:\Users\Administrator\Downloads
在 System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement)
在 System.Drawing.Image.FromFile(String filename)
在 铜镜映无邪.Form1.修改背景色ToolStripMenuItem_Click(Object sender, EventArgs e) 位置 E:\360data\重要数据\我的文档\Visual Studio 2010\Projects\铜镜映无邪\铜镜映无邪\Form1.cs:行号 162
在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
在 System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
在 System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
在 System.Windows.Forms.ToolStrip.WndProc(Message& m)
在 System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** 已加载的程序集 **************
mscorlib
程序集版本: 4.0.0.0
Win32 版本: 4.0.30319.235 (RTMGDR.030319-2300)
基本代码: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
铜镜映无邪
程序集版本: 1.0.0.0
Win32 版本: 1.0.0.0
基本代码: file:///E:/360data/重要数据/我的文档/Visual%20Studio%202010/Projects/铜镜映无邪/铜镜映无邪/bin/Debug/铜镜映无邪.exe
----------------------------------------
System.Windows.Forms
程序集版本: 4.0.0.0
Win32 版本: 4.0.30319.235 built by: RTMGDR
基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
程序集版本: 4.0.0.0
Win32 版本: 4.0.30319.1 built by: RTMRel
基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
程序集版本: 4.0.0.0
Win32 版本: 4.0.30319.236 built by: RTMGDR
基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Configuration
程序集版本: 4.0.0.0
Win32 版本: 4.0.30319.1 (RTMRel.030319-0100)
基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
程序集版本: 4.0.0.0
Win32 版本: 4.0.30319.1 built by: RTMRel
基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Windows.Forms.resources
程序集版本: 4.0.0.0
Win32 版本: 4.0.30319.235 built by: RTMGDR
基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_zh-Hans_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------
mscorlib.resources
程序集版本: 4.0.0.0
Win32 版本: 4.0.30319.235 (RTMGDR.030319-2300)
基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_zh-Hans_b77a5c561934e089/mscorlib.resources.dll
----------------------------------------************** JIT 调试 **************
要启用实时(JIT)调试,
该应用程序或计算机的 .config 文件(machine.config)的 system.windows.forms 节中必须设置
jitDebugging 值。
编译应用程序时还必须启用
调试。例如: <configuration>
<system.windows.forms jitDebugging="true" />
</configuration>启用 JIT 调试后,任何未经处理的异常
都将被发送到在此计算机上注册的 JIT 调试器,
而不是由此对话框处理。
{
this.BackgroundImage = Image.FromFile(openFileDialog2.FileName);
}
自己看看FromFile里面参数的含义。你用个Path.GetDirectoryName获取的是什么东西。
openFileDialog2.FileName本来就是地址了,也包括文件名在内的地址,这样就可以了
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.BackgroundImage = Image.FromFile(openFileDialog2.FileName);
}