Advertisement
tinyevil

Untitled

Apr 27th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace CSharpFlags
  11. {
  12. [FlagsAttribute]
  13. enum MyBitField : short
  14. {
  15. Player = 1,
  16. Enemy = 2,
  17. Bullet = 4,
  18. Trigger = 8,
  19. Wall = 16
  20. };
  21.  
  22. public partial class Form1 : Form
  23. {
  24. MyBitField myValue = 0;
  25.  
  26. public Form1() {
  27. InitializeComponent();
  28.  
  29. Array values = Enum.GetValues(typeof(MyBitField));
  30.  
  31. int idx = 0;
  32. foreach (MyBitField val in values) {
  33.  
  34. var name = Enum.GetName(typeof(MyBitField), val);
  35.  
  36. var checkBox = new System.Windows.Forms.CheckBox();
  37. checkBox.AutoSize = true;
  38. checkBox.Location = new System.Drawing.Point(40, 60 + 20 * idx);
  39. checkBox.Name = "bit_" + name;
  40. checkBox.Size = new System.Drawing.Size(80, 17);
  41. checkBox.Text = name;
  42. checkBox.UseVisualStyleBackColor = true;
  43. this.Controls.Add(checkBox);
  44.  
  45. var myVal = val;
  46.  
  47. checkBox.CheckedChanged += new System.EventHandler((sender, evt) => {
  48. if (checkBox.Checked) {
  49. myValue |= myVal;
  50. } else {
  51. myValue &= ~myVal;
  52. }
  53. updateValue();
  54. });
  55.  
  56. idx++;
  57. }
  58.  
  59. updateValue();
  60. }
  61.  
  62. private void updateValue() {
  63. this.textBox1.Text = ((int)(myValue)).ToString();
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement