【发布时间】:2012-12-24 18:08:06
【问题描述】:
我将图像添加到我的项目资源 (Windows Mobile 6.1)。我想使用这个图像来设置我在我的表单中拥有的一些 PictureBox 的 PictureBox.Image 属性。我尝试以下代码:
pictureBox1.Image = Properties.Resources.my_image;
pictureBox2.Image = Properties.Resources.my_image;
pictureBox3.Image = Properties.Resources.my_image;
...
pictureBoxN.Image = Properties.Resources.my_image;
问题是有时图像仅显示在某些 PictureBox 中(当我尝试设置图像时得到TargetInvocationException),而不是全部显示。为什么?我该如何解决这个问题?
编辑:
InnerException 的 StackTrace:
在 Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR ar) 中 System.Drawing.Bitmap._InitFromMemoryStream(MemoryStream mstream) 在 System.Drawing.Bitmap..ctor(Stream 流) 在 System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci,BindingFlags invokeAttr,Binder binder,Object参数, CultureInfo 文化,布尔 isBinderDefault,程序集调用者,布尔 verifyAccess、StackCrawlMark 和 stackMark)在 System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr、Binder binder、Object[] 参数、CultureInfo 文化) 在 System.Reflection.ConstructorInfo.Invoke(Object[] 参数) 中 System.Resources.ResourceReader.CreateResource(类型 objType,类型 [] ctorParamTypes, Object[] ctorParameters) 在 System.Resources.ResourceReader.LoadBitmap(Int32 typeIndex) 在 System.Resources.ResourceReader.LoadObjectV2(Int32 位置, 资源类型代码&类型代码)在 System.Resources.ResourceReader.LoadObject(Int32 位置, 资源类型代码&类型代码)在 System.Resources.RuntimeResourceSet.GetObject(字符串键,布尔值 在 System.Resources.ResourceManager.GetObject(String name, CultureInfo文化)在 Icons_Control.Properties.Resources.get_glass_empty() 在 Icons_Control.ListItem.set_CompletitionStatus(eCompletionStatus 值) 在 Icons_Control.ListItem..ctor() 中 Icons_Control.ListItem..ctor(eItemType type) 在 Icons_Control.MainForm.menuItem3_Click(Object sender, EventArgs e) in System.Windows.Forms.MenuItem.OnClick(EventArgs e) 在 System.Windows.Forms.Menu.ProcessMnuProc(控制 ctlThis,WM wm,Int32 wParam, Int32 lParam) in System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam) 在 System.Windows.Forms.Control._InternalWnProc(WM wm,Int32 wParam, Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain) 中的 Int32 lParam) 在 System.Windows.Forms.Application.Run(Form fm) 中 Icons_Control.Program.Main()
【问题讨论】:
-
TargetInvocationException通常有一个InnerException,可以提供更多细节。 -
我很确定我的答案,只是好奇你的图片有多大,你分配给多少图片框?
-
@Alan 大约 60 Kb,我不能显示超过 5 张图片。
标签: c# image windows-mobile compact-framework picturebox