Advertisement
Guest User

xx

a guest
Mar 29th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 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 Vezba_21
  12. {
  13. public partial class Form1 : Form
  14. {
  15. private Button[] buttons = new Button[26];
  16.  
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. CreateLetterButtons();
  21. }
  22.  
  23. private void CreateLetterButtons()
  24. {
  25. int xLocation = 12;
  26. int yLocation = 12;
  27.  
  28. int i = 0;
  29.  
  30. for (char c = 'A'; c <= 'Z'; c++)
  31. {
  32. //Kreiranje button objekta
  33. Button button = new Button();
  34. //Podesavanje svojstava
  35. button.Location = new System.Drawing.Point(xLocation, yLocation);
  36. button.Name = "button" + c.ToString();
  37. button.Size = new Size(25, 25);
  38. button.Text = c.ToString();
  39. button.BackColor = Color.White;
  40. //Dodavanje hendlera
  41. button.Click += new System.EventHandler(button_Click);
  42. //Dodavanje kontrole u kolciju kontrola
  43. Controls.Add(button);
  44.  
  45. buttons[i] = button;
  46.  
  47. if (c == 'M')
  48. {
  49. xLocation = -18;
  50. yLocation = 40;
  51. }
  52. xLocation += 30;
  53. }
  54.  
  55. xLocation = 12;
  56.  
  57. for (int a = 0; a <= 9; a++)
  58. {
  59. //Kreiranje button objekta
  60. Button button = new Button();
  61. //Podesavanje svojstava
  62. button.Location = new System.Drawing.Point(xLocation, yLocation + 30);
  63. button.Name = "button" + a.ToString();
  64. button.Size = new Size(25, 25);
  65. button.Text = a.ToString();
  66. button.BackColor = Color.White;
  67. //Dodavanje hendlera
  68. button.Click += new System.EventHandler(button_Click);
  69. //Dodavanje kontrole u kolciju kontrola
  70. Controls.Add(button);
  71.  
  72. buttons[i] = button;
  73.  
  74. xLocation += 30;
  75. }
  76. }
  77.  
  78. private void button_Click(object sender, EventArgs e)
  79. {
  80. Button button = (Button)sender;
  81. textBox1.Text += button.Text;
  82. }
  83.  
  84. private void textBox1_KeyDown(object sender, KeyEventArgs e)
  85. {
  86. char c = (char)e.KeyValue;
  87. if(char.IsLetter(c))
  88. {
  89. foreach (Button button in buttons)
  90. {
  91. if (c.ToString() == button.Text)
  92. {
  93. textBox1.Text += c;
  94. button.BackColor = Color.BlueViolet;
  95. }
  96. }
  97. }
  98. }
  99.  
  100.  
  101.  
  102. private void textBox1_KeyUp_1(object sender, KeyEventArgs e)
  103. {
  104. char c = (char)e.KeyValue;
  105. if (char.IsLetter(c))
  106. {
  107. foreach (Button button in buttons)
  108. {
  109. if (c.ToString() == button.Text)
  110. {
  111. textBox1.Text += c;
  112. button.BackColor = Color.White;
  113. }
  114. }
  115. }
  116. }
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement