0
votes

I am working on a project with MDI forms. My problem is when I open an MDI child borderless form. For a moment I see this...

enter image description here

and then appears to be OK...

enter image description here

Any idea what can cause this? Note that title bar and bottom bar is custom controls. FormBorderStyle is none!!!

1
I would really like to know why my question has downvoted???Simonetos The Greek

1 Answers

1
votes

Windows doesn't actually support changing the border style for MDI child windows. The operating system lets you do it, but it is an unsupported configuration and quite likely to be buggy.

WinForms is supposed to insulate you from these types of concerns, so this is really a design flaw. It should be throwing an exception when you try to modify the FormBorderStyle property of an MDI child. Implementing MDI support probably wasn't Microsoft's biggest priority. It was essentially dead even when WinForms was first released way back in 2001-ish. The entire MDI paradigm is no longer supported, and no longer recommended for use in software.

As you've seen, you can hack it so that it kind of works. But you get this flickering effect because Windows is trying to draw the non-client area that is supposed to be there.

Two better ideas:

  1. Stop using the obsolete MDI paradigm and find a different, more user-friendly way to implement your UI. For example, separate, top-level forms. Or a series of tabs.

  2. Stop using ugly custom "skins" that break with the operating system's standard visual appearance, cannot be customized or disabled by the user, and tend to be buggy.

If you absolutely have to do this, and want to make it look good, then you will essentially have to re-implement the MDI paradigm yourself. Create a standard form that will serve as your de-facto parent. Then, instead of using MDI child forms, you will use a series of UserControl classes (or a Form with its TopLevel property set to False). Then you can remove the system-drawn border, allowing you to draw everything yourself. The UserControl objects will then be displayed as children of the "main" form, just like any other control would be. So far, so good. Now, the ugly part is that you'll be responsible for managing these children yourself: showing them when necessary, hiding them when necessary, allowing the user to drag them around within the "main" form, logic for "maximizing" and "minimizing" them, etc. You'll have to write your own code to do that. I strongly recommend against it; getting this type of thing right is going to be rather difficult and of dubious value once you get finished.