Windows Develop Bookmark and Share   
 index > Windows Forms General > RichTextBox with large text and redraw problem
 

RichTextBox with large text and redraw problem

Hi All,

When i load a large rtf file (1.7 MB) in rich text box, and try to use form resize for resizing the text box, the rtb takes a very long time to redraw. Is there a way to reduce this time? Thanks in advance.



Thanks
Ramses

RSVP
Ramses2  Thursday, September 10, 2009 11:05 AM
        void Form1_Resize(object sender, EventArgs e)
        {
            richTextBox1.Width = this.Width - 30;
            richTextBox1.Height = this.Height - 80;
            this.richTextBox1.Refresh();
        }
the control is taking time to redraw itself because rtf file is huge.. anyway I have observed some bttr performanceon refreshing rtb control on "resize" event.
Paras
paras kumar  Tuesday, September 15, 2009 12:41 PM
Hi Ramses,
Can you pleasenshare the code because for me rtb is not taking long time to redraw.
The rtf file i have used is around 4.5 Mb.

Here is the code I have tried:

public Form1()

{

InitializeComponent();

richTextBox1.LoadFile(

@"C:\Users\parask\Desktop\paras.rtf");

}

private void button1_Click(object sender, EventArgs e)

{

richTextBox1.Height = richTextBox1.Height * 2;

richTextBox1.Width = richTextBox1.Width * 2;

}

paras kumar  Thursday, September 10, 2009 11:40 AM
Hi Paras,

Do this -

Remove the LoadFile call from Form1() constructor.



And changed the button1 click as follows

privatevoidbutton1_Click(objectsender,EventArgse)

{

richTextBox1.LoadFile(

@"C:\Users\parask\Desktop\paras.rtf");

}

Now add a Form1 resize event handler and put your button related code inside the Form1 resize handler

private void Form1_Resize(objectsender,EventArgse)

{

richTextBox1.Height = richTextBox1.Height * 2;

richTextBox1.Width = richTextBox1.Width * 2;


}

Now try to resize the form, by either extending its height or width and then let me know the results.

Thanks

Ramses


RSVP
  • Edited byRamses2 Friday, September 11, 2009 12:11 PMAdded more infor
  •  
Ramses2  Friday, September 11, 2009 12:10 PM
dont use resize event handler. use ResizeEnd, it'll work fine.

- Paras
  • Unproposed As Answer byRamses2 Tuesday, September 15, 2009 6:33 AM
  • Proposed As Answer byparas kumar Friday, September 11, 2009 5:27 PM
  •  
paras kumar  Friday, September 11, 2009 5:27 PM
Hi Paras,


I tried your suggestion, it slightly improved the situation, but the issue still remains. Its still taking a long time to redraw all the text, especially when the text is unicode and has different formatting features like bold etc enabled.




Thanks
Ramses

RSVP
Ramses2  Tuesday, September 15, 2009 6:36 AM
Can you zip and send me your project to insigniya@gmail.com.


Paras
paras kumar  Tuesday, September 15, 2009 8:12 AM
Sent to you mail
RSVP
Ramses2  Tuesday, September 15, 2009 10:29 AM
        void Form1_Resize(object sender, EventArgs e)
        {
            richTextBox1.Width = this.Width - 30;
            richTextBox1.Height = this.Height - 80;
            this.richTextBox1.Refresh();
        }
the control is taking time to redraw itself because rtf file is huge.. anyway I have observed some bttr performanceon refreshing rtb control on "resize" event.
Paras
paras kumar  Tuesday, September 15, 2009 12:41 PM

You can use google to search for other answers

Custom Search

More Threads

• HELP!DoDragDrop And DoubleClick Event
• VS 2005 IDE Crash
• Problem creating dynamic reports
• scrollbars.
• Which comes first, mouse capture or focus event?
• Problem with comboBoxColumn in a Form_Load even handler
• Error creating window handle
• open a web page
• Replicating VISIO Functionality (IMPORTANT)
• How Could I Get the coordinates of the upper-Right corner of the control