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 WindowsFormsApp1
{
public partial class Form1 : Form
{
List<string> listRoom;
List<Index> index;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
listRoom = new List<string>();
index = new List<Index>();
for(char c='A';c<='Z';c++)
{
listRoom.Add(c.ToString());
}
List<Button> buttons = new List<Button>();
int y = 5;
int x = 5;
for (int i = 1; i <= listRoom.Count; i++)
{
Button newButton = new Button();
if (i % 3 != 0)
{
newButton.Location = new Point(2 * x, 2 * y);
x += 42;
}
else
{
newButton.Location = new Point(2 * x, 2 * y);
y += 30;
x = 5;
}
newButton.Text = listRoom[i-1].ToString();
newButton.Size = new Size(80, 50);
newButton.MouseEnter += (s, ee) => newButton.Cursor = Cursors.Hand;
newButton.MouseLeave += (s, ee) => newButton.Cursor = Cursors.Arrow;
newButton.BackColor = Color.Green;
buttons.Add(newButton);
this.Controls.Add(newButton);
Index ind = new Index();
ind.index = newButton.TabIndex;
ind.Room = listRoom[i - 1].ToString();
index.Add(ind);
newButton.Click += NewButton_Click;
}
}
private void NewButton_Click(object sender, EventArgs e)
{
Button b = (Button)sender;
if (b.BackColor != Color.Red)
{
b.Text = b.Text + " [Disable]";
b.BackColor = Color.Red;
}
else
{
foreach (var v in index)
{
if (b.TabIndex == v.index)
{
b.Text = v.Room;
b.BackColor = Color.Green;
break;
}
}
}
}
}
public class Index
{
public int index { get; set; }
public string Room { get; set; }
}
}