C# - How to open form in full screen

This example shows how to make open windows form full screen of computer.

In this example, i will use F11 as a shortcut key to turn form to full screen.

Step By Step :

  1. Create one windows form project
  2. Add Form 2 in the solution.
  3. Add method to event Key Up in Form 1
  4. Copy code below in Key Up  event method Form 1

The Code

private bool _bFullScreenMode = false;

:
:
:

private void Form1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
if ( e.KeyData == Keys.F11)
{
if (_bFullScreenMode == false)
{
Form2 f = new Form2();
this.Owner = f;
this.FormBorderStyle = FormBorderStyle.None;
this.Left = (Screen.PrimaryScreen.Bounds.Width/2 - this.Width/2);
this.Top = (Screen.PrimaryScreen.Bounds.Height/2 - this.Height/2);
f.Show();
_bFullScreenMode = true;
f.KeyUp +=new KeyEventHandler(Form1_KeyUp);
}
else
{
Form f = this.Owner;
this.Owner = null;
f.Close();
this.FormBorderStyle = FormBorderStyle.Sizable;
}
}
}

By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

Popular posts from this blog

Example to disable save as certain file type in SSRS Report Viewer

How to create DataGrid or GridView in JSP - Servlet

Control Webpart Visible/Enable using macro in Kentico