我希望您能告诉我如何设置表单的位置。我尝试了下面这个方法:
this.Location = Point;
或者:
Form2.Left = Point.X;
Form2.Top = Point.Y;
Form2.ShowDialog();
这个不起作用。我做错了什么?
private void button1_Click(object sender, EventArgs e)
{
var form2 = new Form();
form2.StartPosition = FormStartPosition.Manual;
form2.Left = 500;
form2.Top = 500;
form2.ShowDialog();
}
new Point(x,y)
更好,因为不需要添加对System.Drawing.dll
的引用。 - T.ToduaForm myform = new Form()
{
Size = new Size(200,200),
StartPosition = FormStartPosition.Manual,
Location = new Point(10,10) // or Cursor.Position if you want to set it to cursor position
}
// Point(specify location of x, specify location of y)
// with object initializer
var frmUsers = new FrmUsers
{
StartPosition = FormStartPosition.Manual,
Location = new Point(0, 0)
};
// or
var frmUsers = new FrmUsers();
frmUsers.StartPosition = FormStartPosition.Manual;
frmUsers.Location = new Point(0, 0);
试试这个:
private void Form_Load(object sender, EventArgs e)
{
this.SetDesktopLocation(x, y);
}
你的第一种方法无论如何都可以工作。
this.Location = new Point(/*XPosition*/, /*YPosition*/);
你可以这样设置:
form1.Location = new Point(4, 370);