2

When I scroll through the text of my rich text box, it doest scroll fast and smoothly. It works perfectly fine for files of size up to 1 MB, but it gets very slow if I use file in the range of 10MB. The richtextbox I am using is on the form named subform. I am doing subform.TopLevel = false and putting inside a panel on Mainform. From Mainform using object of Subform I am calling subform.richtextbox.Loadfile(filepath).

If I directly run the Subform and load file like this.richtextbox.Loadfile(filepath), the scrolling is working perfectly fine for same file.

Please note , the loading of file itself takes much time, which is not a concern for me right now. I will look into that, once I solve this issue. I want my scroll and all UI operation to work like it works in Notepad and Notepad++ without freezing.

I have pasted the final UI, that I have created

// Subform Code

public SubForm(Form form)
    {
        mainform = form as MainForm;
        InitializeComponent();


        public MyRichTextBox richtextbox;
    }

// MainForm code

public partial class MainForm : Form
{
private void MainForm_Load(object sender, EventArgs e)
       {


        dumpsysform = new SubForm(this);
        dumpsysform.TopLevel = false;
        dumpsysform.Text = "DumpsysLog";

        kernelform = new SubForm(this);
        kernelform.TopLevel = false;
        kernelform.Text = "KernelLog";
        this.panel3.Controls.Add(adbform);
        this.panel3.Controls.Add(dumpsysform);
        this.panel3.Controls.Add(kernelform);

        dumpsysform.Location = new Point(0, panel3.Height / 3);
        kernelform.Location = new Point(0,2* panel3.Height / 3);


        adbform.Show();
        dumpsysform.Show();
        kernelform.Show();   

    }
    // Button to open file and read
    private void btn_click(object sender, EventArgs e)
    {
        dumpsysform.richtextbox.richtextbox1.LoadFile(dumpsysfilepath,
                                         RichTextBoxStreamType.PlainText);
        kernelform.richtextbox.richtextbox1.LoadFile(kernelfilepath,
                                         RichTextBoxStreamType.PlainText);
    }

}

Badro Niaimi
  • 959
  • 1
  • 14
  • 28
bipin nitp
  • 29
  • 4
  • Please post full code samples if you want any reply. We can't help you at all without them. https://stackoverflow.com/help/minimal-reproducible-example – Hogan Nov 21 '19 at 16:41
  • Try breaking down the problem. You can write a bare-bones application to load a file into a RTB in a couple/few dozens lines of code. If that produces the same issue, it's a problem in the framework or on your system. If not, it's a problem with your application. – Michael Gunter Nov 21 '19 at 16:47
  • The question needs example otherwise it will lead to too generic discussion. Also there are already similar topics on SO - https://stackoverflow.com/questions/31214687/in-c-loading-large-file-into-winform-richtextbox - please try to search on the site at first and create question only if you don't find it discussed yet. – mybrave Nov 21 '19 at 16:49
  • Make a UserControl instead of using a Form. UserControls also have a designer. Then, what happens is up to your code. What event you're handling or generating. If you're applying formatting, Font styles, colors etc. to text selections, the overall performance is directly proportional to the length of the text and the quality of the code. – Jimi Nov 21 '19 at 18:35
  • @Jimi , I am using form inside form so that I could have flexibility to use minimize, maximize, resize,drag, options available to me without writing own implementation of these. – bipin nitp Nov 22 '19 at 11:36
  • @MichaelGunter , Like I mentioned , if I am directly calling subform using Application.Run(new SubForm()); , the UI is working faster in terms of scrolling through the text, but still resizing the form is extremely slow. – bipin nitp Nov 22 '19 at 11:42
  • Are you re-inventing [Multiple-Document Interface (MDI)](https://learn.microsoft.com/en-us/dotnet/framework/winforms/advanced/multiple-document-interface-mdi-applications)? I hope you're not actually using `Application.Run()` to create those Forms. – Jimi Nov 22 '19 at 17:44

0 Answers0