反正有做到这一点之前,获取表格的位置?在我的理解应该是可以的,但如果我展示的形式之前尝试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