读写注册表的样码:
void SaveSettings()
{
RegistryKey softwareKey = 
Registry.LocalMachine.OpenSubKey("Software", true);
RegistryKey wroxKey = softwareKey.CreateSubKey("WroxPress");
RegistryKey selfPlacingWindowKey = 
wroxKey.CreateSubKey("SelfPlacingWindow");
selfPlacingWindowKey.SetValue("BackColor", 
(object)BackColor.ToKnownColor());
selfPlacingWindowKey.SetValue("Red", (object)(int)BackColor.R);
selfPlacingWindowKey.SetValue("Green", (object)(int)BackColor.G);
selfPlacingWindowKey.SetValue("Blue", (object)(int)BackColor.B);
selfPlacingWindowKey.SetValue("Width", (object)Width);
selfPlacingWindowKey.SetValue("Height", (object)Height);
selfPlacingWindowKey.SetValue("X", (object)DesktopLocation.X);
selfPlacingWindowKey.SetValue("Y", (object)DesktopLocation.Y);
selfPlacingWindowKey.SetValue("WindowState", 
(object)WindowState.ToString());
} bool ReadSettings()

RegistryKey softwareKey = 
Registry.LocalMachine.OpenSubKey("Software");
RegistryKey wroxKey = softwareKey.OpenSubKey("WroxPress");
if (wroxKey == null)
return false;
RegistryKey selfPlacingWindowKey = 
wroxKey.OpenSubKey("SelfPlacingWindow");
if (selfPlacingWindowKey == null)
return false;
else
listBoxMessages.Items.Add("Successfully opened key " + 
selfPlacingWindowKey.ToString());
int redComponent = (int)selfPlacingWindowKey.GetValue("Red");
int greenComponent = (int)selfPlacingWindowKey.GetValue("Green");
int blueComponent = (int)selfPlacingWindowKey.GetValue("Blue");
this.BackColor = Color.FromArgb(redComponent, greenComponent, 
blueComponent);
listBoxMessages.Items.Add("Background color: " + BackColor.Name);
int X = (int)selfPlacingWindowKey.GetValue("X");
int Y = (int)selfPlacingWindowKey.GetValue("Y");
this.DesktopLocation = new Point(X, Y);
listBoxMessages.Items.Add("Desktop location: " + 
DesktopLocation.ToString());
this.Height = (int)selfPlacingWindowKey.GetValue("Height");
this.Width = (int)selfPlacingWindowKey.GetValue("Width");
listBoxMessages.Items.Add("Size: " + new 
Size(Width,Height).ToString());
string initialWindowState = 
(string)selfPlacingWindowKey.GetValue("WindowState");
listBoxMessages.Items.Add("Window State: " + initialWindowState);
this.WindowState = (FormWindowState)FormWindowState.Parse
(WindowState.GetType(), initialWindowState);
return true;
}

解决方案 »

  1.   

    2.
    你在注册表里选择一个根项(或者自己建一个项):
    在右面的框里右键新建字符串:名称你自定,然后在属性窗口里的VALUE栏里输入以下其中一个:
    [EDITA1]         -->对应文本框A的第1个输入框
    [EDITA2]         -->对应文本框A的第2个输入框
    [EDITA3]         -->对应文本框A的第3个输入框
    [EDITA4]         -->对应文本框A的第4个输入框
    这样文本框输入的值就可以保存到注册表了.