首页 > 解决方案 > C# 如何使用我的 MessageBoxButtons/Icons 修复此错误错误

问题描述

设计注册表单,添加 MessageBoxButtons 和 MessageBoxIcon 时出现此错误。错误是“参数2:无法将'system.windows.forms.Messageboxicon'转换为'string'。错误所在的代码是这样的:**

MessageBox.Show("您的账号注册成功", MessageBoxIcon.Exclamation, MessageBoxButtons.OK);

** 以及这里:

MessageBox.Show("请正确填写所有方框", MessageBoxIcon.Exclamation, MessageBoxButtons.OK);

当我删除 Messageboxbutton/icon 时,没有错误。这是我得到的:

        {
        MyConnections.insert.CommandText = "INSERT Customer(EmailAddress,Firstname,Surname,Password)VALUES('" + txtEmail.Text + "','" + txtFirst.Text + "','" + txtSur.Text + "','" + txtPassword.Text + "')";
        MyConnections.insert.Connection = MyConnections.Customer;
        MyConnections.Customer.Open();
        MyConnections.insert.ExecuteNonQuery();
        MyConnections.Customer.Close();

        if (txtFirst.Text.Length > 0 && txtSur.Text.Length > 0 && txtEmail.Text.Length > 0 && txtPassword.Text.Length > 0 && txtConfirmPass.Text.Length > 0)


        {
            MessageBox.Show("You have successfully registered your account", MessageBoxIcon.Exclamation, MessageBoxButtons.OK);


        }

        else
        {
            MessageBox.Show("Please fill in all of the boxes correctly", MessageBoxIcon.Exclamation, MessageBoxButtons.OK);


        }

标签: c#messagebox

解决方案


在这里,您确实有正确的顺序,但您忘记添加标题

MessageBox.Show("You have successfully registered your account","Your caption goes here", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

希望这可以帮助。


推荐阅读