c# - Winform 在 Designer 中的位置

标签 c# winforms visual-studio-2008

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

enter image description here

最佳答案

找到了!我继承了表单,并像这样覆盖了 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/

相关文章:

c# - 如何使用 global.asax 中的 Server.MapPath()?

c# - 如何在 C# 中找到可用的命名空间及其内容?

c# - Asp.Net WebApi OWIN 身份验证

c# - DataGridView CheckBox 行返回 null,直到单击复选框

c# - 在 WinForms 应用程序中准确测量、渲染、 HitTest 和打印文本

.net - 无法访问 VBA 中的 COM 公开方法

c# - WCF:使用消息契约创建 Soap header

c# - Vector3 的纬度和经度未在 3D 球体上对齐

c# - ToolStripMenuItem ShowDropDown - 事件未触发

c++ - Visual Studio 链接器找不到 libboost_system