MessageBox,执行代码时不止一个

时间:2018-08-08 18:01:08

标签: c# io messagebox

我正在Visual Studio C#中创建一个代码,当我执行代码时,我到达一个弹出消息框的区域,以确认是否要更改值。此时,第二个MessageBox将首先进行。有人对我如何消除第二个盒子有任何想法吗?

请注意:我在过去编写的代码中遇到此错误,但是每次重置代码时,它都会不断增加盒子的数量,因为该控件是在启动时调用的我的Initialize方法之一中调用的,该错误我总是始终有两个MessageBoxes

编辑:这是一个直接显示在其后的消息框。

使用MessageBox并出现问题的代码示例:

private void comboBoxReprint_SelectedIndexChanged(object sender, EventArgs e)
{
    DialogResult result = MessageBox.Show(
        "Change Reason to: \r\n" comboBoxReprint.Text + "\r\n\r\n" + "Confirm?", 
        "Label Reprint Reason",
        MessageBoxButtons.YesNo, MessageBoxIcon.Information);

        if (result == DialogResult.Yes)
        {
            Console.WriteLine("PROCEED WITH PROCESS");


            //Grab the selection so I can save it 
            string _reason = (string)comboBoxReprint.SelectedItem;


            //move forward in the flowchart.
            if (MODE == "B")
            {
                //SAVE BAG REPRINT REASON TO DB TABLE;
                //Get time in this moment.
                string _time = DateTime.Now.ToString("h:mm:ss tt");
                //InsertData(ID, _reason, "LabelReprintReasonBag");
            }

            else if (MODE == "P")
            {
                //SAVE PACK REPRINT REASON TO TABLE;
                //InsertData(ID, _reason, "LabelReprintReasonPack");
            }

            comboBoxReprint.Enabled = false;


            //Proceed to section B of flowchat. 
            if (MODE == "B")
            {
                QueryTestPresCheck();
            }

            else if (MODE == "P")
            {
                //Run Query for Bagging VI result *************************************************************************************************
                //SelectData(_LN, _SN, "BAGGING_VI_RESULT");
            }
        }
        else if (result == DialogResult.No)
        {
            comboBoxReprint.ResetText();
        }
    }

0 个答案:

没有答案