第一种方法:
private void Form1_Load(object sender, EventArgs e)
{
this.Location = new System.Drawing.Point(100,100);
}
{
this.Location = new System.Drawing.Point(100,100);
}
第二种方法:
private void Form1_Load(object sender, EventArgs e)
{
this.Left = 100;
this.Top = 100;
}
{
this.Left = 100;
this.Top = 100;
}
第三种方法:
private void Form1_Load(object sender, EventArgs e)
{
SetDesktopLocation(100, 100);
}
{
SetDesktopLocation(100, 100);
}
对于winform窗体显示在父窗体中,有两种情况,第一是模式显示,既showDialog().这种显示只需要设置StartPosition=CenterPostion.用代码如下:
From f2=new Form();
f2.StartPosition = FormStartPosition.CenterParent;
f2.ShowDialog()
第二种是非模式显示:这样只能用手动去控制他的位置了。代码如下:
From f2=new Form();
f2.Left = this.Left + (this.Width - f2.Width) / 2;
f2.Top = this.Top + (this.Top - f2.Top) / 2;
f2.Show();
再在属性中设置StartPosition 为Manual.
特别提示:这里f2.show()一定要写在f2.left,f2.top后面,否则效果会达不到的