0

好的,所以我正在使用打开新表单的下一个按钮做一些事情,令人讨厌的是新表单会弹出我不想在桌面上的某个地方。

我正在尝试使用下面的代码让新表单在旧表单的位置生成,不幸的是无论出于何种原因它根本不起作用,它们仍然以与以前相同的方式弹出。是的,我已经注册了这些活动。

表格1:

System.Drawing.Point LocationPoint = new System.Drawing.Point(200,200);
private void Installer_template_LocationChanged(object sender, EventArgs e)
{
    // Save the window location to the installer arts
    LocationPoint = this.Location;
}
private void NextButton_Click(object sender, EventArgs e)
{
    var NextForm = new Form2(LocationPoint);
    NextForm.Show();
    this.Hide();
}

表格2

  public Form2(System.Drawing.Point LocationPoint)
    {
        InitializeComponent();
        this.Location = LocationPoint;
    }

代码是这样的

4

2 回答 2

1

您是否尝试过设置新表单的StartPosition,即

        this.StartPosition = FormStartPosition.Manual;

或者

        this.StartPosition = FormStartPosition.CenterParent;
于 2012-08-01T00:28:53.583 回答
0

好吧,我修复了它,这是一堆问题。

  1. 错误的属性,必须使用 DesktopLocation 而不是 Location 属性

  2. 其次,我遇到了一些无法修改的静态成员问题或任何错误,我只是使用设置文件来保存我的位置

  3. Having that done, it still didn't work because you can't just do this.DesktopLocation = something, you have to use this.SetDesktopLocation(X, Y)

  4. Still didn't work, because it got overwritten by other code when loading the form so you had to use the Shown even of the form and run it in there..

于 2012-08-01T00:47:52.663 回答