Advertisement
Guest User

Untitled

a guest
Feb 6th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.07 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 TextBoxTeste
  11. {
  12. public partial class Form1 : Form
  13. {
  14. TextBox[,] txts = new TextBox[16, 16];
  15.  
  16. public Form1()
  17. {
  18. CriarGrelhaTextBoxs();
  19. InitializeComponent();
  20. //=========================================
  21. comboBox1.Text = "Select one Bag of Words";
  22. comboBox1.Items.Add("Animais");
  23. comboBox1.SelectedItem = "";
  24.  
  25.  
  26. }
  27. private void Form1_Load(object sender, EventArgs e)
  28. {
  29.  
  30. }
  31.  
  32. public void CriarGrelhaTextBoxs() // Função que cria a matriz e as texbox's.
  33. {
  34. for (int y = 0; y < 16; y++)
  35. {
  36. for (int x = 0; x < 16; x++)
  37. {
  38. TextBox txt = new TextBox();
  39. txt.Left = x * 20;
  40. txt.Top = y * 20;
  41. txt.Width = 21;
  42. txt.MaxLength = 1;
  43. txt.Font = new System.Drawing.Font("Perpetua Titling MT", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  44. txt.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
  45. this.Controls.Add(txt);
  46.  
  47. txts[x, y] = txt;
  48. txts[x, y].CharacterCasing = CharacterCasing.Upper; // Tornar todas as letras em Maisculas*
  49.  
  50. }
  51. }
  52.  
  53. Cores(); // Chamar a função para introduzir as cores no tabuleiro
  54. NumerarTabuleiro(); // Chamar a função para introduzir os numeros ao redor do tabuleiro
  55.  
  56. }
  57.  
  58. public void Cores()
  59. {
  60. txts[8, 8].BackColor = System.Drawing.Color.Yellow; // centro
  61.  
  62. txts[14, 14].BackColor = System.Drawing.Color.LightGreen; // LightGreen
  63. txts[13, 13].BackColor = System.Drawing.Color.LightGreen;
  64. txts[12, 12].BackColor = System.Drawing.Color.LightGreen;
  65. txts[11, 11].BackColor = System.Drawing.Color.LightGreen;
  66. txts[10, 10].BackColor = System.Drawing.Color.LightGreen;
  67. txts[9, 9].BackColor = System.Drawing.Color.LightGreen;
  68. txts[7, 7].BackColor = System.Drawing.Color.LightGreen;
  69. txts[6, 6].BackColor = System.Drawing.Color.LightGreen;
  70. txts[5, 5].BackColor = System.Drawing.Color.LightGreen;
  71. txts[4, 4].BackColor = System.Drawing.Color.LightGreen;
  72. txts[3, 3].BackColor = System.Drawing.Color.LightGreen;
  73. txts[2, 2].BackColor = System.Drawing.Color.LightGreen;
  74. txts[2, 14].BackColor = System.Drawing.Color.LightGreen;
  75. txts[3, 13].BackColor = System.Drawing.Color.LightGreen;
  76. txts[4, 12].BackColor = System.Drawing.Color.LightGreen;
  77. txts[5, 11].BackColor = System.Drawing.Color.LightGreen;
  78. txts[6, 10].BackColor = System.Drawing.Color.LightGreen;
  79. txts[7, 9].BackColor = System.Drawing.Color.LightGreen;
  80. txts[14, 2].BackColor = System.Drawing.Color.LightGreen;
  81. txts[13, 3].BackColor = System.Drawing.Color.LightGreen;
  82. txts[12, 4].BackColor = System.Drawing.Color.LightGreen;
  83. txts[11, 5].BackColor = System.Drawing.Color.LightGreen;
  84. txts[10, 6].BackColor = System.Drawing.Color.LightGreen;
  85. txts[9, 7].BackColor = System.Drawing.Color.LightGreen;
  86.  
  87. txts[8, 1].BackColor = System.Drawing.Color.LightSalmon; // vermelho
  88. txts[1, 8].BackColor = System.Drawing.Color.LightSalmon;
  89. txts[8, 15].BackColor = System.Drawing.Color.LightSalmon;
  90. txts[15, 8].BackColor = System.Drawing.Color.LightSalmon;
  91. txts[15, 1].BackColor = System.Drawing.Color.LightSalmon;
  92. txts[1, 15].BackColor = System.Drawing.Color.LightSalmon;
  93. txts[1, 1].BackColor = System.Drawing.Color.LightSalmon;
  94. txts[15, 15].BackColor = System.Drawing.Color.LightSalmon;
  95.  
  96. txts[6, 14].BackColor = System.Drawing.Color.CornflowerBlue; // azul
  97. txts[10, 14].BackColor = System.Drawing.Color.CornflowerBlue;
  98. txts[2, 6].BackColor = System.Drawing.Color.CornflowerBlue;
  99. txts[2, 10].BackColor = System.Drawing.Color.CornflowerBlue;
  100. txts[6, 2].BackColor = System.Drawing.Color.CornflowerBlue;
  101. txts[10, 2].BackColor = System.Drawing.Color.CornflowerBlue;
  102. txts[14, 10].BackColor = System.Drawing.Color.CornflowerBlue;
  103. txts[14, 6].BackColor = System.Drawing.Color.CornflowerBlue;
  104.  
  105. txts[8, 12].BackColor = System.Drawing.Color.LightBlue; // LightBlue
  106. txts[7, 13].BackColor = System.Drawing.Color.LightBlue;
  107. txts[9, 13].BackColor = System.Drawing.Color.LightBlue;
  108. txts[3, 7].BackColor = System.Drawing.Color.LightBlue;
  109. txts[3, 9].BackColor = System.Drawing.Color.LightBlue;
  110. txts[4, 8].BackColor = System.Drawing.Color.LightBlue;
  111. txts[7, 3].BackColor = System.Drawing.Color.LightBlue;
  112. txts[9, 3].BackColor = System.Drawing.Color.LightBlue;
  113. txts[8, 4].BackColor = System.Drawing.Color.LightBlue;
  114. txts[13, 7].BackColor = System.Drawing.Color.LightBlue;
  115. txts[13, 9].BackColor = System.Drawing.Color.LightBlue;
  116. txts[12, 8].BackColor = System.Drawing.Color.LightBlue;
  117.  
  118. txts[1, 4].BackColor = System.Drawing.Color.LightBlue;
  119. txts[4, 1].BackColor = System.Drawing.Color.LightBlue;
  120. txts[1, 12].BackColor = System.Drawing.Color.LightBlue;
  121. txts[4, 15].BackColor = System.Drawing.Color.LightBlue;
  122. txts[12, 15].BackColor = System.Drawing.Color.LightBlue;
  123. txts[15, 12].BackColor = System.Drawing.Color.LightBlue;
  124. txts[12, 1].BackColor = System.Drawing.Color.LightBlue;
  125. txts[15, 3].BackColor = System.Drawing.Color.LightBlue;
  126. } // Função para por as cores no tabuleiro
  127.  
  128. public void NumerarTabuleiro()
  129. {
  130. // Escrever os limites do tabuleiro
  131. txts[0, 0].Text = "0";
  132. txts[0, 1].Text = "1";
  133. txts[0, 2].Text = "2";
  134. txts[0, 3].Text = "3";
  135. txts[0, 4].Text = "4";
  136. txts[0, 5].Text = "5";
  137. txts[0, 6].Text = "6";
  138. txts[0, 7].Text = "7";
  139. txts[0, 8].Text = "8";
  140. txts[0, 9].Text = "9";
  141. txts[0, 10].Text = "10";
  142. txts[0, 11].Text = "11";
  143. txts[0, 12].Text = "12";
  144. txts[0, 13].Text = "13";
  145. txts[0, 14].Text = "14";
  146. txts[0, 15].Text = "15";
  147. //====================
  148. txts[0, 0].Text = "0";
  149. txts[1, 0].Text = "1";
  150. txts[2, 0].Text = "2";
  151. txts[3, 0].Text = "3";
  152. txts[4, 0].Text = "4";
  153. txts[5, 0].Text = "5";
  154. txts[6, 0].Text = "6";
  155. txts[7, 0].Text = "7";
  156. txts[8, 0].Text = "8";
  157. txts[9, 0].Text = "9";
  158. txts[10, 0].Text = "10";
  159. txts[11, 0].Text = "11";
  160. txts[12, 0].Text = "12";
  161. txts[13, 0].Text = "13";
  162. txts[14, 0].Text = "14";
  163. txts[15, 0].Text = "15";
  164. } // Função para enumerar o tabuleiro
  165.  
  166. private void button1_Click(object sender, EventArgs e)
  167. {
  168.  
  169. if (txts[7, 3].Text == "E" && txts[7, 4].Text == "L" && txts[7, 5].Text == "E" && txts[7, 6].Text == "F" && txts[7, 7].Text == "A" && txts[7, 8].Text == "N" && txts[7, 9].Text == "T" && txts[7, 10].Text == "E" &&// Elefante
  170. txts[12, 4].Text == "U" && txts[12, 5].Text == "R" && txts[12, 6].Text == "S" && txts[12, 7].Text == "O" && // Urso
  171. txts[13, 4].Text == "G" && txts[13, 5].Text == "A" && txts[13, 6].Text == "T" && txts[13, 7].Text == "O" && // Gato
  172. txts[9, 5].Text == "C" && txts[10, 5].Text == "O" && txts[11, 5].Text == "B" && txts[12, 5].Text == "R" && txts[13, 5].Text == "A" && // Cobra
  173. txts[9, 5].Text == "C" && txts[9, 6].Text == "A" && txts[9, 7].Text == "O" && // cao /*
  174. txts[3, 7].Text == "P" && txts[4, 7].Text == "A" && txts[5, 7].Text == "S" && txts[6, 7].Text == "S" && txts[7, 7].Text == "A" && txts[8, 7].Text == "R" && txts[9, 7].Text == "O" && // Passaro
  175. txts[3, 7].Text == "P" && txts[3, 8].Text == "A" && txts[3, 9].Text == "P" && txts[3, 10].Text == "A" && txts[3, 11].Text == "G" && txts[3, 12].Text == "A" && txts[3, 13].Text == "I" && txts[3, 14].Text == "O" && // Papagaio
  176. txts[2, 12].Text == "V" && txts[3, 12].Text == "A" && txts[4, 12].Text == "C" && txts[5, 12].Text == "A" && // Vaca
  177. txts[2, 13].Text == "G" && txts[3, 13].Text == "I" && txts[4, 13].Text == "R" && txts[5, 13].Text == "A" && txts[6, 13].Text == "F" && txts[7, 13].Text == "A" && // Girafa
  178. txts[3, 14].Text == "O" && txts[4, 14].Text == "V" && txts[5, 14].Text == "E" && txts[6, 14].Text == "L" && txts[7, 14].Text == "H" && txts[8, 14].Text == "A" ) // Ovelha
  179.  
  180. {
  181. MessageBox.Show("Parabéns, conseguiste completar as palavras!");
  182. }
  183. else
  184. {
  185. MessageBox.Show("Ups, parece que algo não está bem!");
  186. }
  187. } // Função para verificar se todas as posições correspondem ao que é pedido
  188.  
  189. private void btnVerificarBoW_Click(object sender, EventArgs e)
  190. {
  191. if (comboBox1.Text == "Animais")
  192. {
  193. listBox1.Items.Clear();
  194. listBox1.Items.AddRange(new Object[] { "Passaro", "Cao", "Gato", "Elefante", "Cobra", "Ovelha", "Papagaio", "Vaca", "Urso", "Girafa" });
  195.  
  196. txts[7, 3].Text = "E";
  197. txts[12, 4].Text = "U";
  198. txts[13, 4].Text = "G";
  199. txts[9, 5].Text = "C";
  200. txts[3, 7].Text = "P";
  201. txts[2, 12].Text = "V";
  202. txts[2, 13].Text = "G";
  203. txts[3, 14].Text = "O";
  204.  
  205. }
  206. else
  207. {
  208. MessageBox.Show("Sistema: ERRO btnVerificarBoW_Click");
  209. }
  210. } // Função de seleção de palavras e inserção de letras no tabuleiro
  211.  
  212. private void button2_Click(object sender, EventArgs e)
  213. {
  214. if (comboBox1.Text == "Animais")
  215. {
  216. txts[7, 3].Text = "E";
  217. txts[7, 4].Text = "L";
  218. txts[7, 5].Text = "E";
  219. txts[7, 6].Text = "F";
  220. txts[7, 7].Text = "A";
  221. txts[7, 8].Text = "N";
  222. txts[7, 9].Text = "T";
  223. txts[7, 10].Text = "E";
  224. // Elefante
  225. txts[12, 4].Text = "U";
  226. txts[12, 5].Text = "R";
  227. txts[12, 6].Text = "S";
  228. txts[12, 7].Text = "O";
  229. // Urso
  230. txts[13, 4].Text = "G";
  231. txts[13, 5].Text = "A";
  232. txts[13, 6].Text = "T";
  233. txts[13, 7].Text = "O";
  234. // Gato
  235. txts[9, 5].Text = "C";
  236. txts[10, 5].Text = "O";
  237. txts[11, 5].Text = "B";
  238. txts[12, 5].Text = "R";
  239. txts[13, 5].Text = "A";
  240. // Cobra
  241. txts[9, 5].Text = "C";
  242. txts[9, 6].Text = "A";
  243. txts[9, 7].Text = "O";
  244. // cao
  245. txts[3, 7].Text = "P";
  246. txts[4, 7].Text = "A";
  247. txts[5, 7].Text = "S";
  248. txts[6, 7].Text = "S";
  249. txts[7, 7].Text = "A";
  250. txts[8, 7].Text = "R";
  251. txts[9, 7].Text = "O";
  252. // Passaro
  253. txts[3, 7].Text = "P";
  254. txts[3, 8].Text = "A";
  255. txts[3, 9].Text = "P";
  256. txts[3, 10].Text = "A";
  257. txts[3, 11].Text = "G";
  258. txts[3, 12].Text = "A";
  259. txts[3, 13].Text = "I";
  260. txts[3, 14].Text = "O";
  261. // Papagaio
  262. txts[2, 12].Text = "V";
  263. txts[3, 12].Text = "A";
  264. txts[4, 12].Text = "C";
  265. txts[5, 12].Text = "A";
  266. // Vaca
  267. txts[2, 13].Text = "G";
  268. txts[3, 13].Text = "I";
  269. txts[4, 13].Text = "R";
  270. txts[5, 13].Text = "A";
  271. txts[6, 13].Text = "F";
  272. txts[7, 13].Text = "A";
  273. // Girafa
  274. txts[3, 14].Text = "O";
  275. txts[4, 14].Text = "V";
  276. txts[5, 14].Text = "E";
  277. txts[6, 14].Text = "L";
  278. txts[7, 14].Text = "H";
  279. txts[8, 14].Text = "A";
  280. }
  281. } // Função preencher o tabuleiro
  282. }
  283. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement