Click here to Skip to main content
15,749,352 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I was making login form.
But the problem is, I want to do that any user login from his/her ID and Password then a new form will open and his name will appear on that form.
Updated 27-Dec-17 22:21pm
OriginalGriff 24-Mar-12 6:31am    
What is the problem with that?
What part of it is giving you difficulties?
Arsalaan Ahmed 24-Mar-12 7:08am    
Problem is user name Cannot appear in Next form,

On your login form do the following :
public static class Global
    public string Username;

private void btn_login(object sender, EventArg e)
    Global.Username = txtUsername.Text; // from your Login UI text box

    // your login logic 

Then you can get Global.Username in your other forms.
Share this answer
Arsalaan Ahmed 24-Mar-12 7:15am    
But I access user name is database and show next form . Only those user then enter only Correct ID and Password.
Oshtri Deka 24-Mar-12 7:28am    
5.I am afraid OP doesn't get it or hurries too much with beginners' guides.
First a friendly advice: use search tools before posting and post question when you have exhausted all other possibilities.
Don't expect to answers popping out the sky.

This is first result offered by Google.

Find a good book for C# or search the web for tutorials, there is no excuse only

in much simplified form it could be written along these lines:
//login form handles everything and 
//gets user's real name
MyLoginForm loginForm = new MyLoginForm();

//login succeeded 
if(loginForm.DialogResult == DialogResult.OK)
   MyOther frm = new MyOtherForm();
   //set forms properties, user's real name including
   //frm.PropertyToHandleUserRealName = 
Share this answer
Arsalaan Ahmed 24-Mar-12 9:16am    
After a long time i search. And many people to ask this question.

It depands to the Workflow of the application.

I prefer it for small applications:

1. Have a main form.

2. In Form_Load event:

LoginForm loginForm = new LoginForm();

while (!loginForm.IsAuthenticated)
    if (loginForm.ShowDialog() != System.Windows.Forms.DialogResult.Cancel)

//Show username

3. And a little change in LoginForm:

you need at least 2 extra properties:
public bool IsAuthenticated { get; set; }
public string UserName { get; set; }

Before closing the LoginForm check the userName and password and if they are ok, then IsAuthenticated = true; and this.UserName = UserNameTextBox.Text;

In Click event of Ok or Login button, Set:
this.DialogResult = System.Windows.Forms.DialogResult.OK;

Specify the Cancel button
Share this answer
if(textbox1.text=="admin" && textbox2.text=="admin")
Form1 ff = new Form1();;
{"Please Enter the correct Username or Password");
Share this answer

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