如何将for循环的值添加到文本框中 [英] how to add value of for loop into a textbox

查看:379
本文介绍了如何将for循环的值添加到文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void Window_Loaded_1(object sender, RoutedEventArgs e)
   {
      int ymax = 500;
      parentchart.Axes.Add(new LinearAxis() { Minimum = 0, Orientation=AxisOrientation.Y, Maximum = ymax > 0 ? ymax : 300 });
      txty.Text = ymax.ToString();
      List<int> inp = new List<int>();
      for (int i = 0; i <= ymax; i++)
         {
            inp.Add(i);
            textbox.Text = inp.ToString();
            cmbb.ItemsSource = inp;
            cmbb.SelectedIndex = 0;
         }
   }





这里我想让文本框包含0到500之间的值,应该在文本框中垂直scorlling



它是一个wpf应用程序



here i want to make that textbox should contain value from 0 to 500 and there should be vertical scorlling in the textbox

its an wpf application

推荐答案

然后附加值而不是赋值他们。要么:

Then append the values rather than assign them. Either:
textbox.Text += inp.ToString();

或更好,请使用StringBuilder:

or better, use a StringBuilder:

StringBuilder sb = new StringBuilder;
string sep = "";
for (int i = 0; i <= ymax; i++)
   {
      inp.Add(i);
      sb.AppendFormat("{0}{1}", sep, inp);
      sep = ",";
      cmbb.ItemsSource = inp;
      cmbb.SelectedIndex = 0;
   }
textbox.Text = sb.ToString();

但是......你可能想要移动 cmbb 循环外的行。

But... you probably want to move the cmbb lines outside the loop as well.


Collapse | Copy Code

private void Window_Loaded_1(object sender, RoutedEventArgs e)
   {
      int ymax = 500;
      parentchart.Axes.Add(new LinearAxis() { Minimum = 0, Orientation=AxisOrientation.Y, Maximum = ymax > 0 ? ymax : 300 });
      txty.Text = ymax.ToString();
      List<int> inp = new List<int>();
      for (int i = 0; i <= ymax; i++)
         {
            inp.Add(i);
            textbox.Text = inp.ToString();
            cmbb.ItemsSource = inp;
            cmbb.SelectedIndex = 0;
         }
   }



textbox.Text + = inp.ToString();







StringBuilder sb = new StringBuilder;

string sep =;

for(int i = 0; i< = ymax; i ++)

{

inp.Add(i);

sb.AppendFormat({0 } {1},sep,inp);

sep =,;

cmbb.ItemsSource = inp;

cmbb.SelectedIndex = 0;

}

textbox.Text = sb.ToString();


textbox.Text += inp.ToString();



StringBuilder sb = new StringBuilder;
string sep = "";
for (int i = 0; i <= ymax; i++)
{
inp.Add(i);
sb.AppendFormat("{0}{1}", sep, inp);
sep = ",";
cmbb.ItemsSource = inp;
cmbb.SelectedIndex = 0;
}
textbox.Text = sb.ToString();


这篇关于如何将for循环的值添加到文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆