我有一个奇怪的问题。当我在 Visual Studio (WinForm) 中创建新窗体时,在设计器中始终出现在位置 0,0。 不知何故(我不知道如何),我的表单位于设计器的中间(例如,左上角现在位于位置 120、150)。 有没有办法把它放回0,0?试图拖动它但不起作用。 提前致谢。 费尔南多
最佳答案
找到了!我继承了表单,并像这样覆盖了 OnShown:
private void gp_InicialN_Shown(object sender, EventArgs e)
{
Rectangle oRect = Screen.GetBounds(this);
this.Top = (oRect.Height / 2) - (this.Height / 2);
this.Left = (oRect.Width / 2) - (this.Width / 2);
}
我没有做的是检查 DesignMode 变量。现在,一旦更改就可以正常工作。
private void gp_InicialN_Shown(object sender, EventArgs e)
{
if (!DesignMode)
{
Rectangle oRect = Screen.GetBounds(this);
this.Top = (oRect.Height / 2) - (this.Height / 2);
this.Left = (oRect.Width / 2) - (this.Width / 2);
}
}
关于c# - Winform 在 Designer 中的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10643805/