Click here to Skip to main content
15,913,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

I am creating windows application.
where I have added menu control on usercontrol and i have added that control on my other forms.

Now what i want is , from my menu when i select new form , it should hide or close previosuly open window and then it should show me next window.

But this.hide from user control on menus click event is not working

What I have tried:

private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
CallDetailsForm frmCalls = new CallDetailsForm();
frmCalls.Show();
this.Hide();
}
Posted
Updated 5-Jul-16 20:25pm
Comments
BillWoodruff 6-Jul-16 13:15pm    
This can be managed easily, but, first, we need to know your architecture here: is this an 'MDI' WinForm project, or a standard WinForm project with a 'Main Form' ?

What is your goal here: is it to let the user move "forward and back" through a sequence of Forms ... showing the next Form, and hiding the previous Form ?

When you crate a new Form inside a method ... like your code shows here ... as soon as that method ends, you have no reference to the Form that has been created.

Is creating a new Form with each menu-click REALLY what you want to do here ?

1 solution

You can't hide the form from inside the usercontrol - you don't have access to it.
Instead, create an event in your UserControl which is handled by the form and which requests the form to hide itself (and another to show it again later)

At the moment, you have no obvious way of redisplaying the form - you probably need to handle the CallDetailsForm.FormClosing event within your UserControl to indicate that something should be displayed.
 
Share this answer
 
Comments
Torakami 6-Jul-16 2:50am    
Thanks , can you show me some sample code to handle this scnerio. It would be helpful for me. Thanks
OriginalGriff 6-Jul-16 3:07am    
What code do you need?
You know how to handle an event, and how to add a handler, yes?
And you know how to create an event, I assume?
BillWoodruff 6-Jul-16 13:26pm    
fyi: one could hide/dispose a Form from within a UserControl by using the 'TopLevelControl method to get the outermost container object, but I think that's a terrible choice :)
OriginalGriff 6-Jul-16 13:56pm    
Just because you *can* do something... :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900