Reputation: 11
I want to Check that whether a panel have some form or not. kindly tell me the best condition. if panel have some form inside it than bool variable should be true. the code that i have write is below.Kindly answer this question as soon as possible. thanks.
this is a button click event. i want to check that when i click on a button its first check these conditions. 1. check if form have existing this form that i want to pass in it than break it and make bool variable true. 2. if it does't have than clear all form inside the panel and generate click event form inside it.
enter code here
private void btn_dashboard_Click(object sender, EventArgs e)
{
bool isOpen = false;
dash = new Dashboard();
if (panel_window_data.Controls.Equals(dash))
{
isOpen = true;
}
if (isOpen == false)
{
panel_window_data.Controls.Clear();
dash.TopLevel = false;
panel_window_data.Controls.Add(dash);
dash.Height = panel_window_data.Height;
dash.Width = panel_window_data.Width;
dash.Show();
}
}
Upvotes: 1
Views: 388
Reputation: 11
I'm using this code in every single btn, and actually works.
/*------------------------------------------------------------------*/
// to show other form inside panel in main form
users objuser = new users();
pnlobjform.Controls.Clear();
objuser.TopLevel = false;
pnlobjform.Controls.Add(objuser);
objuser.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
objuser.Dock = DockStyle.Fill;
objuser.Show();
/*---------------------------------------------------------------*/
Upvotes: 1