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());// string ColorString = (string)SelfPlacingWindowKey.GetValue("BackColor");
// BackColor = Color.FromName(ColorString);
// listBoxMessages.Items.Add("Background color: " + ColorString); int RedComponent = (int)SelfPlacingWindowKey.GetValue("Red");
int GreenComponent = (int)SelfPlacingWindowKey.GetValue("Green");
int BlueComponent = (int)SelfPlacingWindowKey.GetValue("Blue");
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");
DesktopLocation = new Point(X, Y);
listBoxMessages.Items.Add("Desktop location: " + DesktopLocation.ToString()); Height = (int)SelfPlacingWindowKey.GetValue("Height");
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);
WindowState = (FormWindowState)FormWindowState.Parse
(WindowState.GetType(), InitialWindowState); return true;
}
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());
}