2013-09-01 47 views
1

我嘗試在C#(WinForms)中每次在同一位置打開新窗口。 嘗試使用此代碼:窗口中StartPosition =手動打開後新窗口的位置

但結果

private void Notification_Load(object sender, EventArgs e) 
{ 
    Rectangle screenSize = Screen.PrimaryScreen.Bounds; //get resolution of screen 
    int x = screenSize.Height -115-30; //x coordinate = resolution of screen - window Height - 30 (for taskbar) 
    int y = screenSize.Width - 345; //y coordinate = resolution of screen - window Weight 
    this.SetDisplayRectLocation(x, y); //new coordinates for form 
} 

特性 - 有我總是在窗口左上角打開。

嘗試爲x和y設置不同的值 - 結果相同。

我做錯了什麼?

+2

你爲什麼不設置'this.Left'和'this.Top'的值? – iabbott

+0

爲什麼你的'x = Height'和'y = Width'? – Fabio

回答

3

我希望這有助於

int x = Screen.PrimaryScreen.WorkingArea.Top; 
int y = Screen.PrimaryScreen.WorkingArea.Left; 
this.Location = new Point(x, y); 
+0

'Rectangle screenSize = Screen.PrimaryScreen.Bounds; int x = Screen.PrimaryScreen.WorkingArea.Right - this.Right; int y = Screen.PrimaryScreen.WorkingArea.Bottom - this.Bottom; this.Location = new Point(x,y);' - ok – gbk

1

Ť ry this:

this.Location=new Point(x,y);