如何在二维数组中存储用户输入
本文关键字:存储 用户 输入 二维数组 | 更新日期: 2023-09-27 18:14:15
所以我有这个GUI应用程序,它应该计算运输成本。首先,我需要输入要运送的包的数量(已经完成),然后从domainUpDown工具(也是完成的)中选择package #,然后在文本框中输入所选包的尺寸。这就是我被困的地方。这是我目前掌握的信息。
const int WEIGHT = 0
const int NMBR_OF_PROPETIES = 7;
const int MAX_PACKAGES = 10;
const double FLAT_RATE = 4.99;
int numOfPackages, packageNumber;
double[,] packagesArray = new double[MAX_PACKAGES, NMBR_OF_PROPETIES];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//label texts get initialized
}
private void button1_Click(object sender, EventArgs e)
{
if (!int.TryParse(numOfPackagesTextBox.Text, out numOfPackages))
{
//message box tells that number cant be parsed
}
else if(numOfPackages > 0 && numOfPackages < 10)
{
//everything in the program is enabled
}
else
{
//message box saying that you can't ship more than 10 packages
}
//adding package numbers to the domainUpDown tool
DomainUpDown.DomainUpDownItemCollection items = packageUpDown.Items;
for (int packageNumber = 1; packageNumber <= numOfPackages; packageNumber++)
{
items.Add(packageNumber);
}
}
private void weightBox_TextChanged(object sender, EventArgs e)
{
packagesArray[(int)packageUpDown.SelectedItem, WEIGHT] = Convert.ToInt32(weightBox.Text);
//also here goes the rest of the dimension entry
}//from here i don't know what to do, and im sure that this isn't right..
我感到困惑的是如何保存输入的文本,如果用户从domainUpDown工具以某种方式改变包号。
您是否尝试过注册DomainUpDown的OnChanged或SelectedItemChanged事件?
在OnChanged事件处理程序上执行保存。
的例子:
myDomainUpDown.OnChanged += new EventHandler(myDomainUpDown_OnChanged);
void OnChanged(object sender, EventArgs e)
{
//save all the information you need in whatever collection/file/db you want
}