110,538
社区成员
发帖
与我相关
我的任务
分享
//窗体位置在屏幕中间
form1.StartPosition = FormStartPosition.CenterScreen;
//窗体在其父窗口中间
form1.StartPosition = FormStartPosition.CenterParent;
//窗体在有其空间的Location属性而定
form1.StartPosition = FormStartPosition.Manual;
//窗体位置由Windows默认位置决定,窗体大小也是Windows默认大小
form1.StartPosition =FormStartPosition.WindowsDefaultBounds;
//窗体位置是Windows默认,大小在窗体大小中确定
form1.StartPosition =FormStartPosition.WindowsDefaultLocation
//获取屏幕宽度
int width=SystemInformation.VirtualScreen.Width;
//获取屏幕高度
int height = SystemInformation.VirtualScreen.Height;
那左上角的位置,就是Location(0,0)了。实际就是两句代码:
this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(0, 0);
private void _form2_LocationChanged(object sender, EventArgs e)
{
Point p = this.textBox1.PointToClient(_form2.PointToScreen(new Point(0, 0)));
int x = p.X - 8;
int y = p.Y - 28;
bool b1 = x < this.textBox1.Width && x > -_form2.Width;
bool b2 = y < this.textBox1.Height && y > -_form2.Height;
if (b1 && b2)
{
_form2.Location = new Point(0, 0);
}
}