示例#1
0
 private void ConfigWindow()
 {
     try
     {
         var formatter = new XmlSerializer(typeof(AppConfigs));
         using (FileStream fs = new FileStream("../../conf/config.xml", FileMode.Open))
         {
             AppConfigs conf = (AppConfigs)formatter.Deserialize(fs);
             if (conf.ClientHeight <= 0 || conf.ClientHeight > 740 ||
                 conf.ClientWidth <= 0 || conf.ClientWidth > 1366 ||
                 conf.ClientOpacity <= 0 || conf.ClientOpacity > 100)
             {
                 throw new Exception();
             }
             this.Width     = conf.ClientWidth;
             this.Height    = conf.ClientHeight;
             this.Opacity   = conf.ClientOpacity;
             this.BackColor = Color.FromName(conf.ClientBackground);
         }
     }
     catch
     {
         MessageBox.Show("Ошибка при чтении параметров");
         this.Width     = 899;
         this.Height    = 432;
         this.Opacity   = 100;
         this.BackColor = Color.White;
     }
 }
示例#2
0
        private void buttonApply_Click(object sender, EventArgs e)
        {
            int width, height, opacity;

            if (textBoxWidth.Text.Trim() != "" && int.TryParse(textBoxWidth.Text, out width) &&
                width > 0 && width <= 1366 &&
                textBoxHeight.Text.Trim() != "" && int.TryParse(textBoxHeight.Text, out height) &&
                height > 0 && height <= 740 &&
                textBoxOpacity.Text.Trim() != "" && int.TryParse(textBoxOpacity.Text, out opacity) &&
                opacity > 0 && opacity <= 100)
            {
                var conf      = new AppConfigs(width, height, opacity, background);
                var formatter = new XmlSerializer(typeof(AppConfigs));

                using (FileStream fs = new FileStream("../../conf/config.xml", FileMode.Create))
                {
                    formatter.Serialize(fs, conf);
                }
                this.Close();
            }
            else
            {
                MessageBox.Show("Неверные значения");
                return;
            }
        }