Home
Manage Your Code
Snippet: center align every form (C#)
Title: center align every form Language: C#
Description: Make Every form center aligned according to the display resolution Views: 149
Author: raheel farooq Date Added: 4/2/2008
Copy Code  
1
2//Get the Width and Height (resolution) of the screen

3System.Windows.Forms.Screen src = System.Windows.Forms.Screen.PrimaryScreen;
4
5int src_height = src.Bounds.Height;
6int src_width = src.Bounds.Width;
7
8//put the form in the center

9this.Left = (src_width - this.Width) / 2;
10this.Top = (src_height - this.Height) / 2;
Notes
Simply paste the above code @ start of the "form's load event".