只打印1行到文本框,而不是关闭所有语句c#

时间:2017-03-24 11:20:16

标签: c#

我试图将所有真实的陈述从我的文件打印到文本框。出于某种原因,只出现了一条线。我无法看到错误或遗漏支架。

我有单选按钮,我已经分配了一个变量,然后打印到文档,这是有效的。我用过.toString();因为当我试图在txtbox中显示这个的摘要时,我收到的错误是无法将字符串更改为int。

`

//if radio button is checked write to file
            if (rdoIndoor.Checked == true)
            {
                rdoIndoor.Text = iIndoor.ToString();
                sw.WriteLine(rdoIndoor.Text);
            }
            else
            {
                rdoOutdoor.Text = iOutdoor.ToString();
                sw.WriteLine(rdoOutdoor.Text);
            }

            //if radio button is checked write to file
            if (rdoFree.Checked == true)
            {
                rdoFree.Text = iFree.ToString();

                sw.WriteLine(rdoFree.Text);
            }
            else
            {
                rdoPriced.Text = iPriced.ToString();

                sw.WriteLine(rdoPriced.Text);
            }

代码:

                        txtSummary.Text = "Music events were most popular        this year" + Environment.NewLine;
                    }
                    else
                    {
                        txtSummary.Text = "Theatre events were most popular this year" + Environment.NewLine;
                    }

                    //find out if free or pri string line = string.Empty;
        while ((line = sr.ReadLine()) != null)
        {
            for (int iCount = 0; iCount < sMonths.Length; iCount++)
            {


                //conditions
                if (iCount == 2)
                {
                    sMonths[iCount] = sr.ReadLine();

                    //find out which type of event was more popular within the year 

                    if (iCountDance > iCountArt && iCountDance > iCountMusic && iCountDance > iCountTheatre)
                    {
                        txtSummary.Text = "Dance events were most popular this year" + Environment.NewLine;
                    }
                    else if (iCountArt > iCountDance && iCountArt > iCountMusic && iCountArt > iCountTheatre)
                    {
                        txtSummary.Text = "Art events were most popular this year" + Environment.NewLine;
                    }
                    else if (iCountMusic > iCountDance && iCountMusic > iCountArt && iCountMusic > iCountTheatre)
                    {ced events were more popular this year
                    if (iPriced > iFree)
                    {
                        txtSummary.Text = "Priced events were more popular this year" + Environment.NewLine;
                    }
                    else if (iFree > iPriced)
                    {
                        txtSummary.Text = "Free events were moree popular this year" + Environment.NewLine;
                    }

                    iAttendanceTotal = iAttendance * iAttendance;
                    txtSummary.Text = "At least " + iAttendanceTotal + " people attended events over the year" + Environment.NewLine;
                }

1 个答案:

答案 0 :(得分:0)

替换此

txtSummary.Text =...

有了这个:

txtSummary.Text +=

因为每次分配新值时,它都会用新值替换存储的值。

希望它有所帮助!