检查包装盒时要求确认

时间:2011-11-12 00:45:27

标签: c# .net winforms

我目前有一个包含多个复选框的表单,一旦选中所有复选框或将其留空,它会将其发送到数据库中复选框的状态 我想补充一点,如果没有选中一个方框,当你检查它时,它应该询问确认窗口“你确定要检查这个” 有什么帮助吗?

这是当前的代码

            public IMeditor(IMui IMui, IMuser U, string User)
    {
        InitializeComponent();
        this.IMui = IMui;
        imu = U;
        if (imu.UID == 0)
        {
            Add.Text = "Add";
            imu.name = user;
        }
        else
            Add.Text = "Update";
        AuthChat.Checked = imu.AuthChat == 1;
        AuthTac1.Checked = imu.AuthTac1 == 1;
        AuthTac2.Checked = imu.AuthTac2 == 1;
        AuthTac3.Checked = imu.AuthTac3 == 1;
        AuthTac4.Checked = imu.AuthTac4 == 1;
        AuthTac5.Checked = imu.AuthTac5 == 1;
        AuthTac6.Checked = imu.AuthTac6 == 1;
        AuthTac7.Checked = imu.AuthTac7 == 1;
        AuthTac8.Checked = imu.AuthTac8 == 1;
        AuthTac9.Checked = imu.AuthTac9 == 1;
        AuthTac10.Checked = imu.AuthTac10 == 1;

        switch (imu.Transport.ToLower()) {
            case "aim":   Transport.SelectedIndex = 0; break;
            case "gtalk": Transport.SelectedIndex = 1; break;
            case "msn":   Transport.SelectedIndex = 2; break;
            case "yahoo": Transport.SelectedIndex = 3; break;
        }
    }

5 个答案:

答案 0 :(得分:2)

我同意Izzy的观点。添加类似

的内容
    private void PrivateInitialize()
    {

        CheckBox chkBox = new CheckBox();
        chkBox.Text = "Click me";
        chkBox.CheckedChanged += new EventHandler(chkBox_CheckedChanged);
    }

    private void chkBox_CheckedChanged(object sender, EventArgs e)
    {
        MessageBox.Show("Nag, nag, nag!  You take out the trash yet?");
    }

答案 1 :(得分:1)

您需要为复选框处理事件CheckedChangedEvent。您可以在MSDN上找到示例代码。还

this link for the complete了解复选框。

否则你可以从Windows窗体的CheckBox控件派生自己的类,然后覆盖所需的函数并实现自己的逻辑,并从这个派生类创建应用程序中的所有复选框

答案 2 :(得分:0)

public IMeditor(IMui IMui, IMuser U, string User)
    {
        InitializeComponent();
        this.IMui = IMui;
        imu = U;
        if (imu.UID == 0)
        {
            Add.Text = "Add";
            imu.name = user;
        }
        else
            Add.Text = "Update";
        AuthChat.Checked = imu.AuthChat == 1;
        AuthTac1.Checked = imu.AuthTac1 == 1;
        AuthTac2.Checked = imu.AuthTac2 == 1;
        AuthTac3.Checked = imu.AuthTac3 == 1;
        AuthTac4.Checked = imu.AuthTac4 == 1;
        AuthTac5.Checked = imu.AuthTac5 == 1;
        AuthTac6.Checked = imu.AuthTac6 == 1;
        AuthTac7.Checked = imu.AuthTac7 == 1;
        AuthTac8.Checked = imu.AuthTac8 == 1;
        AuthTac9.Checked = imu.AuthTac9 == 1;
        AuthTac10.Checked = imu.AuthTac10 == 1;

        switch (imu.Transport.ToLower()) {
            case "aim":   Transport.SelectedIndex = 0; break;
            case "gtalk": Transport.SelectedIndex = 1; break;
            case "msn":   Transport.SelectedIndex = 2; break;
            case "yahoo": Transport.SelectedIndex = 3; break;
        }

         AuthChat.CheckedChanged += new EventHandler(CheckChangedHandler);
         AuthChat1.CheckedChanged += new EventHandler(CheckChangedHandler);

    }

 void CheckChangedHandler(Object obj, EventArgs args)
        {
            if (obj == AuthChat)
            {
                MessageBox.Show("Checked changed for AuthChat");
            }
            else if (obj == AuthChat1)
            {
                MessageBox.Show("Checked changed for AuthChat1");
            }
        }

答案 3 :(得分:0)

public IMeditor(IMui IMui, IMuser U, string User)
    {
        InitializeComponent();
        this.IMui = IMui;
        imu = U;
        if (imu.UID == 0)
        {
            Add.Text = "Add";
            imu.name = user;
        }
        else
            Add.Text = "Update";
        AuthChat.Checked = imu.AuthChat == 1;
        AuthTac1.Checked = imu.AuthTac1 == 1;
        AuthTac2.Checked = imu.AuthTac2 == 1;
        AuthTac3.Checked = imu.AuthTac3 == 1;
        AuthTac4.Checked = imu.AuthTac4 == 1;
        AuthTac5.Checked = imu.AuthTac5 == 1;
        AuthTac6.Checked = imu.AuthTac6 == 1;
        AuthTac7.Checked = imu.AuthTac7 == 1;
        AuthTac8.Checked = imu.AuthTac8 == 1;
        AuthTac9.Checked = imu.AuthTac9 == 1;
        AuthTac10.Checked = imu.AuthTac10 == 1;

        switch (imu.Transport.ToLower()) {
            case "aim":   Transport.SelectedIndex = 0; break;
            case "gtalk": Transport.SelectedIndex = 1; break;
            case "msn":   Transport.SelectedIndex = 2; break;
            case "yahoo": Transport.SelectedIndex = 3; break;
        }

         AuthChat.Click += new EventHandler(ClickHandler);


    }

 void ClickHandler(Object obj, EventArgs args)
        { 
if (obj == AuthChat && AuthChat.CheckState == CheckState.Checked)
            {
                DialogResult result = MessageBox.Show("Do you want to change?", "are you sure?", MessageBoxButtons.YesNo);        

                if (result == DialogResult.No)
                {
                    AuthChat.Checked = false;
                }
            }
        }

答案 4 :(得分:-1)

用javascript做到这一点?添加OnClientClick =“return confirmCheck(this);”

<script language="javascript">
function confirmCheck(e){
 return confirm("are you sure?");
 // do other stuff
}
</script>

这应该比重定向人更好