问题描述
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
推荐答案
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循环的值添加到文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!