反正有做到這一點之前,獲取表格的位置?在我的理解應該是可以的,但如果我展示的形式之前嘗試myForm.Location
我得到(0, 0)
。Winform的:顯示(StartupPosition爲中心屏幕)
謝謝!
反正有做到這一點之前,獲取表格的位置?在我的理解應該是可以的,但如果我展示的形式之前嘗試myForm.Location
我得到(0, 0)
。Winform的:顯示(StartupPosition爲中心屏幕)
謝謝!
知道表單的位置,最好的辦法是決定你想要和把它放在那裏。
Form formDemo = new DemoForm();
formDemo.Location = new Point(20, 30);
formDemo.Show(); //or formDemo.ShowDialog();
後@Diego澄清了他的問題,我相信這將做什麼是需要:
int ScreenWidth = Screen.PrimaryScreen.WorkingArea.Width;
int ScreenHeight = Screen.PrimaryScreen.WorkingArea.Height;
int formTop = (ScreenHeight/2) - (formDemo.Height/2);
int formLeft = (ScreenWidth/2) - (formDemo.Width/2);
我覺得技術上繪製之前,你沒有一個位置。我個人不知道如何將「System.Windows.Forms.FormStartPosition」枚舉轉換爲Point。
不過你想要的東西,它應該是很簡單的。我將顯示第一種形式,然後將其傳遞給第二種形式,您可以將其設置爲啓動邏輯,以便將其用於定位。像這樣。
public Form1()
{
InitializeComponent();
StartPosition = FormStartPosition.CenterScreen;
this.Shown += new EventHandler(Form1_Shown);
}
void Form1_Shown(object sender, EventArgs e)
{
ShowForm2(this.Bounds);
}
public void ShowForm2(Rectangle ParentBounds)
{
Form2 f = new Form2();
int x = ParentBounds.Right+2;
int y = ParentBounds.Y + (ParentBounds.Height/2) - (f.Height/2);
Point childStartPosition = new Point(x,y);
f.StartPosition = FormStartPosition.Manual;
f.Location = childStartPosition;
f.Show();
}
你需要什麼信息呢? – Bernard 2011-06-16 20:43:30
儘管這種形式示出了作爲一個模態對話框('ShowDialog'),顯示它之前,我需要顯示,這將根據這形成位置被定位其它形式。 – Diego 2011-06-16 20:46:17