using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Microsoft.Win32; namespace 从上次关闭位置启动窗体 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { RegistryKey reg1, reg2; reg1 = Registry.CurrentUser; try { reg2 = reg1.CreateSubKey("Software\Mysoft"); this.Location = new Point(Convert.ToInt16(reg2.GetValue("1")), Convert.ToInt16(reg2.GetValue("2"))); } catch { } } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { RegistryKey reg1, reg2; reg1 = Registry.CurrentUser; reg2 = reg1.CreateSubKey("Software\Mysoft"); try { reg2.SetValue("1", this.Location.X.ToString()); reg2.SetValue("2", this.Location.Y.ToString()); } catch { } } } }