Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My first form in the app is Login, so when the user wants to login it should transfer to the main form. But, the main form is made of menu with 4 buttons where each button represents one user control form. So, what I want to do is to when the user logs in it should open the main form, but actually to open the first button (Home) - known as HomeUserControl.
How can I do this?

What I have tried:

I have tried:

In the Login.cs*

// check if user exists

           if(table.Rows.Count > 0)
           {
               this.Hide();
               MainForm mainform = new MainForm();
               mainform.Show();
           }


but when I start the project, the login works fine (it accepts the data for username and password and the button works too) but it opens a form that shows nothing.
Posted
Updated 7-Sep-19 23:14pm

1 solution

Handle the MainForm.Shown event - it fires once, the first time a form is displayed.
In there, you can call the method that the Home button Click event handler calls (and if that code is directly in the button Click handler, move it into a method and call that - that way you don;t have to update it in two places later).
 
Share this answer
 
v2
Comments
[no name] 8-Sep-19 5:37am    
Can you please simplify your comment?
I am a total beginner in this
OriginalGriff 8-Sep-19 5:50am    
What parts do you need simplified?

You know how to add a handler for a Form event, yes?
[no name] 8-Sep-19 6:04am    
No, first time working with usercontrols and events. Can you suggest some tutorials which I should read upon?
OriginalGriff 8-Sep-19 6:31am    
How did you add the Click handler to the Home button?
Same thing ... just highlight the Form in the designer, look at eth Properties pane, click the Events button (it looks like a lightning bolt) and double click the Shown event - that'll add the handler method for you ready to edit.

Try it - it's really easy.

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