c# form center code example

Example 1: c# center windows form

// Do not call CenterToScreen() directly from your code. Instead,
	// Use somthing like this

	//-- After InitializeComponent()
	InitializeComponent();

	//-- Center Screen - Multi Monitor Support
	Rectangle workingArea = Screen.FromControl(this).WorkingArea;
	this.Location = new Point()
    {
      X = Math.Max(workingArea.X, workingArea.X + (workingArea.Width - this.Width) / 2),
      Y = Math.Max(workingArea.Y, workingArea.Y + (workingArea.Height - this.Height) / 2)
    };

Example 2: how to align a form in the center c# forms

protected void CenterToScreen ();

Tags:

Html Example