Is there anyway to execute code after Form.Show()? What I am doing is a small menu that will popup after user clicks the mouse right click and if I use Form.ShowDialog() I can’t click anywhere but on that menu and it should be that if I clicked anywhere not on the menu the menu should disappear and that can only happen on Form.Show().
After Form.Show() I am adding info to the database that is why Form.Show() is the only thing that suits my situation.
Code:
if (e.Button == MouseButtons.Right)
{
if (Application.OpenForms["frm_Options"] == null)
{
frm_Options ofrm = new frm_Options();
ofrm.StartPosition = FormStartPosition.Manual;
ofrm.SetBounds(MousePosition.X + 5, MousePosition.Y + 5, ofrm.Width, ofrm.Height);
ofrm.ShowDialog();
}
}
}
In the other form:
{
TreeNode oTreeNode = new TreeNode("New Node");
frm_Test ofrm = (frm_Test)Application.OpenForms["frm_Test"];
//updateTreeView is custom event created on ther main form
ofrm.updateTreeView(false, false, oTreeNode);
this.Close();
}
Considering that you’re talking about
ContextMenu, means that only one form can appear in single moment. That means that if you can useShow()non blocking call. If user clicks anywhere outside of the form, you can close it, if it was already opened before. If user clicks on the form, or on any control on it (if there is any) you can raise an event (kind ofContextMenuFormControlClickedthat main window recieves and executes necessary action (in your case DB acess).Hope this helps.