views:

338

answers:

2

I have a layout of medium complexity based on several nested TableLayoutPanels. Resizing the form causes the controls inside the deeper nested tables to visually lag behind the resize. Firstly, this makes them look like they move around while the form is being resized, but worse, the edges of the controls are visibly clipped when they lag enough to leave their allocated table cells.

Is there any way to prevent this or is this the best TableLayoutPanel can do?

Edit: Having experimented with a bunch of programs I came to the conclusion that lag on resize is a ubiquitous problem. To me, it seems that everyone has resigned that this is inevitable and acceptable. Of course if it's actually inevitable then accepting this is that much easier :)

The easiest way to see the lag in your favourite "good UI" program: resize it by holding the left boundary and watch all right-aligned controls jump around (or alternatively, top boundary & bottom-aligned controls, like statusbars). It's broken all around.

If anyone could provide good reasons why this is inevitable when using native windows controls I will accept that answer. Also, if you find a program using native controls that doesn't suffer this please say so, this could help...

+1  A: 

The problem with native controls in windows is that each control is responsible for drawing itself which means painting a bitmap to the screen. As each control in a container control is resized the region of the window it occupies becomes invalidated so not only does each control in the container repaint, the container itself must repaint. Also, the resize/repaint events are all occuring on the UI thread so it's a single threaded operation. The basic mechanisms behind native window drawing haven't changed since 16 bit windows introduced it.

There are many tricks(hacks) that people employ to try and get around the problem, things like double buffering, off screen rendering, or simply disabling resizing.

To see how it should be, look at WPF. MS developed it as a means of solving this problem.

If WPF isn't an option and you are using windows forms check out the layout related documentation from microsoft. You can implement your own layout engine as opposed to relying on the out of the box microsoft offerings.

Joe Caffeine
I tried this same thing in WPF and, amazingly, the VERY SAME problem exists :) Try it - create a bottom-right aligned button and resize the form by the top left corner.
romkyns
A: 

This doesn't seem to be possible at all, including WPF (which is actually even worse - see this question). Qt can avoid such lag, except if Aero is enabled. Sigh...

romkyns