如何在2D数组中存储用户输入?

时间:2022-07-26 15:41:56

So I have this GUI application that is supposed to calculate shipping costs. First I need to enter the number of packages that is being shipped (already done), then choose package # from a domainUpDown tool(also complete), and then input dimensions for selected package in a text box. This is where I'm stuck. This is what I have thus far.

所以我有这个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..

The thing I'm confused about is how to save entered text if user somehow changes package number from domainUpDown tool.

我很困惑的是如果用户以某种方式更改domainUpDown工具的包号,如何保存输入的文本。

1 个解决方案

#1


0  

Have you tried registering to the OnChanged or SelectedItemChanged events of the DomainUpDown ?

您是否尝试过注册DomainUpDown的OnChanged或SelectedItemChanged事件?

Perform saving on the OnChanged event handler.

在OnChanged事件处理程序上执行保存。

Example:

     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 
      }

#1


0  

Have you tried registering to the OnChanged or SelectedItemChanged events of the DomainUpDown ?

您是否尝试过注册DomainUpDown的OnChanged或SelectedItemChanged事件?

Perform saving on the OnChanged event handler.

在OnChanged事件处理程序上执行保存。

Example:

     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 
      }