Designer中的Winform位置

时间:2012-05-17 21:29:18

标签: c# winforms visual-studio-2008

我有一个奇怪的问题。当我在Visual Studio(WinForm)中创建一个新表单时,在设计器中始终出现在位置0,0。 不知何故(我不知道如何),我的表格位于设计师的中间(左上角现在位于120,150位)。 有没有办法把它放回0,0?试图拖动但不起作用。 提前致谢。 费尔南多

enter image description here

1 个答案:

答案 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);
     }
  }