Reputation: 616
I have a main menu and when I click one of the buttons the menu panel should hide and the clicked one should open. This works for one button, but for my second it doesn't. Well, it shows the panel I guess, but it is empty, even though I have something in the panel.
The code is pretty simple, so I don't see where the problem is
public Form1()
{
InitializeComponent();
menu_botStrip.Text = DateTime.Now.ToString("dd/mm/yyyy h:mm tt");
panel_startMenu.Show();
panel_informationService.Hide();
panel_customerManagement.Hide();
}
private void btn_informationService_Click(object sender, EventArgs e)
{
panel_startMenu.Hide();
panel_informationService.Show();
}
private void btn_customerManagement_Click(object sender, EventArgs e)
{
panel_startMenu.Hide();
panel_customerManagement.Show();
}
Upvotes: 5
Views: 17817
Reputation: 2496
I agree with @MD.Unicorn, you must be careful about ordering those panels on your form (layer context). This means that if your panel contains another panel or panels - after hiding specific parent you will hide and all child components also.
Upvotes: -1
Reputation: 18443
Make sure that you did not put the second panel inside the first panel. If you dragged the panels from the toolbox, there is high probability of this.
To make sure, open the Document Outline
window (View->Other Windows->Document Outline), and look at the relation between panels. Make sure that they are not contained in one another. They must be at the same level of nesting.
If it is like this:
then select the inner panel and press the left arrow button above the window. Then it should look like:
which is the correct one.
Upvotes: 37
Reputation: 629
Shouldn't be the first panel (information service) be hidden again? Maybe there's an ugly overlay if both are shown at the same time ...
private void btn_informationService_Click(object sender, EventArgs e)
{
panel_startMenu.Hide();
panel_customerManagement.Hide();
panel_informationService.Show();
}
private void btn_customerManagement_Click(object sender, EventArgs e)
{
panel_startMenu.Hide();
panel_informationService.Hide();
panel_customerManagement.Show();
}
Upvotes: 0