CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: [RESOLVED] Where to create code to limit form opening by password Visual Studio 2012

  1. #1
    Join Date
    May 2019
    Location
    Michigan
    Posts
    25

    [RESOLVED] Where to create code to limit form opening by password Visual Studio 2012

    I have an Visual Studio 2012 application that has 3 forms:

    Form 1 is the main form
    Form 2 is a settings form
    Form 3 is a password form

    I want the user to enter a password in Form 3 to open Form 1 if a password exists , otherwise just open Form 1
    I also want the user to be able to change the password (using the same Form 3) from the settings Form 2

    I haven't written any code for this - I KNOW HOW TO DO WHAT I WANT! I just need help locating where to put the
    code to prohibit Form 1 from opening unless the correct password is entered (if any).

    Thank you
    Last edited by oldGMtireman; December 17th, 2019 at 01:38 AM.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,268

    Re: Where to create code to limit form opening by password Visual Studio 2012

    Why not just set the startup form to Form3?
    [SIGPIC][/SIGPIC]
    All my Articles
    Hannes

  3. #3
    Join Date
    May 2019
    Location
    Michigan
    Posts
    25

    Re: Where to create code to limit form opening by password Visual Studio 2012

    Because it opens every time even if no password is set. I want the application to end if the main form (Form 1) is closed.
    Any other suggestions? BTW: Thank You, Merry Christmas & Happy New Year!!!

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,356

    Re: Where to create code to limit form opening by password Visual Studio 2012

    I would start by flow charting the whole thing out. A couple of things to think about:

    IIRC, whichever form you open first needs to stay open for the program to stay running. Note that this form may be hidden and still keep the app running.
    This main form may also be a form with no controls (just a hidden window) whose sole purpose is be the anchor point to contain the logic to launch the other forms.

    I'm a big believer in the model/view architecture. With MV, the forms' controls don't contain any data. Instead a single instance of the model gets passed around to the forms as they open an close.

    The model may be a class with properties and it may be a more complicated hierarchy of classes depending on the data needs.

    Each form, upon opening, loads its controls' data from the model, and saves its data to the model when closed (or not saved if canceled).

    With this approach each form only knows or cares about the model as doesn't need to know about form hierarchy or need to try to extract data from a control in another form. This is a huge benefit because storing data the old fashion way in the controls of the forms can be difficult when there are several forms, and forms that can opened by different parent forms. It can be nightmare to be in a child1 form and try to get myData1 from child1.parent2.parent4.control3, but when opened differently, it's child1.parent1.parent3.control7.

    Using the model/view approach, all this nastiness goes away because if any form needs access to myData1, it simply gets it from the model, e.g., model.myData1.
    Last edited by Arjay; December 19th, 2019 at 11:40 AM.

  5. #5
    Join Date
    May 2019
    Location
    Michigan
    Posts
    25

    Re: Where to create code to limit form opening by password Visual Studio 2012

    Thank you. I sorta took your advice. I knew about the fact that the application would close if the startup form closed. I also understand modal forms fairly well. I sometimes use them as "settings" forms when I need to keep focus on changes made to the application settings.

    I did some experimenting with the various ways to "catch" the password and I think I found the best for my application. Now I am deciding IF I want to enter the password after it has just been created / changed - OR should I wait until the application is restarted to enter it.

    I'll figure it out eventually. Thank you very much for your help. Merry Christmas and Happy New Year.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)