Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Vezba_21
- {
- public partial class Form1 : Form
- {
- private Button[] buttons = new Button[26];
- public Form1()
- {
- InitializeComponent();
- CreateLetterButtons();
- }
- private void CreateLetterButtons()
- {
- int xLocation = 12;
- int yLocation = 12;
- int i = 0;
- for (char c = 'A'; c <= 'Z'; c++)
- {
- //Kreiranje button objekta
- Button button = new Button();
- //Podesavanje svojstava
- button.Location = new System.Drawing.Point(xLocation, yLocation);
- button.Name = "button" + c.ToString();
- button.Size = new Size(25, 25);
- button.Text = c.ToString();
- button.BackColor = Color.White;
- //Dodavanje hendlera
- button.Click += new System.EventHandler(button_Click);
- //Dodavanje kontrole u kolciju kontrola
- Controls.Add(button);
- buttons[i] = button;
- if (c == 'M')
- {
- xLocation = -18;
- yLocation = 40;
- }
- xLocation += 30;
- }
- xLocation = 12;
- for (int a = 0; a <= 9; a++)
- {
- //Kreiranje button objekta
- Button button = new Button();
- //Podesavanje svojstava
- button.Location = new System.Drawing.Point(xLocation, yLocation + 30);
- button.Name = "button" + a.ToString();
- button.Size = new Size(25, 25);
- button.Text = a.ToString();
- button.BackColor = Color.White;
- //Dodavanje hendlera
- button.Click += new System.EventHandler(button_Click);
- //Dodavanje kontrole u kolciju kontrola
- Controls.Add(button);
- buttons[i] = button;
- xLocation += 30;
- }
- }
- private void button_Click(object sender, EventArgs e)
- {
- Button button = (Button)sender;
- textBox1.Text += button.Text;
- }
- private void textBox1_KeyDown(object sender, KeyEventArgs e)
- {
- char c = (char)e.KeyValue;
- if(char.IsLetter(c))
- {
- foreach (Button button in buttons)
- {
- if (c.ToString() == button.Text)
- {
- textBox1.Text += c;
- button.BackColor = Color.BlueViolet;
- }
- }
- }
- }
- private void textBox1_KeyUp_1(object sender, KeyEventArgs e)
- {
- char c = (char)e.KeyValue;
- if (char.IsLetter(c))
- {
- foreach (Button button in buttons)
- {
- if (c.ToString() == button.Text)
- {
- textBox1.Text += c;
- button.BackColor = Color.White;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement