初学c#,诚心求解!!目的是当NumericUpDown控件达到最大值时弹窗,但关闭后就报错:未将对象引用设置
不知是哪里出错了渣码如下:publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privat...
不知是哪里出错了
渣码如下:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
label1.Visible = false;
numericUpDown1.Minimum = 0;
numericUpDown1.Maximum = 25;
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
label1.Visible = true;
if (numericUpDown1.Value == numericUpDown1.Maximum)
{
label1.Text = (numericUpDown1.Value).ToString();
MessageBox.Show("max value");
}
else
{
label1.Text = (numericUpDown1.Value).ToString ();
}
}
} 展开
渣码如下:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
label1.Visible = false;
numericUpDown1.Minimum = 0;
numericUpDown1.Maximum = 25;
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
label1.Visible = true;
if (numericUpDown1.Value == numericUpDown1.Maximum)
{
label1.Text = (numericUpDown1.Value).ToString();
MessageBox.Show("max value");
}
else
{
label1.Text = (numericUpDown1.Value).ToString ();
}
}
} 展开
展开全部
这个问题其实有点麻烦(你的代码从表面看是没问题的),这个vlaluechange事件由多线程实现的,在其它线程中访问主线程的控件可能有点问题,加个委托好了
this.BeginInvoke(new MethodInvoker(delegate
{
label1.Visible = true;
if (numericUpDown1.Value == numericUpDown1.Maximum)
{
label1.Text = (numericUpDown1.Value).ToString();
MessageBox.Show("max value");
}
else
{
label1.Text = (numericUpDown1.Value).ToString();
}
}));
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询