-
Another TextBox Question
Hi everyone ... im just wondering if i can output a string into a textbox with a specified format.
I have an array thats 3200 chars that i want to output to a text box, however i want to output
this array in a row/column oriented fashion that is 80 columns by 40 rows. But when i add the
next lines into the array after 80 chars then output it to a text box, it will only output the
first line into the textbox.
Code:
const int NUMOFROWS = 40;
const int NUMOFCOLS = 80;
private char[] TempHeader = new char[3200];
private char[] ASCIIHeader = new char[3200];
private void DisplayASCII(char[] ASCIIHeader)
{
for (int row = 0; row < NUMOFROWS; row++)
{
for (int col = 0; col < NUMOFCOLS; col++)
{
TempHeader[col] = ASCIIHeader[col];
}
TempHeader[col] = '\n';
}
outputFileTextBox.Text = new string(TempHeader);
}
Thanks for any help :)
-
Make that '\n' a System.Environment.Newline
-
hi and thanks for the reply prog-bman. However i was able to figure it out so it works but now
the problem is its really really slow to output 3200 chars on the screen. I can almost write
this out by hand while its doing it!!! Just wondering if anyone might have an idea of why this
is ? here is the code ...
Code:
const int NUMOFROWS = 40;
const int NUMOFCOLS = 80;
private char[] ASCIIHeader = new char[3200];
private void DisplayASCII(char[] ASCIIHeader)
{
int x = 0;
for (int row = 0; row < NUMOFROWS; row++)
{
for (int col = 0; col < NUMOFCOLS; col++)
{
outputFileTextBox.Text += Convert.ToString(ASCIIHeader[x]);
x++;
}
outputFileTextBox.Text += "\r\n";
}
}
oh ya i guess the textbox requires the "\r\n" for a nextline, unlike a console that just needs \n.
any help would be great, thanks !
:)
-
You should be using a StringBuilder for that loop. It's much faster.
-
Right on! thanks for the tip prelude. With StringBuilder it works great and is fast!
Code:
const int NUMOFROWS = 40;
const int NUMOFCOLS = 80;
private char[] ASCIIHeader = new char[3200];
StringBuilder buffer = new StringBuilder();
private void DisplayASCII(char[] ASCIIHeader)
{
for (int row = 0; row < NUMOFROWS; row++)
{
for (int col = 0; col < NUMOFCOLS; col++)
{
buffer.Append(ASCIIHeader[(row) * NUMOFCOLS + col]);
}
buffer.AppendLine();
}
outputFileTextBox.Text = Convert.ToString(buffer);
}
:)