Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have two forms

its Form1 and Form2 :).

and the first will show is the form1 when the program is running

I just wanna ask how to execute a command or run a code when my form1 hides.


can somebody help me? because i cant find anything in the form events..


this is urgent ty.ty.ty.



pls help
Posted
Updated 24-Jun-13 16:10pm
v2
Comments
Sergey Alexandrovich Kryukov 24-Jun-13 22:25pm    
Why?
—SA
Crixalis Paul 24-Jun-13 22:28pm    
I have a program that will save the user who log in in the system and its working, but its working when login form closes so the whole program close so i want to know how to run it when the login form hides

1 solution

What's wrong with Form.Show, Form.Hide?

Here: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.aspx[^].

However, I feel the abuse in your application design, which is only natural for a person who did not yet hide or show a form. Chances are, you will need to review it. You could get more help if you explain why would you do it.

[EDIT]

After OP's clarification:

It's wasn't a good idea to hide one form and show another. Why hiding one form if you are not going to use it any longer. One pattern would be like this:

VB
' in entry-point method (Main):
Dim mainForm As Form = New FormMain()
Dim loginForm As Form = New FormAuthentication()
' implement AuthenticationFailed property
loginForm.ShowDialog()
If loginForm.AuthenticationFailed Then
	Return
End If
' application terminates, the user can tray again
' authentication successful:
Application.Run(mainForm)

In more complex variants of it, you can give a user few attempts, etc...

—SA
 
Share this answer
 
v3
Comments
Crixalis Paul 24-Jun-13 22:36pm    
I will explain it.

My Form1 is Login Form
and My Form2 is The Main Program.

So its obvious that the user must pass a login form (kind of security) before he/she enters the prgram.

and when i run the program i make both form1 and form 2 to show and the form2 is set false in the enbled property and it will only turn to true if the user pass the security and the log in form will hide.

my log in form code is ok and the codes for saving the user's name is also ok.

My only problem is that the code for saveing the user's name is embeded on the event called
FormClosing and its working.

I just wanna know if form hide is not suitable what else of event can i use to initiate the code of saving user's name without affectiong the form2.


TY -SA
Crixalis Paul 24-Jun-13 22:37pm    
AND THE FORM 2 WILL HIDE
Sergey Alexandrovich Kryukov 24-Jun-13 22:40pm    
Please see updated answer, after [EDIT]
—SA
Crixalis Paul 24-Jun-13 22:42pm    
sir can you convert it in vb.net? because your edit is made on c-csharp and im not good in that
Sergey Alexandrovich Kryukov 24-Jun-13 22:47pm    
OK, done, but next time, for such simple cases, please use:
http://converter.telerik.com/

Besides, if you need help on C#, best information is usually in C#, so a .NET developer needs to understand at least some C#.

OK, will you accept the answer formally (green button)?
Your follow-up questions will be welcome anyway...

—SA

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