我尝试使用numeric updown在一个数组中来回移动,该数组存储用户进行的输入测试的分数。老实说,我甚至不知道从哪里开始。我写了一些代码,但看起来没什么用。
private void testUpDown_ValueChanged(object sender, EventArgs e)
{
foreach (testUpDown.Value = allTests[i])
{
prevErrorsBox = Errors.ToString();
prevWpmBox = WPM.ToString();
}
}正如您可以想象的那样,它不会做很多事情。我应该对此使用不同的控件吗?这是通过3层设计完成的,如果这很重要的话。我还必须让这个表单从数据库中加载值。
提前感谢您的帮助。
发布于 2012-11-25 14:05:42
您需要使用向上/向下控件更改数组的索引,以确保不能超出数组的界限。看看这样的东西对你是否有效。
public partial class Form1 : Form
{
string[] values;
public Form1()
{
InitializeComponent();
values = setValueArray();
numericUpDown1.Maximum = values.Length - 1;
numericUpDown1.Minimum = 0;
}
private string[] setValueArray()
{
return new string[] { "100", "90", "80", "70", "60" };
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
label1.Text = values[(int)((NumericUpDown)sender).Value];
}
}https://stackoverflow.com/questions/13548659
复制相似问题