0

我正在对我的应用程序中有三个文本框的生物种群进行分配,这将获得用户对“生物起始数量”(StartingNumOfOrganismsTextBox)、“平均每日增长”(DailyIncreaseTextBox)和“天数”的输入乘”(NumOfDaysTextBox)。

        int NumOfOrganisms = 0, DailyIncrease = 0, NumOfDays = 1;

        StartingNumOfOrganisms = int.Parse(StartingNumOfOrganismsTextBox.Text);
        DailyIncrease = int.Parse(DailyIncreaseTextBox.Text);
        NumOfDays = int.Parse(NumOfDaysTextBox.Text);

当用户在这些文本框中输入整数时,应该有一个计算按钮,当按下时,它应该自动将用户输入显示到一个名为 (PopulationsListBox) 的单独列表框中,如下所示的数据表:

例如,如果用户在提到的 TextBoxes 中输入以下输入: StartingNumOfOrganismsTextBox: 2 DailyIncreaseTextBox: 30% NumOfDaysTextBox: 5

按下计算按钮,应用程序应在 ListBox 控件中的两列中显示以下数据表。(天)列和(近似人口)列。

第 1 天,近似人群 2。第 2 天,近似人群 2.6。第 3 天,大约人口 3.38。第 4 天大约人口 4.394。第 5 天,大约人口 5.7122。

有人会给我提示如何获取所有三个用户输入,(StartingNumOfOrgranisms,DailyIncrease[%] 然后有机体将留下来繁殖的 NumOfDays,并在 ListBox 控件中显示表格的数据?这对于我,如果有人能帮助我完成这项任务,我将非常感激。谢谢。

另外,我尝试使用 ListView 代码格式来添加我的数据:

        PopulationsListBox.Items.Add("1");
        PopulationsListBox.Items[0].SubItems.Add(StartingNumOfOrganisms.ToString());
        for (int i=2;i<=NumOfDays;++i)
        {
           PopulationsListBox.Items.Add(i.ToString());
           PopulationsListBox.Items[PopulationsListBox.Items.Count-1].SubItems.Add((StartingNumOfOrganisms+StartingNumOfOrganisms*DailyIncrease).ToString());

But, "SubItems" is not a property ListBoxes use. Perhaps someone could suggest trying something similar to that for me? I will be thankful.

4

1 回答 1

0

I haven't tested this but you want to do something like this:

        listbox.Items.Add("Day 1, Approximate Population:" + txtStartingNumberOfOrganisms.Text);
        int ApproximatePopulation = Convert.ToInt16(txtStartingNumberOfOrganisms.Text);             

        for (int i = 2; i <= numOfDays; i++)
        {
            ApproximatePopulation = ApproximatePopulation + ((ApproximatePopulation * Convert.ToDouble(txtDailyIncrease.text)) / 100);
            listbox.Items.Add("Day " + Convert.ToString(i) + ", Approximate Population:" + Convert.ToString(ApproximatePopulation));
        }

Apologies if the sums are all over the place but you can figure those out ;)

于 2013-03-30T21:52:41.953 回答