Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. How can I start an app with window hidden?

How can I start an app with window hidden?

Scheduled Pinned Locked Moved Windows Forms
csharphelpquestionc++css
4 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FinishedOnTime
    wrote on last edited by
    #1

    Hi Everyone, I'm a log time fan of CodeProject, former C++ guy, now C# guy. Here's what I need help with if you please: I have a Windows Forms app (C#, VS2005, .NET 2.0) with a grid control on it, the grid control will be populated with information collected from a call to a SOAP WebService. The workflow is: 1. App starts up - main window is hidden 2. App pops up a dialog asking for logon / password 3. Logon dialog hits webservice and gets back a token 3a. If user cancels login, exit application 4. Main window appears with a grid control on it that is empty 5. Main window uses token from web service to make calls to get data from webservice and display on the grid Here is my problem: I don't want the main window to appear before the user completes the process of logging on with the login dialog. However, I can't figure out how to get my application to start with my main window hidden except to launch the login dialog from the main form's constructor (gross!!). I try to use the Windows Form methods I can find like Hide() which will hide the window, but the problem is you'll see it before it gets hidden. I don't want it to appear at all until the user is done with the login window. I've tried modeless dialog for the login dialog, modeless etc. The desired effect that I can't achieve (without putting login form's instantiation and execution in the Main Form's construtor) is that you never see the main form until after login successfully completes, and if login is cancelled the program exits and you never see the main window at all. Thanks a lot for any help!

    P 1 Reply Last reply
    0
    • F FinishedOnTime

      Hi Everyone, I'm a log time fan of CodeProject, former C++ guy, now C# guy. Here's what I need help with if you please: I have a Windows Forms app (C#, VS2005, .NET 2.0) with a grid control on it, the grid control will be populated with information collected from a call to a SOAP WebService. The workflow is: 1. App starts up - main window is hidden 2. App pops up a dialog asking for logon / password 3. Logon dialog hits webservice and gets back a token 3a. If user cancels login, exit application 4. Main window appears with a grid control on it that is empty 5. Main window uses token from web service to make calls to get data from webservice and display on the grid Here is my problem: I don't want the main window to appear before the user completes the process of logging on with the login dialog. However, I can't figure out how to get my application to start with my main window hidden except to launch the login dialog from the main form's constructor (gross!!). I try to use the Windows Form methods I can find like Hide() which will hide the window, but the problem is you'll see it before it gets hidden. I don't want it to appear at all until the user is done with the login window. I've tried modeless dialog for the login dialog, modeless etc. The desired effect that I can't achieve (without putting login form's instantiation and execution in the Main Form's construtor) is that you never see the main form until after login successfully completes, and if login is cancelled the program exits and you never see the main window at all. Thanks a lot for any help!

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Unfortunately, you do need to call the login dialog before you call the code to create the main window. This could be accomplished from your static void Main() code:

      public static void Main()
      {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
      
        SecurityClass sec = new SecurityClass();
        if (sec.AuthenticateUser())
        {
          Application.Run(new MainForm(/* pass in sec if necessary */));
        }
      }
      

      Them the security class would be responsible for identifying whether or not the user was valid. This would involve displaying your login dialog. By doing this, you don't hit the Application.Run until you've validated that your user exists.

      Deja View - the feeling that you've seen this post before.

      F 1 Reply Last reply
      0
      • P Pete OHanlon

        Unfortunately, you do need to call the login dialog before you call the code to create the main window. This could be accomplished from your static void Main() code:

        public static void Main()
        {
          Application.EnableVisualStyles();
          Application.SetCompatibleTextRenderingDefault(false);
        
          SecurityClass sec = new SecurityClass();
          if (sec.AuthenticateUser())
          {
            Application.Run(new MainForm(/* pass in sec if necessary */));
          }
        }
        

        Them the security class would be responsible for identifying whether or not the user was valid. This would involve displaying your login dialog. By doing this, you don't hit the Application.Run until you've validated that your user exists.

        Deja View - the feeling that you've seen this post before.

        F Offline
        F Offline
        FinishedOnTime
        wrote on last edited by
        #3

        Thank you Pete, I did this and it works but I have a question: public static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SecurityClass sec = new SecurityClass(); if (DialogResult.Ok == sec.ShowDialog()) { if (sec.AuthenticateUser()) { Application.Run(new MainForm(/* pass in sec if necessary */)); } } } If we can open windows before we call Application.Run what does Application.Run do for us? Why do we need it at all? Online reference says this: Application.Run: Begins running a standard application message loop on the current thread, and makes the specified form visible. How is the application message loop different from the windows message queue? What happens to my app if I don't have one of these 'standard application message loop's? Thanks if anyone can explain!

        P 1 Reply Last reply
        0
        • F FinishedOnTime

          Thank you Pete, I did this and it works but I have a question: public static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SecurityClass sec = new SecurityClass(); if (DialogResult.Ok == sec.ShowDialog()) { if (sec.AuthenticateUser()) { Application.Run(new MainForm(/* pass in sec if necessary */)); } } } If we can open windows before we call Application.Run what does Application.Run do for us? Why do we need it at all? Online reference says this: Application.Run: Begins running a standard application message loop on the current thread, and makes the specified form visible. How is the application message loop different from the windows message queue? What happens to my app if I don't have one of these 'standard application message loop's? Thanks if anyone can explain!

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          If you don't call Application.Run then the application will stop as soon as it leaves the Main() method. Try it - call new MainForm() without calling the Application.Run. This will end your application before you would normally want to do this.

          Deja View - the feeling that you've seen this post before.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups