Results 1 to 19 of 19

Thread: [RESOLVED] Help me speed this up...

Hybrid View

  1. #1

    Thread Starter
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Help me speed this up...

    Suspend and resume layout only affect resizing and redrawing of controls, from what I got out of my experimenting with it this afternoon.

    It turns out, the original method using the RichTextBox.Find is still faster than the char-by-char method, but not because of calculation time.. The actual char by char writing to the RichTextBox, whether visible, disabled, suspended, or not, is incredibly slow.

    I can load a huge file into the RTB in almost no time using standard streamreader read methods, but char by char it's way too slow. I did some testing with my parsing method, and if I use special characters to define where colors would stop and start, rather than actually coloring/writing them to the RTB, and write that string to the RTB all in black, the text loads at what is not noticably any slower speed.

    Conversely, if I read in the strings one line at a time, and add them to the RTB one character at a time, it's pretty much the same speed as it is when I am writing the formatted text one char at a time.

    So, is there a way, to build a Rich Text string with formatting, and write it line-at-a-time to the RTB? I think if I could do that, the speed would go right up where I want it.

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Help me speed this up...

    What if you created a dynamic RTB in memory and populated it that way?

    Also instead of doing it char by char, why not load all the text into the RTB and just read it char by char and apply formatting to words.

    I might try and create some code to do this tonight just for fun. If I get something efficient, I will post it.

  3. #3

    Thread Starter
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Help me speed this up...

    I tried just making a temporary RTB to write to.. it was just as slow. however, I did manage to figure out how RTF files work (more or less)

    http://www.biblioscape.com/rtf15_spec.htm#Heading16

    With that link..

    And, after doing one the slow way, I saved it to an RTF file, and viewed it with notepad. I can see all the formatting, and so on, so I thought I would try to build the formatted strings and insert them using the RichtTextBox.Rtf method instead of using SelectedText. Unfortunately, I get a file format error every time I try to insert a string I'm gonna keep playing with it and see what I can do..

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  4. #4

    Thread Starter
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Help me speed this up...

    OK, so that worked well. now that I've figured out how to format RTF text (and not have pieces vanish?!@#) It's good and fast. Only one problem.

    RTF codes use our friend the backslash : \ to signify that there are functions coming. So, if I want to actually have that character displayed, I have to send \\. No big deal, just like C# actually. The problem comes in with the string quotes being colored in certain cases.

    for example:

    string myString = "\"Bill\""; would in C#set Bill to the value "Bill". So if my state is switched off at the first escape sequence for the quote, Bill would be black, rather than red.
    i.e,
    string myString = "\"Bill\"";
    A more serious problem occurs if there is only one of these in a string, like this:

    string mystring = "\" <- Thats the quote";

    Where that string would translate to : " <-Thats the quote. Since there are an odd number of " in there, the first one would set it would look like this:

    string myString = "\" <- Thats the quote";
    nextline.programming = still.red;
    etc,etc
    until I hit another "


    So, I thought I'd be smooth and say, OK, don't turn off the quote mode if this quote is proceeded by a \. Well, that fixed 90% of the problem, but now I have another problem.

    This is a valid string in C#:

    string myPath = "C:\\Documents and Settings\\Administrator\\";

    So, when the parser hits that last quote, it's now being ignored because the \ is in front of it.

    Any suggestions?

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  5. #5
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Help me speed this up...

    Instead of looking back, I say when you hit a \ inside of a quote, note it. It always indicates that an escape is coming. So you automatically know the next char is escaped and you can ignore it for rules, so something like this:
    VB Code:
    1. if (inQuote)
    2. {
    3.   if (currentChar == "\\" && blnCurrEscape ==false)
    4.   {
    5.     blnCurrEscape = true;
    6.   }
    7.   elseif (blnCurrEscape==true)
    8.   {
    9.     blnCurrEscape = false;
    10.   }
    11.   else
    12.   {
    13.      //Normal processing
    14.   }
    15. }

  6. #6

    Thread Starter
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Help me speed this up...

    Man, this crap's always harder than it looks. Damned C# Flexibility. Now I need to handle the @ symbol somehow too. Because, this is also a legal string..

    string bill = @"\Bill\";

    I guess if the @ character is seen, I can just go by the straight quotes, ignoring the escape characters (because in C# the escape \" isn't valid when you have the @ in front of it..)

    Sweet, so it looks like I'm done with this part of the deal, unless you can think of another way to break it.

    Bill
    Attached Files Attached Files
    Last edited by conipto; Nov 19th, 2005 at 10:18 PM.
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width