Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restoring WinForm with textbox containing large amount of data

I have created a form in C# (VS2010) which contain (among other) a textbox control. The textbox may contain large amount of data at some point (~3 million chars).

When scrolling or moving the form around no problems are encountered, but when the form is minimized and restored back again, a repaint sequence (I believe) is triggered which causes a big lag of around 5-10 seconds for the form to be repainted.

I've already tried several solutions:

  1. Using double buffer – according to what I've read, double buffering applies only to the form itself and not to its controls

    this.SetStyle(ControlStyles.DoubleBuffer, true); this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.UserPaint, true);

  2. Disabling the textbox redrew once minimized using: SendMessage(this.my_textBox.Handle, WM_SETREDRAW, false, 0); and enabling back after form is restored. I've noticed that the form repaint lag exist also if I don't re-enable the textbox repaint.

  3. Manual double buffer using a bitmap – similar results as #1.

I read somewhere that this issue might be related to the textbox control trying to shrink or adjust to the amount of data, but couldn't override it.

I previously had the same project in MFC, but didn't encounter any repaint or lagging issues there.

Please advise me how to solve this issue.

like image 219
zulfin Avatar asked Jan 02 '13 19:01

zulfin


1 Answers

Found the problem!!! Issue was related to the textbox Anchor property. once i removed it, window restore was immediate. BTW, the new custom class isn't required

like image 87
zulfin Avatar answered Nov 11 '22 02:11

zulfin