+ -
当前位置:首页 → 问答吧 → vs2008和c#中怎样利用Bitmap (String, Boolean)函数给winform加载图片图片

vs2008和c#中怎样利用Bitmap (String, Boolean)函数给winform加载图片图片

时间:2011-12-15

来源:互联网

我用vs2008和c#来开发一个小系统。现在利用Bitmap 构造函数 (String, Boolean)来给winform加载背景,想通过小系统自己设计来换背景(不想利用from属性来添加背景图片), 我就利用这句话来编写的程序
   
  this.BackgroundImage = new Bitmap(this.MyBgPhotoShow, true);  

一编译就出错。

提示如下:未处理 System.ArgumentException
  Message="参数无效。"
  Source="System.Drawing"
  StackTrace:
  在 System.Drawing.Bitmap..ctor(String filename, Boolean useIcm)
  在 高新置业.MainForm.MainForm_Load_1(Object sender, EventArgs e) 位置 C:\Users\LIHONGBO\Desktop\毕业设计--项目\高新置业房产中介管理系统\高新置业房产中介管理系统\高新置业\MainForm.cs:行号 49
  在 System.Windows.Forms.Form.OnLoad(EventArgs e)
  在 System.Windows.Forms.Form.OnCreateControl()
  在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
  在 System.Windows.Forms.Control.CreateControl()
  在 System.Windows.Forms.Control.WmShowWindow(Message& m)
  在 System.Windows.Forms.Control.WndProc(Message& m)
  在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
  在 System.Windows.Forms.ContainerControl.WndProc(Message& m)
  在 System.Windows.Forms.Form.WmShowWindow(Message& m)
  在 System.Windows.Forms.Form.WndProc(Message& m)
  在 高新置业.MainForm.WndProc(Message& SystemMessage) 位置 C:\Users\LIHONGBO\Desktop\毕业设计--项目\高新置业房产中介管理系统\高新置业房产中介管理系统\高新置业\MainForm.cs:行号 75
  在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
  在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
  在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  在 System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
  在 System.Windows.Forms.Control.SetVisibleCore(Boolean value)
  在 System.Windows.Forms.Form.SetVisibleCore(Boolean value)
  在 System.Windows.Forms.Control.set_Visible(Boolean value)
  在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
  在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
  在 System.Windows.Forms.Application.Run(Form mainForm)
  在 高新置业.Program.Main() 位置 C:\Users\LIHONGBO\Desktop\毕业设计--项目\高新置业房产中介管理系统\高新置业房产中介管理系统\高新置业\Program.cs:行号 18
  在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
  在 System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
  在 System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
  在 System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
  在 System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
  在 System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
  在 System.Activator.CreateInstance(ActivationContext activationContext)
  在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
  在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
  在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
  在 System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

作者: guokao666   发布时间: 2011-12-15

C# code
Bitmap pic = new Bitmap(@path);//path为图路径
            this.BackgroundImage = pic;  

作者: DENQH   发布时间: 2011-12-15

this.BackgroundImage = Bitmap.FromFile("图片路径");

作者: mayswind   发布时间: 2011-12-15