小编Mah*_*hin的帖子

更改 ErrorProvider 的图标会出现异常

我正在尝试更改 Windowsform 中 errorProvider 的图标。我已在“属性”->“资源”文件夹中添加了 .ico 文件。我尝试过直接复制粘贴 .ico 文件,还使用了“添加资源”->“添加现有文件”选项。无论我做什么,如果我添加自己的 .ico 文件并尝试将它们设置为 errorProvider 图标(如下面的代码所示),我会在运行程序时遇到异常(特别是在尝试演示程序中的 errorProvider 功能时) 。我的代码是:

 private void textBox1_Leave(object sender, EventArgs e)
        {
            if(string.IsNullOrEmpty(textBox1.Text))
            {
                textBox1.Focus();
                errorProvider1.Icon = Properties.Resources.cross; //here I have change the default icon
                errorProvider1.SetError(this.textBox1, "Input UserId"); //having exception in this line
            }
            else
            {
                errorProvider1.Icon = Properties.Resources.right;
            }
        }
Run Code Online (Sandbox Code Playgroud)

异常详细信息:

System.StackOverflowException
  HResult=0x800703E9
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>
Run Code Online (Sandbox Code Playgroud)

c# errorprovider windows-forms-designer visual-studio .net-4.8

1
推荐指数
1
解决办法
772
查看次数