所以我有这个GUI应用程序,应该计算运费。首先,我需要输入正在发送的包的数量(已经完成),然后从domainUpDown工具中选择包#(也完成),然后在文本框中输入所选包的尺寸。这就是我被困住的地方。这就是我到目前为止所做的。
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工具中的包号,如何保存输入的文本。
答案 0 :(得分:0)
您是否尝试过注册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
}