Advertisement
Guest User

Main.cs

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