-1

I have a form that is a child of an MDI form. When this form isn't maximized, it fits inside of the MDI form, below several menu panels and controls. It has a border, icon, and controlbox. When the form is maximized, the border shows directly underneath the main MDI form border. When it is maximized, the controlbox is disabled and we don't need the border for any reason- it just looks sloppy. The form is resized programmatically so there is never a need for the border/controls when it is maximized.

Is there a way to set the FormBorderStyle = None, ONLY when the form is maximized, and have FormBorderStyle = sizeable when it is any size other than Max?

See screenshots below, The red line is on the border that I want hidden- the area marked toolstrip controls is above the form, not actually on it. The white space marked picture box is the actual form that has the border. When not maximized, it the border will show directly above the picture box area and below the toolstrip area, and can be resized by the user. When maximized, the user cannot resize it, so I want to hide that border as it looks sloppy below the main form border

When Not maximized: [1]: https://i.stack.imgur.com/TFDjk.png

When Maximized: https://i.stack.imgur.com/EK4cY.png

  • a child form doesn't have border when maximized, it fills all client area and usually share its menu with parent form. can share a pic of your form maximized? – McNets Nov 03 '16 at 19:34
  • https://i.stack.imgur.com/EK4cY.png – Brook Ballard Nov 03 '16 at 19:45
  • do you mean the raised border? – McNets Nov 03 '16 at 19:48
  • Yes, I also added a screenshot showing how it appears when not maximized – Brook Ballard Nov 03 '16 at 19:51
  • The red line is on the border that I want hidden- the area marked toolstrip controls is above the form, not actually on it. The white space marked picture box is the actual form that has the border. When not maximized, it the border will show directly above the picture box area and below the toolstrip area, and can be resized by the user. When maximized, the user cannot resize it, so I want to hide that border as it looks sloppy below the main form border. – Brook Ballard Nov 03 '16 at 19:53
  • @BrookBallard You should [edit] that last comment into the question itself so people reading it for the first time don't have to look into the comments for all the info. – Ajean Nov 03 '16 at 20:45
  • I've found a solution, but it's a little bit complicated. http://stackoverflow.com/questions/7752696/how-to-remove-3d-border-sunken-from-mdiclient-component-in-mdi-parent-form – McNets Nov 03 '16 at 22:28
  • @mcNets Thanks! that is a start... now things get a bit tricky- we have functionality where we open up multiple child forms and show them tiled in the main form.. this is when I need to form borders to come back... calling setBevel(true) during that event doesn't seem to work, unless I'm missing something. any ideas? – Brook Ballard Nov 03 '16 at 23:01
  • @BrookBallard for my mdi apps I use a 3rd party components, Infragistics TabbedMdiManager, http://www.infragistics.com/products/windows-forms/layouts/tabbed-mdi This controls give me all the functionality I need. – McNets Nov 03 '16 at 23:53
  • @BrookBallard I just added a new answer because you said that setBevel(true) doesn't works, I built a small project with this code and it works fine for me. Why do you need borders back when you tile mdi forms? – McNets Nov 04 '16 at 09:17

2 Answers2

1

I've wrote this code according to others posts I've found in stackoverflow and googling.

I've tested it, and it works.

[DllImport("user32.dll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

[DllImport("user32.dll", ExactSpelling = true)]
private static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

const int GWL_EXSTYLE = -20;
const int WS_EX_CLIENTEDGE = 0x200;
const uint SWP_NOSIZE = 0x0001;
const uint SWP_NOMOVE = 0x0002;
const uint SWP_NOZORDER = 0x0004;
const uint SWP_NOACTIVATE = 0x0010;
const uint SWP_FRAMECHANGED = 0x0020;
const uint SWP_NOOWNERZORDER = 0x0200;

private void MdiEdgeBorderOnOff(bool off)
{
    foreach(Control ctl in this.Controls)
    {
        if (ctl.GetType() != typeof(MdiClient)) continue;

        int wnd = GetWindowLong(ctl.Handle, GWL_EXSTYLE);
        if (off)
            wnd &= ~WS_EX_CLIENTEDGE;
        else
            wnd |= WS_EX_CLIENTEDGE;

        SetWindowLong(ctl.Handle, GWL_EXSTYLE, wnd);

        SetWindowPos(ctl.Handle, IntPtr.Zero, 0, 0, 0, 0,
            SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
            SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
    }
}
McNets
  • 10,352
  • 3
  • 32
  • 61
0

It is a child form hence it cannot maximize the parent form. Can you please share more details to further assist you? Maybe share a screenshot?

SmartDeveloper
  • 58
  • 2
  • 13
  • The red line is on the border that I want hidden- the area marked toolstrip controls is above the form, not actually on it. The white space marked picture box is the actual form that has the border. When not maximized, it the border will show directly above the picture box area and below the toolstrip area, and can be resized by the user. When maximized, the user cannot resize it, so I want to hide that border as it looks sloppy below the main form border. – Brook Ballard Nov 03 '16 at 19:47