Wednesday, August 24, 2016

how to minimize and maximize windows form in asp.net



Form.WindowState Property
public FormWindowState WindowState { get; set; }
For example -
var form = new Form();
form.WindowState = FormWindowState.Maximized;
form.WindowState = FormWindowState.Minimized;
form.WindowState = FormWindowState.Normal;
However, if you are in the code behind on the main form (or any form) just do this -
WindowState = FormWindowState.Maximized;
VB.NET
Private Sub btnCenter_Click(ByVal sender As ObjectByVal e As EventArgs)
       Dim boundWidth As Integer = Screen.PrimaryScreen.Bounds.Width
       Dim boundHeight As Integer = Screen.PrimaryScreen.Bounds.Height
       Dim x As Integer = boundWidth - Me.Width
       Dim y As Integer = boundHeight - Me.Height
       Me.Location = New Point(x / 2, y / 2)
End Sub
The Screen.PrimaryScreen.Bounds gets the bounds of the display screen. The width and height of the display is subtracted with the width and height of the form. Once we get this calculated value, set the location by passing the value to Point().
 
Maximize the Form
 
Step 1: Drag and drop a button on the form. Rename it to btnMax
Step 2:  On the click event, write the following code :
C#
 private void btnMax_Click(object sender, EventArgs e)
{
      this.WindowState = FormWindowState.Maximized;
}
VB.NET
Private Sub btnMax_Click(ByVal sender As ObjectByVal e As EventArgs)
Me.WindowState = FormWindowState.Maximized
End Sub

No comments:

Post a Comment