Thread: Another TextBox Question

  1. #1
    Registered User C of Green's Avatar
    Join Date
    Jan 2002
    Location
    Calgary/Canada
    Posts
    59

    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

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Make that '\n' a System.Environment.Newline
    Woop?

  3. #3
    Registered User C of Green's Avatar
    Join Date
    Jan 2002
    Location
    Calgary/Canada
    Posts
    59
    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 !


  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    You should be using a StringBuilder for that loop. It's much faster.
    My best code is written with the delete key.

  5. #5
    Registered User C of Green's Avatar
    Join Date
    Jan 2002
    Location
    Calgary/Canada
    Posts
    59
    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);
            }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 03-02-2009, 08:33 AM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM