The thing is like this:
I have two forms, Form1
and Form2
.
Form1
is the main one and has 20 buttons which each represents a different table of my restaurant. Clicking on any of them opens a Form2
in which you can register orders, etc ... Each form2
also contains a Title button Abrir Mesa
which I need that when clicked I change the color of button background MESA 1
in Form1
. If the button Abrir mesa
of MESA 2
is clicked, then I need it to be THIS and not the MESA 1
that changes color, and so on.
I have created this that works for me only for the first button, that is to say the MESA1
but I do not manage to achieve something that is for everyone.
I leave some code to see if someone can help me.
Thank you very much!
// FORM 1
public void btnMesa1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2(this);
f2.Text = "Mesa 1";
f2.Show();
}
private void btnMesa2_MouseClick(object sender, MouseEventArgs e)
{
Form2 f2 = new Form2(this);
f2.Text = "Mesa 2";
f2.Show();
}
public void cambiarFondo()
{
btnMesa1.BackColor = Color.Green;
}
// FORM 2
public partial class Form2 : Form
{
double precio = 0;
double cantidad = 0;
double subtotal = 0;
double total = 0;
Form1 f1 = new Form1();
public Form2()
{
}
public Form2(Form1 parametro)
{
InitializeComponent();
f1 = parametro;
}
private void Form2_Load(object sender, EventArgs e)
{
DataGridViewButtonColumn colBotones = new DataGridViewButtonColumn();
colBotones.Name = "colBotones";
colBotones.HeaderText = "BORRAR";
this.Pagos.Columns.Add(colBotones);
}
private void txtCantidad_TextChanged(object sender, EventArgs e)
{
precio = Convert.ToDouble(txtPrecio.Text);
cantidad = Convert.ToDouble(txtCantidad.Text);
subtotal = precio * cantidad;
etiquetaSubTotalNum.Text = subtotal.ToString();
}
// AGREGA UN PRODUCTO
private void btnAgregarItem_Click(object sender, EventArgs e)
{
Pagos.Rows.Add(txtID.Text, txtNombre.Text, txtPrecio.Text, txtCantidad.Text, etiquetaSubTotalNum.Text);
}
// CALCULA EL VALOR TOTAL DE LA MESA E IMPRIME EL TICKET
private void btnTicket_Click(object sender, EventArgs e)
{
for (int i = 0; i < Pagos.Rows.Count; i++)
{
total += double.Parse(Pagos.Rows[i].Cells["celdaSubtotal"].Value.ToString());
}
etiquetaTotalNum.Text = total.ToString();
total = 0;
}
// CIERRA LA MESA
private void btnCerrarMesa_Click(object sender, EventArgs e)
{
this.Close();
}
// DIBUJA "BORRAR" SOBRE LOS BOTONES DE ELIMINAR
private void Pagos_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex >= 0 && this.Pagos.Columns[e.ColumnIndex].Name == "colBotones" && e.RowIndex >= 0)
{
e.Paint(e.CellBounds, DataGridViewPaintParts.All);
DataGridViewButtonCell celBoton = this.Pagos.Rows[e.RowIndex].Cells["colBotones"] as DataGridViewButtonCell;
e.Graphics.DrawString("BORRAR", new Font("Verdana", 8), new SolidBrush(Color.Red),
e.CellBounds.Left + 3, e.CellBounds.Top + 3);
e.Handled = true;
}
}
// ELIMINA LA FILA DE ESE PRODUCTO AL HACER CLICK EN EL BOTON "BORRAR"
private void Pagos_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (this.Pagos.Columns[e.ColumnIndex].Name == "colBotones")
{
Pagos.Rows.RemoveAt(Pagos.CurrentRow.Index);
}
}
// CAMBIA EL BOTON DE LA MESA A COLOR VERDE/ABIERTA
private void btnAbrirMesa_Click(object sender, EventArgs e)
{
this.btnAbrirMesa.BackColor = Color.Green;
f1.cambiarFondo();
}