Search code examples
c#winformsdocking

Top-docking controls more than 32768 pixels


I have a WinForms application that allows you to edit documents. Each document is made of chapters and each chapter holds a collection of RTF blocks. The RTF blocks are loaded in a PanelControl using Dock = DockStyle.Top.

The problem is that when the total height of a chapter gets too large (estimating > 32768 pixels) the lower blocks are not properly docked: they appear behind one another. When trying to isolate the problem I noticed that this also happens with simpler controls like a LabelControl.

Things I tried are methods like Refresh(), Invalidate() and PerformLayout: they will not resolve the issue.

What does help is resizing the form. After that all controls are laid out correctly.

Can anyone help on how to solve this without resizing the form?

Attached a simple demo-project that illustrates the problem.

screenshot


Solution

  • From my comment above (seems really to be the problem here):

    WinForms (and the GDI in general) is often behaving unpredictably if one tries to use coordinates outside a 16 bit range. Try to avoid that. In the range of possible problems are things just not getting drawn at all, OverflowExceptions at unexpected code positions etc.