Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Восстановление данных из файла конфигурации.
        /// </summary>
        /// <returns></returns>
        bool ReadSettings()
        {
            // Загрузка настроек по парам [ключ]-[значение].
            NameValueCollection allAppSettings = ConfigurationManager.AppSettings;

            if (allAppSettings.Count < 1)
            {
                return(false);
            }

            // Восстановление состояния:
            //1. Цвет фона.
            int red   = Convert.ToInt32(allAppSettings["BackGroundColor.R"]);
            int green = Convert.ToInt32(allAppSettings["BackGroundColor.G"]);
            int blue  = Convert.ToInt32(allAppSettings["BackGroundColor.B"]);

            this.BackColor = Color.FromArgb(red, green, blue);
            listBox1.Items.Add("Цвет фона: " + BackColor.Name);

            //2. Расположение на экране.
            int X = Convert.ToInt32(allAppSettings["X"]);
            int Y = Convert.ToInt32(allAppSettings["Y"]);

            this.DesktopLocation = new Point(X, Y);
            listBox1.Items.Add("Расположение: " + DesktopLocation.ToString());

            //3. Размеры окна.
            this.Height = Convert.ToInt32(allAppSettings["Window.Height"]);
            this.Width  = Convert.ToInt32(allAppSettings["Window.Width"]);
            listBox1.Items.Add("Размер: " + new Size(Width, Height).ToString());

            //4. Состояние окна.
            string winState = allAppSettings["Window.State"];

            listBox1.Items.Add("Состояние окна: " + winState);
            this.WindowState = (FormWindowState)FormWindowState.Parse(WindowState.GetType(), winState);
            return(true);
        }