none
Run query before opening form RRS feed

  • Question

  • When I run my c# forms project, I need to open one of two forms, and to do so I need to run a query to see if its the users' first use.  Where should I run this query from?   
    Wednesday, August 7, 2019 12:20 PM

Answers

  • Hi RichardDunneBsc,

    Welcome to the MSDN forum.

    You can see which form was originally called directly in the Program.cs file just like Simple and Viorel_ said.

    You can see which form is in first use.

    l hope it could help you.

    Best Regards,

    Perry



    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Thursday, August 8, 2019 8:57 AM

All replies

  • In case of C#, see the Program.cs file from your solution, where you can use Application.Run with one of two forms.


    • Edited by Viorel_MVP Wednesday, August 7, 2019 2:02 PM
    Wednesday, August 7, 2019 2:01 PM
  • As Viorel indicated, in the Program class in the Program.cs file there is a statement such as:

    Application.Run(new Form1());

    That is what causes the form to be shown. More technically, the Run method creates a message loop. Typically every Windows Forms application needs one and only one message loop.

    So you can do the query before the run method. One problem is, what to do if there is a problem with the query. You can use message boxes to show errors. If you need something better to show errors then you can create a form to do that but then you will likely need a separate message loop for it. Or you can show the error form in place of either of the other forms. And that is what you will need to do to show either one of the two forms.

    There is another possibility that is relatively advanced. Let us know if you have questions or concerns.



    Sam Hobbs
    SimpleSamples.Info

    Wednesday, August 7, 2019 6:06 PM
  • Hi RichardDunneBsc,

    Welcome to the MSDN forum.

    You can see which form was originally called directly in the Program.cs file just like Simple and Viorel_ said.

    You can see which form is in first use.

    l hope it could help you.

    Best Regards,

    Perry



    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Thursday, August 8, 2019 8:57 AM
  • Thanks for the comments.  I got it working.  I ran a database query in Program.cs and depending on the result, if true open one form, if false open a different form.
    Thursday, August 8, 2019 9:14 AM
  • Ran into a bit or trouble.  I realized that I had a class member in the wrong class, so I need to use a different class.  Now I can't access any classes from Program.cs.  The name "ClassName" does not exist in the current context.  All the classes are in the same namespace.  Any ideas?
    Thursday, August 8, 2019 6:12 PM
  • I have no idea.


    Sam Hobbs
    SimpleSamples.Info

    Thursday, August 8, 2019 7:40 PM
  • Sorted out that issue.  
    Thursday, August 8, 2019 8:57 PM
  • Hi RichardDunneBSc,

    We are glad to hear that you issue is solved.

    To help other community members deal the similar issues, please write a reply about how to solve the issue and mark is as answer.

    Thanks for your understanding.

    Best Regards,

    Perry


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Friday, August 9, 2019 2:07 AM