Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- private int BitPosition = 1;
- private int BitMask = 0;
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- foreach(CheckBox CheckBox in groupBox1.Controls.OfType<CheckBox>())
- { // add CheckBoxSelected setting to this project
- BitMask = Properties.Settings.Default.CheckBoxSelected;
- CheckBox.Tag = BitPosition;
- CheckBox.Checked = (BitMask & Convert.ToInt32(CheckBox.Tag)) == Convert.ToInt32(CheckBox.Tag);
- CheckBox.CheckedChanged += CheckBox_CheckedChanged;
- BitPosition *= 2;
- }
- }
- private void CheckBox_CheckedChanged(object sender, EventArgs e)
- {
- BitMask = BitMask ^ Convert.ToInt32(((System.Windows.Forms.Control)(sender)).Tag);
- }
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- Properties.Settings.Default.CheckBoxSelected = BitMask;
- Properties.Settings.Default.Save();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement