C# Winform操作注册表实现窗体的定位记忆功能

 1 using Microsoft.Win32;
 2 using System;
 3 using System.Windows.Forms;
 4 
 5 namespace csReg
 6 {
 7     public partial class Form1 : Form
 8     {
 9         public Form1()
10         {
11             InitializeComponent();
12         }
13 
14         private void Form1_Load(object sender, EventArgs e)
15         {
16             RegistryKey myReg1, myReg2;
17             myReg1 = Registry.CurrentUser;
18             try
19             {
20                 myReg2 = myReg1.CreateSubKey("Software\MySoftTest");
21                 this.Location = new System.Drawing.Point(Convert.ToInt16(myReg2.GetValue("1")), Convert.ToInt16(myReg2.GetValue("2")));
22             }
23             catch { }      
24             
25         }
26 
27         private void Form1_FormClosed(object sender, FormClosedEventArgs e)
28         {
29             RegistryKey myReg1, myReg2;
30             myReg1 = Registry.CurrentUser;
31             try
32             {
33                 myReg2 = myReg1.CreateSubKey("Software\MySoftTest");
34                 myReg2.SetValue("1", Location.X);
35                 myReg2.SetValue("2", Location.Y);
36             }
37             catch { }
38         }
39     }
40 }
原文地址:https://www.cnblogs.com/heroysj/p/12712544.html