Hiding form on startup [c#]

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    Hiding form on startup [c#]

    Don't get angry! I have googled and I have come across answers - but mainly inconclusive answers.

    I understand that taking the argument for new Form1() away (application.ru n()) is something I should do. But then the code in Form1 wouldn't be executed, would it? I don't quite understand how to go about doing this.
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Well, you could just put
    Code:
    this.Visible = false;
    in the constructor of the startup form.

    Just curious, why do you want to hide the form on startup?

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Originally posted by insertAlias
      Well, you could just put
      Code:
      this.Visible = false;
      in the constructor of the startup form.

      Just curious, why do you want to hide the form on startup?
      Because the form is pointless as it has no content. I am creating an app that allows me to access IP addresses I have and save them to the clipboard (makes things easier for me, I won't go into detail why).

      Is there a better way to do this?

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #4
        Console app, maybe? Depends on what the exact functionality is. Is it something you just run once, and it finishes?

        Comment

        • joedeene
          Contributor
          • Jul 2008
          • 579

          #5
          Originally posted by Markus
          Because the form is pointless as it has no content. I am creating an app that allows me to access IP addresses I have and save them to the clipboard (makes things easier for me, I won't go into detail why).

          Is there a better way to do this?
          A better way to hide the form? Not really, you can have it automatically minimized and still visible when clicked on.

          joedeene

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by joedeene
            A better way to hide the form? Not really, you can have it automatically minimized and still visible when clicked on.

            joedeene
            I meant a better way than using forms.

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              Originally posted by insertAlias
              Console app, maybe? Depends on what the exact functionality is. Is it something you just run once, and it finishes?
              Well, in the future I'm going to add functionality to it like adding IP's, etc. So I'll just leave it as is.

              Comment

              • tlhintoq
                Recognized Expert Specialist
                • Mar 2008
                • 3532

                #8
                Originally posted by Markus
                Because the form is pointless as it has no content. I am creating an app that allows me to access IP addresses I have and save them to the clipboard (makes things easier for me, I won't go into detail why).

                Is there a better way to do this?
                If you're going to make it completely invisible a notify tray icon might be handy. That way it doesn't have to appear in the start bar at all.

                Give it method for double-click that goes something like

                Code:
                                this.Visible = !this.Visible;
                to act like a show/hide toggle.

                Comment

                • Markus
                  Recognized Expert Expert
                  • Jun 2007
                  • 6092

                  #9
                  Originally posted by tlhintoq
                  If you're going to make it completely invisible a notify tray icon might be handy. That way it doesn't have to appear in the start bar at all.

                  Give it method for double-click that goes something like

                  Code:
                                  this.Visible = !this.Visible;
                  to act like a show/hide toggle.
                  Aye, I had thought of that already.

                  Markus.

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    Its not very intuitive, but actually in the form.Shown() eventhandler is the best place to put the .Visible=false. For me this provides a split second blip, just so you know it happened. (I also use that NotifyIcon). Its fast enough that I never see the window, just a disturbance in pixels.

                    The Application.Run (new Form1()); call from what I have seen follow this:

                    Constructor
                    form_Load()
                    form_Shown()

                    I like to use that last one to make sure components have been initialized and whatnot

                    Comment

                    • Curtis Rutland
                      Recognized Expert Specialist
                      • Apr 2008
                      • 3264

                      #11
                      I feel a great disturbance in the Pixels. As if millions of them suddenly cried out in terror, and were suddenly silenced.

                      Comment

                      • bkreitman
                        New Member
                        • Oct 2008
                        • 5

                        #12
                        I have found that if you create a Console App, there is no way to remove the command window from popping up during the running of the application.

                        Instead, choose a "Windows Application" but set the startup object to be "static main()" or "Sub Main", and not a form. Optionally remove the Form objects.

                        Comment

                        • abraxas005
                          New Member
                          • Dec 2011
                          • 1

                          #13
                          Just override the OnVisibleChange d method and change the visibility of the form there, like this:

                          Code:
                          protected override void OnVisibleChanged(EventArgs e)
                          {
                              base.OnVisibleChanged(e);
                              this.Visible = false;
                          }
                          And that's it! Simple and clean.

                          Comment

                          Working...