简体   繁体   English

消息框随时弹出

[英]Message box pops up evertime

I want the messagebox to only show if the number is equal to 0. That part works the part that is giving me a bit of an issue is, when nudTwoByTwo_1_ValueChanged is at zero and I increment nudTwoByTwo_2_ValueChanged to 1 it still gives me the messagebox everytime I increment nudTwoByTwo_2_ValueChanged. 我希望消息框仅在数字等于0时显示。该部分起作用的部分是,当nudTwoByTwo_1_ValueChanged为零且我将nudTwoByTwo_2_ValueChanged递增为1时,每次我仍然给我消息框增量nudTwoByTwo_2_ValueChanged。 It does that until I increment nudTwoByTwo_1_ValueChanged to 1. I would like for them to work seperatly. 直到我将nudTwoByTwo_1_ValueChanged递增为1为止。我希望它们分别工作。 If nudTwoByTwo_1_ValueChanged is set to 0 then throw the messagebox and the same goes for nudTwoByTwo_2_ValueChanged 如果将nudTwoByTwo_1_ValueChanged设置为0,则抛出该消息框,对于nudTwoByTwo_2_ValueChanged也是一样。

I am creating a lottery game. 我正在创建一个彩票游戏。 the min and max value is set 0-20. 最小值和最大值设置为0-20。 I dont want to default the min to 1. 我不想将最小值默认为1。

using System;
using System.Windows.Forms;

namespace LotteryTickets
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void nudPickFive_1_ValueChanged(object sender, EventArgs e)
    {

    }

    private void nudTwoByTwo_1_ValueChanged(object sender, EventArgs e)
    {
        if (cbTwoBytwo.Checked)

            errorcheck();

    }

    private void nudTwoByTwo_2_ValueChanged(object sender, EventArgs e)
    {
        if (cbTwoBytwo.Checked)
        errorcheck();  
    }
    public void errorcheck()
    {



            if (nudTwoByTwo_1.Value == 0)
            {
                MessageBox.Show("Enter a number between 1 -20");
            }

    }



    private void gbTwoByTwo_Enter(object sender, EventArgs e)
    {

    }

    private void cbTwoBytwo_CheckedChanged(object sender, EventArgs e)
    {

    }
}

} }

You need to pass values to error check. 您需要将值传递给错误检查。

public void errorcheck(int val)
{

        if (val == 0)
        {
            MessageBox.Show("Enter a number between 1 -20");
        }

}

private void nudTwoByTwo_1_ValueChanged(object sender, EventArgs e)
{
    if (cbTwoBytwo.Checked)
        errorcheck((int)nudTwoByTwo_1.Value);
}

private void nudTwoByTwo_2_ValueChanged(object sender, EventArgs e)
{
    if (cbTwoBytwo.Checked)
        errorcheck((int)nudTwoByTwo_2.Value);  
}

DISCLAIMER : Untested. 免责声明 :未经测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 消息框不止一次弹出 - Message Box Pops up more than once C#消息框在计时器中反复弹出 - C# Message Box Pops up Repeatedly in a Timer C#退出消息框弹出两次。 我想生成一次事件。 - C# The exit message box pops up twice. I want to generate an event once. 没有项目时,“自动完成”框会弹出默认消息 - Autocomplete box pops a default message when no item exist 弹出窗口时如何保持文本框的焦点 - How to keep text box's focus when a window pops up C#Visual Studio-您能否创建一个通知/消息框,该通知/消息框独立于程序弹出,并且不会阻止其完全关闭? - C# Visual Studio - Can you create a notification / message box that pops up independently from your program and won't stop it from closing completely? 弹出UAC消息时,屏幕颜色默认为正常(无法检测) - Screen colour defaulting to normal when UAC message pops up (undetectable) 为什么弹出的FlipView中包含我的文本框,而软键盘却遮盖了它? - Why is my text box contained in a FlipView obscured by the soft keyboard when it pops up? 尝试添加浏览过的图片时会弹出错误消息但代码是正确的 - when trying to add a browsed picture an error message pops up but the code is correct 为什么消息框未通过RDP显示 - Why is message box not showing up over RDP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM