[英]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.