[英]an unhandled exception of type 'System.ArgumentException' occurred in System.Windows.Forms.dll
I'm really a newbie at programming so do excuse me if my knowledge seems really inadequate. 我确实是编程的新手,所以如果我的知识似乎真的不足,请原谅我。 I'm doing a C# project for my school and I'm having problems with my homework, thanks
我正在为我的学校做一个C#项目,但是我的作业有问题,谢谢
some codes in here: 一些代码在这里:
using System;
using System.Drawing;
private void button1_Click(object sender, EventArgs e)
{
child frm2 = new child();
frm2.ShowDialog();
int color = 0;
int i = 0;
Random rnd = new Random();
i = rnd.Next(51);
frm2.BackColor = Color.FromArgb(i*color);
frm2.ShowDialog();
if (color == 5)
{
color = 0;
}
}
The problem is this line: 问题是这一行:
frm2.BackColor = Color.FromArgb(i*color);
Since your i
variable is 0 (zero), the resulting color is transparent, and the exact exception message you are getting should be like this: 由于您的
i
变量为0(零),因此生成的颜色是透明的,并且您收到的确切异常消息应如下所示:
An unhandled exception of type 'System.ArgumentException' occurred in System.Windows.Forms.dll
System.Windows.Forms.dll中发生了类型为'System.ArgumentException'的未处理异常
Additional information: Control does not support transparent background colors.
附加信息:控件不支持透明的背景色。
In order to fix it, correct your logic for i
and color
variables and use the following: 为了解决此问题,请更正
i
和color
变量的逻辑并使用以下命令:
frm2.BackColor = Color.FromArgb(255, Color.FromArgb(i * color));
which removes the transparency from the generated color - see Color.FromArgb Method (Int32, Color) . 可以从生成的颜色中删除透明度-请参见Color.FromArgb方法(Int32,Color) 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.