Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. public Form1()
  2. {
  3. InitializeComponent();
  4. this.SerCorrespondingButtons();
  5. this.SetCorrespondingInitialButtonInscriptions();
  6. }
  7. System.Windows.Forms.Timer tmr = new System.Windows.Forms.Timer();
  8. private Dictionary<Button, Label> correspondingControls;
  9. private Dictionary<Button, string> initialButtonInscriptions;
  10.  
  11. private List<string> sayingsList;
  12. private Button currentButton;
  13.  
  14. private int i;
  15. private void SerCorrespondingButtons()
  16. {
  17. correspondingControls = new Dictionary<Button, Label>()
  18. {
  19. {this.button1, this.label1},
  20. {this.button2, this.label2},
  21. };
  22. }
  23.  
  24. private void SetCorrespondingInitialButtonInscriptions()
  25. {
  26. this.initialButtonInscriptions = new Dictionary<Button, string>()
  27. {
  28. {this.button1, this.button1.Text},
  29. {this.button2, this.button2.Text}
  30. };
  31. }
  32. private void button2_Click(object sender, EventArgs e)
  33. {
  34. var button = sender as Button;
  35. if (this.currentButton != null)
  36. {
  37. this.currentButton.Enabled = true;
  38. this.currentButton.Text = this.initialButtonInscriptions[this.currentButton];
  39. this.currentButton.Click += this.button2_Click;
  40. tmr.Enabled = false;
  41. tmr.Tick -= timer2_Tick;
  42. }
  43. this.currentButton = button;
  44. var saying = this.correspondingControls[button];
  45. saying.Visible = true;
  46. button.Text = "Click To Hide Saying";
  47. button.Click -= button2_Click;
  48. button.Click += button2_Click2;
  49. }
  50. private void button2_Click2(object sender, EventArgs e)
  51. {
  52. var button = sender as Button;
  53. var saying = this.correspondingControls[button];
  54. saying.Visible = true;
  55. if (saying.Visible)
  56. {
  57. button.Enabled = false;
  58. saying.Visible = false;
  59. button.Text = "Reactivating in 5 seconds";
  60. tmr.Interval = 1000;
  61. button.Click -= button2_Click2;
  62. button.Click += button2_Click;
  63. this.i = 4;
  64. tmr.Tick += timer2_Tick;
  65. tmr.Enabled = true;
  66. }
  67. }
  68. private void timer2_Tick(object sender, EventArgs e)
  69. {
  70. if (i != 0)
  71. {
  72. this.currentButton.Text = "Reactivating in " + i + " seconds";
  73. i -= 1;
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement