1

I have custom windows form that has no border.I apply that custom form on child form. And I have custom MDIParent Form that has also no border. So, My problem is when I maximise child form then top border of is appear out side of MDIForm so how can manage or solve this issue using c#.See my snapshot for more detail of my problem I want to remove border with maximise button from top of the custom MDIForm.

Hardik
  • 33
  • 7

1 Answers1

-1

I am unsure how you are calling the child Form, but here is an example:

private void Button1_Click(object sender, EventArgs e)
{
    var myForm = new MyCustomForm();
    myForm.MdiParent = this;
    myForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; //this should hide the border even when it is maximized.
    myForm.Show();
}

OR, you can capture the 'maximize' event and override it with your own method which once again makes sure there is no border:

private void MaximizeWindow() 
{
    var rectangle = Screen.FromControl(this).Bounds;
    this.FormBorderStyle = FormBorderStyle.None;
    Size = new Size(rectangle.Width, rectangle.Height);
    Location = new Point(0, 0);
    Rectangle workingRectangle = Screen.PrimaryScreen.WorkingArea;
    this.Size = new Size(workingRectangle.Width, workingRectangle.Height);
}

and to capture the maximize event:

private void Form1_Resize (object sender, EventArgs e)
{
    if (Form1.WindowState == FormWindowState.Maximized)
    {
        // Do some stuff
    }
}

Sources:

-How to show a child form within a mdi container form which its windowstate= maximized?

-Remove the title bar in Windows Forms

Community
  • 1
  • 1
Keyur PATEL
  • 2,299
  • 1
  • 15
  • 41
  • May I ask how you eliminated the borders for the child element? What method did you use, some code snippets would be nice to go on. – Keyur PATEL Sep 14 '16 at 07:42
  • Yes why not, I use this code this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; – Hardik Sep 14 '16 at 07:45
  • The only other thing I can think of is: `this.ControlBox = false;`. Otherwise in the worst case, you can disable maximizing and set a fixed size for your child form. – Keyur PATEL Sep 14 '16 at 07:50