输出多维数组中网格样式的文本框 [英] output multidimensional array to grid style textbox
本文介绍了输出多维数组中网格样式的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有文本格式的麻烦,同时试图输出我的数组到一个文本框。
我需要输出这样的事情; http://imgur.com/jQFYsXA,c0ihHyI
有点像表减去边框。
香港专业教育学院设法生产出类似的东西,但我的想法。
http://imgur.com/ZwHh7qj
我的code是:
字符串[,] =玩具新的字符串[5,4]。
对于(INT周= 0;&本周LT; = 3;周++)
{
对于(INT天= 0;日间及LT; = 4;天++)
{
玩具[日,周] = Microsoft.VisualBasic.Interaction.InputBox(日间请输入值+ Convert.ToString(日+ 1)+一周中的+ Convert.ToString(周+ 1)+。) ;
}
}
txtOutput.Text + =星期一+\\ t+星期二+\\ t+星期三+\\ t+星期四+\\ t+星期五+\\ t+ \\ r \\ n;
txtOutput.Text + =1周+\\ t+\\ r \\ n;
txtOutput.Text + =第2周+\\ t+\\ r \\ n;
txtOutput.Text + =3周+\\ t+\\ r \\ n;
txtOutput.Text + =4周+\\ t+\\ r \\ n;的foreach(玩具字符串文本)
{ txtOutput.Text + =文字+\\ t的;
}
解决方案
要做到这一点,最简单的方法是通过画线线如下:
//首先,通过接受一些投入成立了玩具指数
字符串[,] =玩具新的字符串[5,4]。
对于(INT周= 0;&本周LT; = 3;周++)
{
对于(INT天= 0;日间及LT; = 4;天++)
{
玩具[日,周] = Microsoft.VisualBasic.Interaction.InputBox(日间请输入值+ Convert.ToString(日+ 1)+一周中的+ Convert.ToString(周+ 1)+。) ;
}
}
//然后,通过玩具阵列循环打印由线的输出线
//因为标题是不是阵列的一部分的第一行必须是独立的
txtOutput.Text + =星期一+\\ t+星期二+\\ t+星期三+\\ t+星期四+\\ t+星期五+\\ t+ \\ r \\ n;对于(INT周= 0;&本周LT; = 3;周++)//周的foreach
{
//构建文本从而重新presents本周的数据线
txtOutput.Text + =\\ tWeek+(周+ 1)+\\ t的;
对于(INT天= 0;日间及LT; = 4;天++)
{
txtOutput.Text + =玩具[日,周]
如果(天!= 4)
{
//只要它不是最后一天,那么你必须在标签
txtOutput.Text + =\\ t的;
}
} //移动到下一行包东西,你遍历到下一行之前
txtOutput.Text + =\\ r \\ n;
}
I am having trouble with text formatting while trying to output my array into a textbox.
I'm required to output something like this; http://imgur.com/jQFYsXA,c0ihHyI sort of like a table minus the borders.
Ive managed to produce something similar, but i'm out of ideas. http://imgur.com/ZwHh7qj
My code is:
string[,] toys = new string[5, 4];
for (int week = 0; week <= 3; week++)
{
for (int day = 0; day <= 4; day++)
{
toys[day, week] = Microsoft.VisualBasic.Interaction.InputBox("Please enter value for Day " + Convert.ToString(day + 1) + " in week " + Convert.ToString(week + 1) + ".");
}
}
txtOutput.Text += "Mon" + "\t" + "Tue" + "\t" + "Wed" + "\t" + "Thu" + "\t" + "Fri" + "\t" + "\r\n";
txtOutput.Text += "Week 1" + "\t" + "\r\n";
txtOutput.Text += "Week 2" + "\t" + "\r\n";
txtOutput.Text += "Week 3" + "\t" + "\r\n";
txtOutput.Text += "Week 4" + "\t" + "\r\n";
foreach (string text in toys)
{
txtOutput.Text += text + "\t";
}
解决方案
The easiest way to do this is by drawing line by line as follows:
//first, set up the toys index by accepting some inputs
string[,] toys = new string[5, 4];
for (int week = 0; week <= 3; week++)
{
for (int day = 0; day <= 4; day++)
{
toys[day, week] = Microsoft.VisualBasic.Interaction.InputBox("Please enter value for Day " + Convert.ToString(day + 1) + " in week " + Convert.ToString(week + 1) + ".");
}
}
//then, print the output line by line by looping through the toys array
//the first line must be separate because the headings are not part of the array
txtOutput.Text += "Mon" + "\t" + "Tue" + "\t" + "Wed" + "\t" + "Thu" + "\t" + "Fri" + "\t" + "\r\n";
for (int week = 0; week <= 3; week++)//foreach week
{
//construct the line of text which represents the week's data
txtOutput.Text += "\tWeek " + (week+1) + "\t";
for (int day = 0; day <= 4; day++)
{
txtOutput.Text += toys[day,week];
if(day != 4)
{
//so long as it is not the last day, then you have to tab over
txtOutput.Text += "\t";
}
}
//wrap things up by moving to the next line before you iterate to the next line
txtOutput.Text += "\r\n";
}
这篇关于输出多维数组中网格样式的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文