Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 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.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Assignment_2
  12. {
  13. public partial class FormMain : Form, IView
  14. {
  15. string ClickedText;
  16.  
  17. public FormMain()
  18. {
  19. InitializeComponent();
  20. }
  21.  
  22. public void Show(string message)
  23. {
  24. // DisplayOutput(message);
  25. }
  26. public void SetController(GameController controller)
  27. {
  28. // theController = controller;
  29. }
  30.  
  31. /* protected void MakeButtons()
  32. {
  33. Button btnNew = new Button();
  34. btnNew.Name = "btn";
  35. btnNew.Height = 50;
  36. btnNew.Width = 50;
  37. btnNew.Font = new Font("Arial", 20);
  38. btnNew.Text = "#";
  39. btnNew.Visible = true;
  40. btnNew.Location = new Point(10, 10);
  41.  
  42. Controls.Add(btnNew);
  43. } */
  44.  
  45. protected void MakeButtons2(string name, string text, int row, int column)
  46. {
  47. Button btnNew = new Button();
  48. btnNew.Name = name + column.ToString() + "_" + row.ToString();
  49. btnNew.Height = 50;
  50. btnNew.Width = 50;
  51. btnNew.Font = new Font("Arial", 20);
  52. btnNew.Text = text;
  53. btnNew.Visible = true;
  54. btnNew.Location = new Point(10 + 50 * row, 10 + 50 * column);
  55.  
  56. Controls.Add(btnNew);
  57. }
  58.  
  59. protected void WhoClicked(object sender, EventArgs e)
  60. {
  61. Button btnWho = sender as Button;
  62.  
  63. this.Text = btnWho.Name;
  64.  
  65. if (btnWho.Name.StartsWith("btn"))
  66. {
  67. btnWho.Text = ClickedText;
  68. }
  69. else if (btnWho.Name.StartsWith("iptBtn_"))
  70. {
  71. this.ClickedText = btnWho.Text;
  72. }
  73. }
  74.  
  75. protected void SetClicks()
  76. {
  77. foreach (Control c in this.Controls)
  78. {
  79. if (c is Button)
  80. {
  81. Button who = c as Button;
  82. who.Click += new EventHandler(WhoClicked);
  83. }
  84. }
  85. }
  86.  
  87. private void button1_Click(object sender, EventArgs e)
  88. {
  89. // MakeButtons();
  90.  
  91. for (int i = 0; i < 6; ++i)
  92. {
  93. for (int j = 0; j < 5; ++j)
  94. {
  95. MakeButtons2("btn_", "#", i, j);
  96. }
  97. }
  98.  
  99. Control c = Controls.Find("btn_3_4", true)[0];
  100. Button b = c as Button;
  101.  
  102. // c.Text = "@";
  103. b.Text = "@";
  104.  
  105. // SetClicks();
  106. }
  107.  
  108. private void button2_Click(object sender, EventArgs e)
  109. {
  110. for (int i = 0; i < 6; ++i)
  111. {
  112. for (int j = 6; j < 7; ++j)
  113. {
  114. MakeButtons2("iptBtn_", ((char)(35 + i)).ToString(), i, j);
  115. }
  116. }
  117.  
  118. SetClicks();
  119. }
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement