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. Windows Forms z-order?

Windows Forms z-order?

Scheduled Pinned Locked Moved Windows Forms
winformshelpquestion
10 Posts 4 Posters 0 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.
  • C Offline
    C Offline
    Cyrilix
    wrote on last edited by
    #1

    I am essentially running an application that creates a thread to run a Form, say Form1 by calling...

    Application.Run(new Form1()); //new thread has already been created and this is run on that new thread

    Then, the application runs another process. This creates a Form, say Form2 in the same way that Form1 was created, by calling Application.Run(). The problem is that Form1 is on top of Form2, even though right before the Application.Run() call of Form2, I call BringToFront(), which is supposed to place it at the front of the z-order. Why is Form1 on top of Form2 even though Form2 was created afterwards, and explicitly brought to the front? I would like to do this without having to call SendToBack() on Form1, since I don't want to send it all the way back, I just want it to be behind Form2.

    C M 2 Replies Last reply
    0
    • C Cyrilix

      I am essentially running an application that creates a thread to run a Form, say Form1 by calling...

      Application.Run(new Form1()); //new thread has already been created and this is run on that new thread

      Then, the application runs another process. This creates a Form, say Form2 in the same way that Form1 was created, by calling Application.Run(). The problem is that Form1 is on top of Form2, even though right before the Application.Run() call of Form2, I call BringToFront(), which is supposed to place it at the front of the z-order. Why is Form1 on top of Form2 even though Form2 was created afterwards, and explicitly brought to the front? I would like to do this without having to call SendToBack() on Form1, since I don't want to send it all the way back, I just want it to be behind Form2.

      C Offline
      C Offline
      CodeChurn
      wrote on last edited by
      #2

      Can you post what you are exactly trying to do? Do you want to just create 2 forms?

      C 1 Reply Last reply
      0
      • C Cyrilix

        I am essentially running an application that creates a thread to run a Form, say Form1 by calling...

        Application.Run(new Form1()); //new thread has already been created and this is run on that new thread

        Then, the application runs another process. This creates a Form, say Form2 in the same way that Form1 was created, by calling Application.Run(). The problem is that Form1 is on top of Form2, even though right before the Application.Run() call of Form2, I call BringToFront(), which is supposed to place it at the front of the z-order. Why is Form1 on top of Form2 even though Form2 was created afterwards, and explicitly brought to the front? I would like to do this without having to call SendToBack() on Form1, since I don't want to send it all the way back, I just want it to be behind Form2.

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        Why are you using Application.Run(Form2). This will create 2 discreet applications and they have nothing to do with each other - I think. Z order is for controls on a form and will have no effect between forms.

        Never underestimate the power of human stupidity RAH

        C 1 Reply Last reply
        0
        • C CodeChurn

          Can you post what you are exactly trying to do? Do you want to just create 2 forms?

          C Offline
          C Offline
          Cyrilix
          wrote on last edited by
          #4

          Create one form with one process. Then, when the second form is created, have it be on top of the form created by the first process. I don't know why that's not happening.

          Process1 -> Creates new thread -> Runs first form on new thread
          -> Executes another process "Process2" (completely independent of Process1) -> Runs second form

          1 Reply Last reply
          0
          • M Mycroft Holmes

            Why are you using Application.Run(Form2). This will create 2 discreet applications and they have nothing to do with each other - I think. Z order is for controls on a form and will have no effect between forms.

            Never underestimate the power of human stupidity RAH

            C Offline
            C Offline
            Cyrilix
            wrote on last edited by
            #5

            Well, that's the point -- they shouldn't have anything to do with each other, however, the second application's form should still be on top of the first application's form, right? I thought that this would happen by default, since when you open up a new application, it should be the new application we're looking at, and as such, shouldn't be hidden by something that already existed. For example, if I open up notepad. Then I open up Firefox, I won't be able to see notepad anymore. I want to do the same thing here. The only difference is that the first application's form is covering up the second application's form when the second application's form is loaded.

            M 1 Reply Last reply
            0
            • C Cyrilix

              Well, that's the point -- they shouldn't have anything to do with each other, however, the second application's form should still be on top of the first application's form, right? I thought that this would happen by default, since when you open up a new application, it should be the new application we're looking at, and as such, shouldn't be hidden by something that already existed. For example, if I open up notepad. Then I open up Firefox, I won't be able to see notepad anymore. I want to do the same thing here. The only difference is that the first application's form is covering up the second application's form when the second application's form is loaded.

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              I guess there is a good design reason for what you are attempting but it seems really weird to me. I'm sure you are going to run into domain issues (obviously you are already). Your example of opening 2 DIFFERENT applications is not valid. You are attempting to launch 2 forms as applications from the same stub. Even if you are opening 2 copies of notepad they are copies not the same exe. A closer example would be word where each document is treated as an application. How it's done I do not know.

              Never underestimate the power of human stupidity RAH

              C 1 Reply Last reply
              0
              • M Mycroft Holmes

                I guess there is a good design reason for what you are attempting but it seems really weird to me. I'm sure you are going to run into domain issues (obviously you are already). Your example of opening 2 DIFFERENT applications is not valid. You are attempting to launch 2 forms as applications from the same stub. Even if you are opening 2 copies of notepad they are copies not the same exe. A closer example would be word where each document is treated as an application. How it's done I do not know.

                Never underestimate the power of human stupidity RAH

                C Offline
                C Offline
                Cyrilix
                wrote on last edited by
                #7

                Even if you are opening 2 copies of notepad they are copies not the same exe.

                Yes, I understand that they are copies, even if you run the same executable twice. What I don't understand, however, is what you mean by "2 forms as applications from the same stub". My first form is being launched from the process I double-clicked. That one's pretty simple to understand. My second form is being launched when I create another process, so from what I understand, it is completely separate, since I'm only using the first process to call the second process. Let me see if I can give an example of this... it would sort of be like cmd.exe. When you run it, a form pops up that's designed to be like a command prompt. Then, you enter some text into this command prompt, say "notepad.exe", and it opens up notepad as a new process, and the form of notepad is on top of the form for the command prompt. If my example is not a good one, could you please elaborate further? What I just gave above seems to make logical sense to me...

                M S 2 Replies Last reply
                0
                • C Cyrilix

                  Even if you are opening 2 copies of notepad they are copies not the same exe.

                  Yes, I understand that they are copies, even if you run the same executable twice. What I don't understand, however, is what you mean by "2 forms as applications from the same stub". My first form is being launched from the process I double-clicked. That one's pretty simple to understand. My second form is being launched when I create another process, so from what I understand, it is completely separate, since I'm only using the first process to call the second process. Let me see if I can give an example of this... it would sort of be like cmd.exe. When you run it, a form pops up that's designed to be like a command prompt. Then, you enter some text into this command prompt, say "notepad.exe", and it opens up notepad as a new process, and the form of notepad is on top of the form for the command prompt. If my example is not a good one, could you please elaborate further? What I just gave above seems to make logical sense to me...

                  M Offline
                  M Offline
                  Mycroft Holmes
                  wrote on last edited by
                  #8

                  Same issues applies, you are running cmd.exe to get the dos prompt and from there you want to run notepad.exe. You are hitting 2 different exe files. Your application compiles into 1 exe and from that your want to run 2 applications. Do you want 2 apps or do you want 1 app with 2 threads.

                  Never underestimate the power of human stupidity RAH

                  1 Reply Last reply
                  0
                  • C Cyrilix

                    Even if you are opening 2 copies of notepad they are copies not the same exe.

                    Yes, I understand that they are copies, even if you run the same executable twice. What I don't understand, however, is what you mean by "2 forms as applications from the same stub". My first form is being launched from the process I double-clicked. That one's pretty simple to understand. My second form is being launched when I create another process, so from what I understand, it is completely separate, since I'm only using the first process to call the second process. Let me see if I can give an example of this... it would sort of be like cmd.exe. When you run it, a form pops up that's designed to be like a command prompt. Then, you enter some text into this command prompt, say "notepad.exe", and it opens up notepad as a new process, and the form of notepad is on top of the form for the command prompt. If my example is not a good one, could you please elaborate further? What I just gave above seems to make logical sense to me...

                    S Offline
                    S Offline
                    SiFitz
                    wrote on last edited by
                    #9

                    I think that that Form.Activate method might do what you require. This brings a form to the front of Windows so that it would appear on top of anything that you have open. I have been using this from a notiify icon so that that double clicking the icon will bring the form to the z-order of all open windows apps. I assume this will work for threads within the same application but I haven't tried that (I'm not too familiar with threading code)

                    Bye.

                    C 1 Reply Last reply
                    0
                    • S SiFitz

                      I think that that Form.Activate method might do what you require. This brings a form to the front of Windows so that it would appear on top of anything that you have open. I have been using this from a notiify icon so that that double clicking the icon will bring the form to the z-order of all open windows apps. I assume this will work for threads within the same application but I haven't tried that (I'm not too familiar with threading code)

                      Bye.

                      C Offline
                      C Offline
                      Cyrilix
                      wrote on last edited by
                      #10

                      Hi, This worked for me. What I was doing before was:

                      Form2 form2 = new Form2();
                      form2.BringToFront();
                      Application.Run(form2);

                      Then, I tried:

                      Form2 form2 = new Form2();
                      form2.Activate();
                      Application.Run(form2);

                      This didn't work either, so I tried:

                      Form2 form2 = new Form2();
                      Application.Run(form2); //after this, call Activate() on the Form's Load event

                      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