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 CSharpFlags
- {
- [FlagsAttribute]
- enum MyBitField : short
- {
- Player = 1,
- Enemy = 2,
- Bullet = 4,
- Trigger = 8,
- Wall = 16
- };
- public partial class Form1 : Form
- {
- MyBitField myValue = 0;
- public Form1() {
- InitializeComponent();
- Array values = Enum.GetValues(typeof(MyBitField));
- int idx = 0;
- foreach (MyBitField val in values) {
- var name = Enum.GetName(typeof(MyBitField), val);
- var checkBox = new System.Windows.Forms.CheckBox();
- checkBox.AutoSize = true;
- checkBox.Location = new System.Drawing.Point(40, 60 + 20 * idx);
- checkBox.Name = "bit_" + name;
- checkBox.Size = new System.Drawing.Size(80, 17);
- checkBox.Text = name;
- checkBox.UseVisualStyleBackColor = true;
- this.Controls.Add(checkBox);
- var myVal = val;
- checkBox.CheckedChanged += new System.EventHandler((sender, evt) => {
- if (checkBox.Checked) {
- myValue |= myVal;
- } else {
- myValue &= ~myVal;
- }
- updateValue();
- });
- idx++;
- }
- updateValue();
- }
- private void updateValue() {
- this.textBox1.Text = ((int)(myValue)).ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement