Placing or Setting a Form to screen or windows Center

vishalneeraj-24503
Posted by vishalneeraj-24503 under Windows Forms category on | Points: 40 | Views : 530
Divide the screen in Half and find the center,then put the center of the form there.
By using Screen.PrimaryScreen.WorkingArea ,we can get Screen Height and Width .

IN VB.Net
Imports System.Drawing
Dim rect As Rectangle = Screen.PrimaryScreen.WorkingArea
Me.Top = (rect.Height / 2) - (Me.Height / 2)
Me.Left = (rect.Width / 2) - (Me.Width / 2)


//In C#
using System.Drawing;
Rectangle rect = Screen.PrimaryScreen.WorkingArea;
this.Top = (rect.Height / 2) - (this.Height / 2);
this.Left = (rect.Width / 2) - (this.Width / 2);

Comments or Responses

Login to post response