La cosa es así:
Tengo dos formularios, Form1
y Form2
.
Form1
es el pricipal y tiene 20 botones el cual cada uno representa una mesa diferente de mi restaurante. Al hacer click en cualquier de ellos se abre un Form2
en el cual se pueden registrar pedidos, etc ... Cada form2
contiene también un botón de Titulo Abrir Mesa
el cual necesito que cuando sea clickeado me cambie el color de fondo del botón MESA 1
en el Form1
. Si el botón Abrir mesa
de MESA 2
es clickeado, entonces necesito que sea ÉSTE y no el de MESA 1
el que cambie de color, y así sucesivamente.
He creado esto que me funciona solamente para el primer botón, o sea el de MESA1
pero no logro congeniar algo que ande para todos.
Dejo un poco de código a ver si alguien me puede ayudar.
Desde ya muchas gracias!
// 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();
}