Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何解决ImageList变量中的错误,例如:指定的参数超出有效值范围?_C#_.net_Winforms - Fatal编程技术网

C# 如何解决ImageList变量中的错误,例如:指定的参数超出有效值范围?

C# 如何解决ImageList变量中的错误,例如:指定的参数超出有效值范围?,c#,.net,winforms,C#,.net,Winforms,在表格1中,我在设计器中有这样一个部分,deisgner部分在表格1构造函数中: this.components = new System.ComponentModel.Container(); this.imageList1 = new System.Windows.Forms.ImageList(this.components); this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources

在表格1中,我在设计器中有这样一个部分,deisgner部分在表格1构造函数中:

this.components = new System.ComponentModel.Container();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
this.imageList1.Images.SetKeyName(0, "");
然后我创建了一个名为test.cs的新用户控件 在designer中,我添加了与表1相同的内容:

this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ExplorerTree));
System.Windows.Forms.ImageList imageList1 = new System.Windows.Forms.ImageList(this.components);
imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
imageList1.TransparentColor = System.Drawing.Color.Transparent;
imageList1.Images.SetKeyName(0, "");
在设计器代码中的用户控件中,我得到的错误在以下行:

imageList1.Images.SetKeyName(0, "");
我没有看到任何红线下的线,但在错误窗口中,我看到蓝色的符号! 错误是:消息1指定的参数超出了有效值的范围。 参数名称:“0”不是“索引”的有效值。C:\windowsexplorersource\TV LV Basic\ExplorerTree.Designer.cs 166 0

消息1指定的参数超出有效值的范围。 参数名称:“0”不是“索引”的有效值。C:\windowsexplorersource\TV LV Basic\ExplorerTree.Designer.cs 166 0


蓝色的错误是什么?我该如何修复它

你添加了图片吗???不能使用Stream::加载图像,但是,不能使用此类通过直接从一个ImageList分配ImageStream属性将图像加载到ImageList控件。相反,您应该直接将一个ImageList实例分配给另一个实例(例如,ImageList2=ImageList1)。谢谢