2010年7月16日 星期五

視窗顯示於螢幕中央的方法

將Form 顯示於螢幕中央的方法:

1.

MainForm mainForm = new MainForm();

mainForm.StartPosition = FormStartPosition.CenterScreen;

2.

mainForm.StartPosition = FormStartPosition.Manual;

mainForm.Left = (Screen.PrimaryScreen.Bounds.Width - mainForm.Width) / 2;


mainForm.Top = (Screen.PrimaryScreen.Bounds.Height - this.Height) / 2;

3.

mainForm.StartPosition = FormStartPosition.Manual;

mainForm.Left = (SystemInformation.PrimaryMonitorSize.Width - mainForm.Width) / 2;

mainForm.Top = (SystemInformation.PrimaryMonitorSize.Height - this.Height) / 2;

4.

mainForm.StartPosition = FormStartPosition.Manual;
int left== (Screen.PrimaryScreen.Bounds.Width - mainForm.Width) / 2;

int.top = (Screen.PrimaryScreen.Bounds.Height - this.Height) / 2;

mainForm.Location = new Point(left,top);

沒有留言:

張貼留言