/// <summary> /// Saves the new Warcraft III start-up settings. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">An System.EventArgs that contains no event data.</param> private void btnSave_Click(object sender, EventArgs e) { // Create a new Loader.StartOptions variable with None as default flag. // None means really no startup flag at all. Loader.StartOptions opt = Loader.StartOptions.None; /* * Explained: * The operator | means or. * In an If...Else statement it would look like this: * <code> * bool A = true; * bool B = false; * if (A == true || B == true) * { * Console.WriteLine("A or B is true"); * } * </code> * * To add a flag to an enum use |= (Or is) * * I'm not such an expert to tell you how it works in detail however, it has something to do with bit comparing. (Refer to Wikipedia.) */ if (cbClassic.Checked) { opt |= Loader.StartOptions.Classic; } if (cbOpenGL.Checked) { opt |= Loader.StartOptions.OpenGl; } if (cbSWTNL.Checked) { opt |= Loader.StartOptions.SWTNL; } if (cbWindow.Checked) { opt |= Loader.StartOptions.Window; } // Let the settings class handle the rest. Settings.StartupOptions = opt; }
/// <summary> /// Handles the <see cref="System.Windows.Forms.Form.Load"/> event. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">An System.EventArgs that contains no event data.</param> private void frmMain_Load(object sender, EventArgs e) { // Loads the start-up options into the form... Loader.StartOptions opt = Settings.StartupOptions; // Check if opt has some start-up flags. // If so, mark the right CheckBox as checked. if (opt.HasFlag(Loader.StartOptions.Classic)) { cbClassic.Checked = true; } if (opt.HasFlag(Loader.StartOptions.OpenGl)) { cbOpenGL.Checked = true; } if (opt.HasFlag(Loader.StartOptions.SWTNL)) { cbSWTNL.Checked = true; } if (opt.HasFlag(Loader.StartOptions.Window)) { cbWindow.Checked = true; } }