简体   繁体   English

无法将类型'System.Drawing.Image'隐式转换为'System.Windows.Forms.PictureBox'

[英]Cannot Implicitly Convert type 'System.Drawing.Image' to 'System.Windows.Forms.PictureBox'

I have been trying to set up a random number generator that pics a number between 0 and 52 and then change a picture box to the the corresponding picture in an imagelist but i keep getting this error message 我一直在尝试设置一个随机数生成器,该生成器会显示一个介于0到52之间的数字,然后将一个图片框更改为imagelist中的相应图片,但是我一直收到此错误消息

Cannot Implicitly Convert type 'System.Drawing.Image' to 'System.Windows.Forms.PictureBox' 无法将类型'System.Drawing.Image'隐式转换为'System.Windows.Forms.PictureBox'

Random ran = new Random();
int RandomNumber = ran.Next(0, 52);
PicPlayerCard1 = imgCards.Images[RandomNumber];

PicPlayerCard1 in your code is of type PictureBox , not Image . 您代码中的PicPlayerCard1PictureBox类型,而不是Image类型。

There is a property named Image in the class PictureBox, so you should use it: 在PictureBox类中有一个名为Image的属性,因此您应该使用它:

Random ran = new Random();
int RandomNumber = ran.Next(0, 52);
PicPlayerCard1.Image = imgCards.Images[RandomNumber];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将类型system.drawing.image隐式转换为system.windows.controls.image - cannot implicitly convert type system.drawing.image to system.windows.controls.image 无法将类型“System.Drawing.Image”隐式转换为“System.Drawing.Bitmap” - Cannot implicitly convert type 'System.Drawing.Image' to 'System.Drawing.Bitmap'` 错误CS0029无法将类型&#39;System.Drawing.Image&#39;隐式转换为&#39;UnityEngine.Sprite&#39; - Error CS0029 Cannot implicitly convert type 'System.Drawing.Image' to 'UnityEngine.Sprite' 不能隐式转换类型 &#39;Emgu.CV.Image<Emgu.CV.Structure.Bgr, byte> &#39; 到 &#39;System.Drawing.Image&#39; - Cannot implicitly convert type 'Emgu.CV.Image<Emgu.CV.Structure.Bgr, byte>' to 'System.Drawing.Image' 无法将类型转换为“System.Drawing.Image”,存在显式转换 - Cannot convert type to 'System.Drawing.Image' an explicit conversion exists 无法将System.Drawing.Image转换为EmguCV - Cannot convert System.Drawing.Image to EmguCV 无法将类型“System.Drawing.Image”转换为“System.Drawing.Icon” - Cannot convert type 'System.Drawing.Image' to 'System.Drawing.Icon' 将System.Drawing.Image转换为System.Windows.Controls.Image? - Convert System.Drawing.Image to System.Windows.Controls.Image? 错误:无法将类型 System.type 转换为 system.drawing.Image - ERROR: Cannot convert type System.type to system.drawing.Image 如何更改无法从 'System.Drawing.Image' 转换为 'System.Drawing.Image[]? - How to change cannot convert from 'System.Drawing.Image' to 'System.Drawing.Image[]?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM