Click here to Skip to main content
15,914,014 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to display Form2 by click button in Form1 Pin
xingselex17-Jun-09 6:08
xingselex17-Jun-09 6:08 
GeneralRe: how to display Form2 by click button in Form1 Pin
musefan17-Jun-09 6:11
musefan17-Jun-09 6:11 
GeneralRe: how to display Form2 by click button in Form1 Pin
xingselex17-Jun-09 6:17
xingselex17-Jun-09 6:17 
GeneralRe: how to display Form2 by click button in Form1 Pin
musefan17-Jun-09 6:21
musefan17-Jun-09 6:21 
GeneralRe: how to display Form2 by click button in Form1 Pin
xingselex17-Jun-09 6:35
xingselex17-Jun-09 6:35 
GeneralRe: how to display Form2 by click button in Form1 Pin
musefan17-Jun-09 6:42
musefan17-Jun-09 6:42 
GeneralRe: how to display Form2 by click button in Form1 Pin
xingselex17-Jun-09 6:52
xingselex17-Jun-09 6:52 
GeneralRe: how to display Form2 by click button in Form1 Pin
musefan17-Jun-09 7:37
musefan17-Jun-09 7:37 
well let me give you a quick idea of how you might want to handle an application with a login ability.

So assuming you only have two forms (Form1 for you application stuff, Form2 for you login)

go to your Main function, which you will probably find is your Program Class...

you should have a line of code like

Application.Run(new Form1());


which is always called on start-up. Basically you want to only use that line of code if the login is successful (as decided by your Form2)

First add a class level public static bool to test for login page to be shown or not...

public static bool ShowLogin = true;



so have something like this in your Main class...


while(ShowLogin)
{
  Form2 loginForm = new Form2();
  if(loginForm.ShowDialog() == DialogResult.OK)//login has passed
    Application.Run(new Form1());
  else
    ShowLogin = false;//or break; or return;
}


Then, in Form2, if the user clicks login and it is succesful use the following code..

this.DialogResult = DialogResult.OK;
this.Close();


else, if the user clicks cancel (which should quit the application) then use this code...

this.DialogResult = DialogResult.Cancel;
this.Close();


now in your Form1 you have your case for 'logoff' or 'exit'. use this code...

case "LOGOFF":
this.Close();
break;
case "EXIT":
Program.ShowLogin = false;
this.Close();
break;


That should now be all you need for a basic login facility for your application

Life goes very fast. Tomorrow, today is already yesterday.

GeneralRe: how to display Form2 by click button in Form1 Pin
Christian Graus17-Jun-09 13:43
protectorChristian Graus17-Jun-09 13:43 
QuestionVerifying SSL Certificate for https Link Pin
singhdurgesh17-Jun-09 5:38
singhdurgesh17-Jun-09 5:38 
AnswerRe: Verifying SSL Certificate for https Link Pin
singhdurgesh18-Jun-09 1:24
singhdurgesh18-Jun-09 1:24 
QuestionMultiple Object Type Serialization Pin
David Muir17-Jun-09 5:34
David Muir17-Jun-09 5:34 
AnswerRe: Multiple Object Type Serialization Pin
I Believe In GOD17-Jun-09 8:41
I Believe In GOD17-Jun-09 8:41 
GeneralRe: Multiple Object Type Serialization Pin
David Muir17-Jun-09 22:46
David Muir17-Jun-09 22:46 
GeneralRe: Multiple Object Type Serialization Pin
I Believe In GOD18-Jun-09 4:28
I Believe In GOD18-Jun-09 4:28 
QuestionWindows service. Mobile service? Pin
Yosh_17-Jun-09 4:41
professionalYosh_17-Jun-09 4:41 
AnswerRe: Windows service. Mobile service? Pin
Matt Cavanagh17-Jun-09 5:21
Matt Cavanagh17-Jun-09 5:21 
GeneralRe: Windows service. Mobile service? Pin
Yosh_17-Jun-09 5:37
professionalYosh_17-Jun-09 5:37 
GeneralRe: Windows service. Mobile service? Pin
Matt Cavanagh17-Jun-09 5:44
Matt Cavanagh17-Jun-09 5:44 
Questioncreating crystal report by passing multiple parameter in store procedure Pin
pupilstuff17-Jun-09 4:12
pupilstuff17-Jun-09 4:12 
AnswerRe: creating crystal report by passing multiple parameter in store procedure Pin
Michael Bookatz17-Jun-09 4:23
Michael Bookatz17-Jun-09 4:23 
QuestionReading from resource file in C# through access violation exception sometimes Pin
cancerion17-Jun-09 3:54
cancerion17-Jun-09 3:54 
AnswerRe: Reading from resource file in C# through access violation exception sometimes Pin
Michael Bookatz17-Jun-09 4:09
Michael Bookatz17-Jun-09 4:09 
GeneralRe: Reading from resource file in C# through access violation exception sometimes Pin
Luc Pattyn17-Jun-09 4:24
sitebuilderLuc Pattyn17-Jun-09 4:24 
JokeRe: Reading from resource file in C# through access violation exception sometimes Pin
Michael Bookatz17-Jun-09 4:28
Michael Bookatz17-Jun-09 4:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.