dakota97
Centurion
Hi all,
What I'm trying to do is dynamically add menu items to a menubar. I've got the code working, but now I'm trying to add an event handler to the menuitem so that when the user clicks on it, it opens the correct form. The problem is, the program doesn't know that the form exists. So, while creating the menuitem, I've inserted the name of the form that it should open into the tag property.
The problem that I'm having is converting the tag value into a form, so that the correct form is opened. I've tried the following code (setting the tag value to the name of one of my forms), but it's not working for me, as the SelectedForm is showing up as null during runtime
Is there a way the I can convert (or cast) the ClickedMenu.Tag to a form so that I can show the correct form?
Thanks in advance,
Chris
What I'm trying to do is dynamically add menu items to a menubar. I've got the code working, but now I'm trying to add an event handler to the menuitem so that when the user clicks on it, it opens the correct form. The problem is, the program doesn't know that the form exists. So, while creating the menuitem, I've inserted the name of the form that it should open into the tag property.
The problem that I'm having is converting the tag value into a form, so that the correct form is opened. I've tried the following code (setting the tag value to the name of one of my forms), but it's not working for me, as the SelectedForm is showing up as null during runtime
Code:
private void OpenForm(object sender, System.EventArgs e)
{
MenuItem ClickedMenu = sender as MenuItem;
ClickedMenu.Tag = "Splash";
Form SelectedForm = new Form();
SelectedForm = ClickedMenu.Tag as Form;
SelectedForm.ShowDialog();
}
Is there a way the I can convert (or cast) the ClickedMenu.Tag to a form so that I can show the correct form?
Thanks in advance,
Chris