What I want to do is move from one form to another. I call from MenuForm to another call "EmfermoRep", which is fine, but the problem comes when I want to go back from "EnfermoRep" to "MenuForm". I tried to add a button and instantiate "MenuForm", but it sent me that error which is an infinite loop. Some ideas to come back, I would really appreciate it: D!
public partial class MenuForm : Form
{
Ventanas v = new Ventanas();
EnfermoRep reporteEnfermo = new EnfermoRep();
public MenuForm()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void rptEnfermo_Click(object sender, EventArgs e)
{
v.CargarVentana(reporteEnfermo, this.panel1);
}
}
EnfermoRep Class:
public partial class EnfermoRep : Form
{
Ventanas v = new Ventanas();
MenuForm menuForm = new MenuForm();
public EnfermoRep()
{
InitializeComponent();
}
private void EnfermoRep_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'bd.Enfermo' table. You can move, or remove it, as needed.
this.EnfermoTableAdapter.Fill(this.bd.Enfermo);
this.reportViewer1.RefreshReport();
}
private void btnVolver1_Click(object sender, EventArgs e)
{
v.CargarVentanas(menuForm, this.enfermoRep);
}
}
It is worth mentioning that I created a class called windows, which allows me to move in Forms through panels (In other words, the program only has one main Form, which calls other but with panels, without ever leaving the main one) No I know if I can understand -.- '
This is the class that allows that:
class Ventanas
{
public void CargarVentana(object sonform, Panel panel)
{
panel.Controls.Clear();
Form fh = sonform as Form;
fh.TopLevel = false;
fh.FormBorderStyle = FormBorderStyle.None;
fh.Dock = DockStyle.Fill;
panel.Controls.Add(fh);
panel.Tag = fh;
fh.Show();
}
}