简体   繁体   English

System.Windows.Forms.dll中发生类型为'System.ArgumentException'的未处理异常

[英]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: 为了解决此问题,请更正icolor变量的逻辑并使用以下命令:

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.

相关问题 BLL.dll中发生了'System.ArgumentException'类型的未处理异常 - An unhandled exception of type 'System.ArgumentException' occurred in BLL.dll Windows窗体应用程序数据库:“ System.Data.dll中发生了'System.ArgumentException'类型的未处理异常” - Windows form application database: “An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll” Windows窗体应用程序数据库:“System.Data.dll中发生了'System.ArgumentException'类型的未处理异常” - Windows form application database: “An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll” System.Windows.Forms.dll中发生了类型为'System.StackOverflowException'的未处理异常 - An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll “System.Windows.Forms.dll中发生了'System.StackOverflowException'类型的未处理异常” - “An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll” 生成报告导致在system.windows.forms.dll中发生类型为'system.stackoverflowexception'的未处理异常 - Generating report results in an unhandled exception of type 'system.stackoverflowexception' occurred in system.windows.forms.dll 错误:System.Windows.Forms.dll中发生未处理的“System.BadImageFormatException”类型异常 - Error: An unhandled exception of type 'System.BadImageFormatException' occurred in System.Windows.Forms.dll 发生类型为'System.ArgumentException'的未处理异常 - An unhandled exception of type 'System.ArgumentException' occurred System.Drawing.dll(C#,VisualStudio 2015)中发生类型为'System.ArgumentException'的未处理异常 - An unhandled exception of type 'System.ArgumentException' occurred in System.Drawing.dll (C#, VisualStudio 2015) System.Drawing.dll中发生了'System.ArgumentException'类型的未处理异常,用于灰度 - An unhandled exception of type 'System.ArgumentException' occurred in System.Drawing.dll for grayscale
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM