I have a main form. There is a panel in the main form. There are three buttons in total. When clicking on the "Setting" button in the main form, the panel shows up. There is a "General Setting" button on it. When clicking on it, it load the General Setting Form. When exiting this form (using the exit button), it returns to panel1, but the General Setting button is not there. Would you please help me with that.
Form1
namespace Developing_Serial_Terminal_for_Arduino_in_C_
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
//private void DisconnectFromPort_Click(object sender, EventArgs e)
//{
//if (SerPort.IsOpen)
//{
//SerPort.Close();
//MessageBox.Show("Disconnected from port.");
//ConnectToPort.Enabled = true;
//DisconnectFromPort.Enabled = false;
//}
//}
public void LoadForm(object Form)
{
if (this.panel1.Controls.Count > 0)
this.panel1.Controls.RemoveAt(0);
Form f = Form as Form;
f.TopLevel = false;
f.Dock = DockStyle.Fill;
this.panel1.Controls.Add(f);
this.panel1.Tag = f;
f.Show();
}
private void btnSetting_Click(object sender, EventArgs e)
{
panel1.Visible = true;
panel1.Show();
}
private void btnGeneralSetting_Click(object sender, EventArgs e)
{
LoadForm(new General_Setting());
//btnGeneralSetting.Visible = false;
}
}
}
And general Setting form
namespace Developing_Serial_Terminal_for_Arduino_in_C_
{
public partial class General_Setting : Form
{
private object btnGeneralSetting;
public General_Setting()
{
InitializeComponent();
}
private void btnExit_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("Do you want to Exit this page?", "Exit Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
// Close the current form
Close();
}
}
}
}