2

Ive got a basic questions about windows forms, im designing a app in visual c# express, It needs a login, heres where im stuck,

Take msn messenger loads up and you get the use/pass prompt, put the details in and then you get your contacts,

How would you replicate something like that

in the simpilist form is this 2 seperate forms? ie a login form and a contact form? or is this one form with dynamic controls? etc

squareborg
  • 1,562
  • 14
  • 18
  • 1
    In its simplest form, it would be 2 yes. You'd load the application showing the login screen, they'd enter their details and then you'd authenticate them. Once that's successful, you load the main form of the application. EDIT: Putting this as a comment as I'm sure someone can give you a more elegant solution overall. – Delebrin Jun 09 '11 at 20:18
  • Thanks, im coming from a php/html background so im not clued on winforms atall, in your opinion, Im going to go back to msn messenger here but whe you sign in msn keeps the same height width and screen position as the login, is this possible using two forms? – squareborg Jun 09 '11 at 20:24
  • You should be able to set the height, width, and screen position of the form to match the login form when it loads. I'm work primarily in web apps, so I'd be a little rusty in trying to provide code simples for win forms. But it's definitely possible. – Delebrin Jun 09 '11 at 20:39

2 Answers2

1

Since no one else has posted an answer yet, I'll go ahead and move my comments to here. Hopefully someone can provide more insight still.

In its simplest form, it would be 2 yes. You'd load the application showing the login screen, they'd enter their details and then you'd authenticate them. Once that's successful, you load the main form of the application.

You should then be able to set any options on the second (main) form when you show it, such as its height, width, or screen position as desired.

As a reference and possible starting point on opening one form from another, check out this question: Open Form2 from Form1, close Form1 from Form2

Hopefully that'll help get you started.

Community
  • 1
  • 1
Delebrin
  • 1,049
  • 4
  • 11
  • 19
0

This is what I'd suggest:

  1. Have a central form in your application, you could call it "frmMain" for-the-purpose-of-discussion, and ensure that this form is the first thing that loads up on application start-up -

    Program { Main() { Application.Run(frmMain()); } }

  2. Next, define a central app-level properties management class, FTPOD - "AppProperties"

  3. Define, configure and manage the logged in users' entity in this class
  4. This is so that, if the user is logged in then the details like login-name, id, email address, etcetera can be easily accessed at any time in the application life-span i.e., from any form
  5. Have a method in this class to check whether a user is logged in or not, FTPOD - "IsUserAuthenticated"
  6. Now when the Form_Load event of the "frmMain" is invoked, check if the user is logged-in
  7. If not then open a new form for requesting the user for login credentials, FTPOD - "frmLogin"

``

frmLogin login = new frmLogin()
login.ShowDialog(this);
login = null;
  1. Manage your authentication/login logic in this form ("frmLogin"), or as relevant in its business logic
  2. Upon successful authentication, set the users' entity in the "AppProperties" class and then close the from
  3. Then from the "frmMain" class (once authenticated) open your main functioning form
Tathagat Verma
  • 549
  • 7
  • 12