public void TakeMessage(string btnStatus, string userName)
{
if (userName == "")
{
MessageBox.Show("Введите Ваше имя!");
}
else if (btnStatus == "Red")
{
btnTest.BackColor = Color.Green;
btnTest.Text = "Свободно";
}
else
{
btnTest.BackColor = Color.Red;
btnTest.Text = userName;
}
}
private void btnClick(object sender, EventArgs e)
{
Control btn = (Control)sender;
if (btn.BackColor == Color.Green)
{
btnStatus = "Green";
}
else
{
btnStatus = "Red";
}
Server.SendMessageToAll(btnStatus, tbLogin.Text);
TakeMessage(btnStatus, tbLogin.Text);
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (var button in Controls.OfType<Button>())
{
button.Click += btnClick;
}
}
public void TakeMessage(string btnStatus, string userName, Button btnTest)
{
if (userName == "")
{
MessageBox.Show("Введите Ваше имя!");
}
else if (btnStatus == "Red")
{
btnTest.BackColor = Color.Green;
btnTest.Text = "Свободно";
}
else
{
btnTest.BackColor = Color.Red;
btnTest.Text = userName;
}
}
private void btnClick(object sender, EventArgs e)
{
var btn = sender as Button;
if (btn.BackColor == Color.Green)
{
btnStatus = "Green";
}
else
{
btnStatus = "Red";
}
Server.SendMessageToAll(btnStatus, tbLogin.Text);
TakeMessage(btnStatus, tbLogin.Text, btn);
}