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 Vezba21
- {
- public partial class Form1 : Form
- {
- Button[] buttons = new Button[26];
- Button[] brojeviButton = new Button[10];
- public Form1()
- {
- InitializeComponent();
- CreateButtons();
- }
- private void button_Click(object sender, EventArgs e)
- {
- Button button = (Button)sender;
- textBox1.Text += button.Text;
- }
- private void CreateButtons()
- {
- int xLoc = 12;
- int yLoc = 30;
- for (int i = 0; i < 10; i++)
- {
- Button button = new Button();
- button = new System.Windows.Forms.Button();
- button.Location = new System.Drawing.Point(xLoc, yLoc);
- button.Name = "button" + i.ToString();
- button.Size = new System.Drawing.Size(40, 40);
- button.Text = i.ToString();
- button.Click += new System.EventHandler(button_Click);
- Controls.Add(button);
- brojeviButton[i] = button;
- xLoc += 40;
- }
- xLoc = 12;
- yLoc = 70;
- for (char c= 'A'; c <= 'Z';c++)
- {
- Button button = new Button();
- button = new System.Windows.Forms.Button();
- button.Location = new System.Drawing.Point(xLoc , yLoc);
- button.Name = "button" + c.ToString();
- button.Size = new System.Drawing.Size(40, 40);
- button.Text = c.ToString();
- button.Click += new System.EventHandler(button_Click);
- Controls.Add(button);
- buttons[c - 'A'] = button;
- xLoc += 40;
- if (c.ToString() == "M")
- {
- yLoc = 110;
- xLoc = 12;
- }
- }
- }
- private void textBox1_KeyUp(object sender, KeyEventArgs e)
- {
- char c = (char)e.KeyValue;
- if (char.IsLetter(c))
- {
- foreach (Button btn in buttons)
- {
- if (c.ToString() == btn.Text)
- {
- btn.BackColor = Color.Transparent;
- }
- }
- }
- if(char.IsDigit(c))
- {
- foreach(Button btn in brojeviButton)
- {
- if(c.ToString() == btn.Text)
- {
- btn.BackColor = Color.Transparent;
- }
- }
- }
- }
- private void textBox1_KeyDown(object sender, KeyEventArgs e)
- {
- char c = (char)e.KeyValue;
- if(char.IsLetter(c))
- {
- foreach(Button btn in buttons)
- {
- if(c.ToString() == btn.Text)
- {
- textBox1.Text += c;
- btn.BackColor = Color.Aquamarine;
- }
- }
- }
- if (char.IsDigit(c))
- {
- foreach (Button btn in brojeviButton)
- {
- if (c.ToString() == btn.Text)
- {
- textBox1.Text += c;
- btn.BackColor = Color.Aquamarine;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement