本文介绍了.Images.SetKeyName设计器生成的代码异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我最近将一个解决方案从vs 2003转换为2005.在主窗体上我使用了几个图像列表。 在每个图像列表上,我使用设计器生成的代码获得异常。 示例: Me .IL_Treeview.ImageStream = CType (resources.GetObject( " IL_Treeview.ImageStream" ),System.Windows.Forms。 ImageListStreamer) Me .IL_Treeview.TransparentColor = System.Drawing.Color.Transparent Me .IL_Treeview.Images.SetKeyName(0, " ; page.png" ) Me .IL_Treeview.Images .SetKeyName(1, " bricks.png") Me .IL_Treeview.Images.SetKeyName(2, " brick.png" ) Me .IL_Treeview .Images.SetKeyName(3, " cog.png" ) Me .IL_Treeview.Images.SetKeyName(4, " arrow_back.png" ; ) Me .IL_Treeview.Images.SetKeyName(5 , " info.png" ) 在此图像列表中,行上引发异常: Me .IL_Treeview.Images.SetKeyName(4, " arrow_back.png" ) System.IndexOutOfRangeException未处理 Message =" Index超出了数组的范围。" Source =&q uot; System.Windows.Forms" StackTrace: System.Windows.Forms.ImageList.ImageCollection.SetKeyName(Int32 index,String name) CZ中的JZL_JTool.FRM_Hoofdscherm.InitializeComponent() \\Development\JZL_JTool\FRM_Hoofdscherm.vb:第473行 - 在JZL_JTool.FRM_Hoofdscherm..ctor()中的C:\Development\JZL_JTool \FRM_Hoofdscherm.vb:第14行在JZL_JTool.startup。在C:\Development\JZL_JTool \startup.vb中的main(String [] sArgs):在System.AppDomain的System.AppDomain.nExecuteAssembly(Assembly assembly,String [] args)中的第112行。在System.Threading的System.Threading.ThreadHelper.ThreadStart_Context(Object state)的Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()中的ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args) .ExecutionContext.Run(ExecutionContext executionContext,Cont System.Threading.ThreadHelper.ThreadStart() = 2>我该怎么做才能解决这个问题? 解决方案 Jonny, 我想到的唯一一件事将验证您作为资源加载的ImageStream确实有6个图像。 您可以在开始设置ImageKeys之前添加以下代码吗? MsgBox(我 .IL_Treeview.Images.Count.ToString ()) 如果数字确实为6,则ImageList或ImageListStreamer类中存在错误;否则你的资源会遗漏一些图片。 希望这有帮助, I recently converted a solution from vs 2003 to 2005. On the main form i use a couple of imagelists. On every imagelist i use i get an exception on the designer generated code.Example:Me.IL_Treeview.ImageStream = CType(resources.GetObject("IL_Treeview.ImageStream"), System.Windows.Forms.ImageListStreamer)Me.IL_Treeview.TransparentColor = System.Drawing.Color.TransparentMe.IL_Treeview.Images.SetKeyName(0, "page.png")Me.IL_Treeview.Images.SetKeyName(1, "bricks.png")Me.IL_Treeview.Images.SetKeyName(2, "brick.png")Me.IL_Treeview.Images.SetKeyName(3, "cog.png")Me.IL_Treeview.Images.SetKeyName(4, "arrow_back.png")Me.IL_Treeview.Images.SetKeyName(5, "info.png")in this imagelist the exception is raised on the row:Me.IL_Treeview.Images.SetKeyName(4, "arrow_back.png")System.IndexOutOfRangeException was unhandled  Message="Index was outside the bounds of the array."  Source="System.Windows.Forms"  StackTrace:       at System.Windows.Forms.ImageList.ImageCollection.SetKeyName(Int32 index, String name)       at JZL_JTool.FRM_Hoofdscherm.InitializeComponent() in C:\Development\JZL_JTool\FRM_Hoofdscherm.vb:line 473       at JZL_JTool.FRM_Hoofdscherm..ctor() in C:\Development\JZL_JTool\FRM_Hoofdscherm.vb:line 14       at JZL_JTool.startup.main(String[] sArgs) in C:\Development\JZL_JTool\startup.vb:line 112       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)       at System.Threading.ThreadHelper.ThreadStart()What can i do to resolve this issue? 解决方案 Hi Jonny,The only thing that comes to my mind would be to verify that the ImageStream that you are loading as a resource does indeed have 6 images in it.Can you add the following code before you start setting the ImageKeys?    MsgBox(Me.IL_Treeview.Images.Count.ToString())If the number is indeed 6, then there is a bug in the ImageList or ImageListStreamer class; otherwise your resource is missing some images.Hope this helps, 这篇关于.Images.SetKeyName设计器生成的代码异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-03 07:22