Results 1 to 15 of 15

Thread: RichTextBox slow to resize

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    RichTextBox slow to resize

    I have a RichTextBox on a form.

    Anchor set to all 4 sides so when the form is resized the RTB resizes as well.

    All works fine but if the RTB contains a lot (ie >20meg) of text then there is a long delay if the form is resized. For example dragging the side of the form pretty much locks up the form for a few seconds.

    I think the problem is that the RTB wants to do a redraw of it's contents which takes ages.

    I tried setting the RTB Anchor back to default (top and left) and that obviously allows the form to be dragged/sized smoothly and then on the Form ResizeEdnded event I could size the RTB. But that doesn't help either. Still a few seconds delay till the RTB redraws itself.

    Anyone got any ideas ?

    Thanks
    Ian

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: RichTextBox slow to resize

    Mais yeah it's going to take a few seconds for the control to redraw itself. If you plan on having a ton of data, why not do all the resizing yourself rather than letting the compiler do it for you?

    Edit - Something like this:

    Code:
        Private beginning As Size
        Private Sub Form1_ResizeBegin(sender As System.Object, e As System.EventArgs) Handles MyBase.ResizeBegin
            beginning = Me.Size
        End Sub
    
        Private ending As Size
        Private Sub Form1_ResizeEnd(sender As System.Object, e As System.EventArgs) Handles MyBase.ResizeEnd
            ending = Me.Size
            Dim difference As Size = ending - beginning
    
            RichTextBox1.Size = RichTextBox1.Size + difference
        End Sub
    Last edited by dday9; Nov 14th, 2013 at 03:32 PM.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: RichTextBox slow to resize

    Thanks. I already try that. I just didnt explain well in my first post. Changing the size, even programatically, causes a redraw which locks it up for a few seconds.

    Quote Originally Posted by IanS View Post

    .................. and then on the Form ResizeEdnded event I could size the RTB. But that doesn't help either.

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: RichTextBox slow to resize

    Ah, my bad. My old teachers always told me I should've paid more attention. I'm not to sure then if you've already tried what I suggested. Sorry.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  5. #5
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: RichTextBox slow to resize

    Before we go on why would you hold 20mb of data in a rtb :? if a 3million line txt file holds around 3.+ mb of data there is no reason to do such a stupid task. UI controls are there to view.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: RichTextBox slow to resize

    Quote Originally Posted by ident View Post
    Before we go on why would you hold 20mb of data in a rtb
    Sorry, i dont know how to answer that question. Cant you assume that i do? So please. Do go on.

  7. #7
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: RichTextBox slow to resize

    Controls are UI elements. They are viewed as such. Why would some One sit there and view 18 million lines of text(give or take) inside a rich text box? They would not.

    If you can't give me a reason then whats the point?

  8. #8
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: RichTextBox slow to resize

    Quote Originally Posted by ident View Post
    Before we go on why would you hold 20mb of data in a rtb :? if a 3million line txt file holds around 3.+ mb of data there is no reason to do such a stupid task. UI controls are there to view.
    Not at all, if each line was only 1000 characters, then it would hold a mere 20,000 lines of data. This could be a small log file or the like, I have logs that run into 100s of megs so build a custom log file viewer to avoid these types of situations.

    You could possibly use a multi-line textbox for this small amount of data. There are methods to force a control to stop drawing itself, so this might be at the start of a move, and then redraw at the end, but do not know how effective this would be on the rtb. Also .ResizeRedraw exists as a property that I have never seen before.
    Last edited by Grimfort; Nov 14th, 2013 at 05:03 PM.

  9. #9
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: RichTextBox slow to resize

    a 1k line @ 20k lines is still still around 3mb, so you seriously telling me you would load another 6 times this and read it? Or load portions when or if needed.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: RichTextBox slow to resize

    Quote Originally Posted by Grimfort View Post
    Not at all, if each line was only 1000 characters, then it would hold a mere 20,000 lines of data. This could be a small log file or the like, I have logs that run into 100s of megs so build a custom log file viewer to avoid these types of situations. You could possibly use a multi-line textbox for this small amount of data.
    Thank you.

    My current solution uses a richtextbox. I use highlighting to pick out certain events. Works perfectly on files much bigger than 20 meg. In the old vb6 days i used to use paging to hold smaller amounts of data but now by classing RICHEDIT50W instead of the default RICHEDIT20W on which the .net rtb is based, i can load the whole thing and syntax highlight smoothly in the background. I currently lock the size of the textbox so it all works fine.

    But, purely for cosmetic reasons. I'd like to size the textbox in relation to the form size. I dont need to. But it would be nice if i could.

  11. #11
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: RichTextBox slow to resize

    Quote Originally Posted by ident View Post
    a 1k line @ 20k lines is still still around 3mb, so you seriously telling me you would load another 6 times this and read it? Or load portions when or if needed.
    You sure, 3mb of 20k lines would only be 150 characters.

    Obviously paging would help in such a situation, but if it can be easily avoided then why not, maybe the OP would eventually have to go this way, guess we have to wait and see.
    Last edited by Grimfort; Nov 14th, 2013 at 05:17 PM.

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: RichTextBox slow to resize

    Quote Originally Posted by ident View Post
    a 1k line @ 20k lines is still still around 3mb, so you seriously telling me you would load another 6 times this and read it? Or load portions when or if needed.
    Perhaps in your world of UI where a human creates and edits everything it doesnt quite make sense. But not everyone works in your world.

    It's a montion control program sending instructions to a bunch of robots on an assembly line. The program runs for 24 hours and a meg or more per hour of runtime is quite normal. The program is generated by a compiler and you're right. No human would ever sit and read or write the whole thing. But a human might load it search for some event, scroll to it and edit a specific line is quite normal.

    While the program is running it's simply scrolling up the display with certain keywords highlifhted allowing an operator to see, at a glance, what the robots are doing at any one time.

    In the old days of vb6 i'd break it into pages. One page per hour. But the rtb can load the whole thing. If it can load the whole thing why shouldnt I. I can lock the size of the box and it works fine. But, for cosmetic reasons id like the box to size if the user increases the size of the form. if i can overcome this one hurdle i can throw away the code that handles the paging.

    Is that enough information? Now do you ha e a solution?

  13. #13
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: RichTextBox slow to resize

    Quote Originally Posted by IanS View Post
    Perhaps in your world of UI where a human creates and edits everything it doesnt quite make sense. But not everyone works in your world.
    If you want to get rude about it then i wont sleep any less not posting. I cant see why posting to a control when running with out interaction for 24 hours is logical.
    Don't use controls for variables. Each control requires a window handle, GDI resources, and a message loop.


    any way i don't need to get into it.

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: RichTextBox slow to resize

    I'm sorry if you think i was rude. If we were sat facing each other you would have seen my face and heard my tone of voice and you wouldnt have thought i was rude.

    But if you want to take it that way then theres nothing i can do about it.

    I took the time to explain in some detail what i do in the hope that you have a solution. I guess you dont.

  15. #15
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: RichTextBox slow to resize

    Quote Originally Posted by ident View Post
    I cant see why posting to a control when running with out interaction for 24 hours is logical.
    I believe the OP is using the rtb to view/modify the process instructions for the next 24 hour run, the same way you would edit a word document.

    The actual display when it is running would not need a full view I would think?

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