0

VB.NET / Win forms / VS 2008

I'm working on some software and I'm very happy with the UI design so far.. very structured and easy to read.. but when I resize the window, it's extremely "laggy". When I watch task manager, CPU spikes to 25% (utilizing 100% of a core) when resizing the window (0% when not being resized). It's redrawing the window at something like 4 frames per second, if that.

It's a fairly complex UI, but nothing crazy by any means. I don't feel like it should be running like this.

My layout heirarchy looks something like this:

<FORM>
    <TABCONTROL> (first tab example, subsequent tabs follow the same control hierarchy)
        <SPLITCONTAINER>
            <PANEL 1>
                <DATAGRIDVIEW />
            </PANEL 1>
            <PANEL 2>
                <TABCONTROL>
                    <TABCONTROL>
                        <TABCONTROL>
                            Lots of data fields in these tabs
                        </TABCONTROL>
                    </TABCONTROL>
                </TABCONTROL>
            </PANEL 2>
        </SPLITCONTAINER>
    </TABCONTROL>
</FORM>

Everything is docked to its parent. It's all very fluid. So the splitters are docked (fill mode) in the main tabs, the tabcontrols are docked (fill mode) within other tabcontrols, etc.

I think it's just putting a large load on the system trying to recalculate positions of controls when the window is resized.

Any suggestions as to what I could do about this short of completely redesigning the software?

cowsay
  • 1,282
  • 1
  • 15
  • 36
  • are you handling any resize events or any events? if yes, please post the enent handling vb.net code – Dhawalk Jan 15 '13 at 19:50
  • @Dhawalk no none at all. – cowsay Jan 15 '13 at 19:53
  • 1
    Unfortunately, this is normal for WinForms apps, but, this should help: [Suspend / Resume Layout](http://stackoverflow.com/questions/2353381/prevent-window-redraw-when-resizing-c-sharp-windows-forms) – xfx Jan 15 '13 at 19:55
  • If you have a lot of information in the DataGridView, and have columns and rows autosized, it may take a lot of resources when resizing. – B L Jan 15 '13 at 19:55
  • If you are going to redesign I would do so in WPF. – paparazzo Jan 15 '13 at 19:55
  • @xfx that will do the trick, thanks very much. Not the optimal solution but I really don't know if there's much else I can do. Want to post that as an answer so I can mark it solved? – cowsay Jan 15 '13 at 20:04

1 Answers1

1

Unfortunately, this is normal for WinForms apps, specially those with lots of nested containers.

But, there is a "workaround" which involves invoking Suspend and Resume Layout when the Form is about to be resized and after it has been resized:

Prevent window redraw when resizing c# windows forms

Community
  • 1
  • 1
xfx
  • 1,329
  • 8
  • 18