示例#1
0
        public MenuBar(UserConfig config)
        {
            Algorithm         = new AlgorithmScreen(config.AlgorithmScreenConfig);
            LogIn.deviceToken = config.DeviceToken;

            MenuPanel           = new Panel();
            MenuPanel.BackColor = Color.White;
            MenuPanel.Size      = new Size(150, 400);

            ToggleButton          = new PictureBox();
            ToggleButton.Image    = Bitmap.FromFile("Content/GUI/Button_Menu.png");
            ToggleButton.Size     = ToggleButton.Image.Size;
            ToggleButton.MouseUp += (sender, e) =>
            {
                if (ToggleButton.Parent.Controls.Contains(MenuPanel))
                {
                    // Hide the menu
                    Hide();
                }
                else
                {
                    // Show the menu
                    Show();
                }
            };
            ToggleButton.LocationChanged += (sender, e) =>
            {
                MenuPanel.Location = new Point(ToggleButton.Location.X, ToggleButton.Location.Y + ToggleButton.Height + 5);
                if (ToggleButton.Parent != null)
                {
                    ToggleButton.Parent.Refresh();
                }
            };

            MenuPanel.Controls.Add(new LogInButton(this));
            MenuPanel.Controls.Add(new ScriptButton(this));
            MenuPanel.Controls.Add(new ScriptSessionButton(this));
            PackMenu();
        }
        /// <summary>
        /// Loads a configuration from a file
        /// </summary>
        /// <param name="filePath">The path to save the file to</param>
        /// <returns>The loaded object</returns>
        public static UserConfig Load(string filePath)
        {
            UserConfig cfg = null;

            try
            {
                if (File.Exists(filePath))
                {
                    using (var stream = System.IO.File.OpenRead(filePath))
                    {
                        var serializer = new XmlSerializer(typeof(UserConfig));
                        cfg = serializer.Deserialize(stream) as UserConfig;
                    }
                }
            }
            catch (Exception ex) { }

            if (cfg == null)
            {
                cfg = new UserConfig();
            }

            return(cfg);
        }