Winform 窗体的初始位置由上次关闭位置决定

private void Form1_Load(object sender, EventArgs e)
{
  RegistryKey reg = Registry.CurrentUser.CreateSubKey("SoftWare\\MySoft");
  int x = Convert.ToInt32(reg.GetValue("1"));
  int y = Convert.ToInt32(reg.GetValue("2"));
  this.Location = new Point(x, y);//可以转换成 Left 、Top 见 2.
}

private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
  RegistryKey reg1 = Registry.CurrentUser;
  RegistryKey reg2 = reg1.CreateSubKey("SoftWare\\MySoft");
  reg2.SetValue("1", this.Location.X);
  reg2.SetValue("2", this.Location.Y);
}

posted @ 2017-08-30 09:41  viu  阅读(432)  评论(0)    收藏  举报