How to prevent controls visually lagging behind on resize inside TableLayoutPanel?

后端 未结 3 1667
囚心锁ツ
囚心锁ツ 2021-01-23 10:41

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 la

相关标签:
3条回答
  • 2021-01-23 10:54

    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.

    0 讨论(0)
  • Set DoubleBuffered = true. You can set it on the forms.

    0 讨论(0)
  • 2021-01-23 11:05

    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...

    0 讨论(0)
提交回复
热议问题