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. Visual Basic
  4. Show new form without taking focus off first form

Show new form without taking focus off first form

Scheduled Pinned Locked Moved Visual Basic
helpcsharptutorialquestion
6 Posts 2 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
    carlos_rocha
    wrote on last edited by
    #1

    Hi! I read the articles related to message windows that popup but i still don't have the answer for my problem. I have a form which launches a new form (i want it to be a topMost form) but even with the ShowWindow() function the second form still gets focus.I tried a simpler example with a main form and a second that didn't contain any controls or painting code and it still gets the focus.This is my declaration of function.Am i doing anything wrong?When should i call showWindow()? _ Private Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As Int32) As Boolean End Function (...) Dim myForm2 As New Form2 ShowWindow(myForm2.Handle, 4) '4 is the SW_SHOWNOACTIVATE value This doesn't work for me (using vb.net).Can anyone help me? Never say never

    R 1 Reply Last reply
    0
    • C carlos_rocha

      Hi! I read the articles related to message windows that popup but i still don't have the answer for my problem. I have a form which launches a new form (i want it to be a topMost form) but even with the ShowWindow() function the second form still gets focus.I tried a simpler example with a main form and a second that didn't contain any controls or painting code and it still gets the focus.This is my declaration of function.Am i doing anything wrong?When should i call showWindow()? _ Private Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As Int32) As Boolean End Function (...) Dim myForm2 As New Form2 ShowWindow(myForm2.Handle, 4) '4 is the SW_SHOWNOACTIVATE value This doesn't work for me (using vb.net).Can anyone help me? Never say never

      R Offline
      R Offline
      rudy net
      wrote on last edited by
      #2

      I don't know how to avoid changing the focus to the new form, but maybe the following will help you: You should be able to use the Show() method to display the second form then call Focus() to set focus back on your primary form. Example: dim f2 as New Form2 public sub ShowForm2() if firstTime Then Me.AddOwnedForm(f2) f2.Show() Me.Focus() End Function

      C 1 Reply Last reply
      0
      • R rudy net

        I don't know how to avoid changing the focus to the new form, but maybe the following will help you: You should be able to use the Show() method to display the second form then call Focus() to set focus back on your primary form. Example: dim f2 as New Form2 public sub ShowForm2() if firstTime Then Me.AddOwnedForm(f2) f2.Show() Me.Focus() End Function

        C Offline
        C Offline
        carlos_rocha
        wrote on last edited by
        #3

        Hi! I was trying to avoid that solution, but after a whole day of searching the web and grups, maybe i'm gonna follow that way. Last night at home i was trying to accomplish this, and i kind of got it (i don't understand why this works but... :D) : I was declaring the forms locally like dim myForm2 as New Form2 and then calling the showWindow() function.But then i declared the form as a class Member: Private myForm2 as Form2 and then in the init.Components method i did myForm2 = new myForm2 and then showed the form and it worked ok!!!Why is this?What's the difference between showing a form declared locally and another that is a class member? Never say never

        C 1 Reply Last reply
        0
        • C carlos_rocha

          Hi! I was trying to avoid that solution, but after a whole day of searching the web and grups, maybe i'm gonna follow that way. Last night at home i was trying to accomplish this, and i kind of got it (i don't understand why this works but... :D) : I was declaring the forms locally like dim myForm2 as New Form2 and then calling the showWindow() function.But then i declared the form as a class Member: Private myForm2 as Form2 and then in the init.Components method i did myForm2 = new myForm2 and then showed the form and it worked ok!!!Why is this?What's the difference between showing a form declared locally and another that is a class member? Never say never

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

          Hi! I GOT IT.It was about time...i can't believe it took me a day and a half to accomplish this. :( I think the problem is in the topMost Property.After a bit of thinking, i didn't use that property in the form designer, what i simply did was this, 2 simple instructions(that's what pisses me off): ShowWindow(Me.Handle,SW_SHOWNOACTIVATE) 'SW_SHOWNOACTIVATE = 4 setWindowPos(Me.Handle,HWND_TOPMOST, XPos, YPos, myWidth, myHeight,SWP_NOACTIVATE) 'HWND_TOPMOST=-1 'SWP_NOACTIVATE=16 The first instruction tells the window how to behave when it appears. That constant tells it to not to steal the focus from other window. The second instruction places the window where you desire with your desired behaviour.Once again the constants mean that: 1-the window will appear as TopMost 2-the window will not steal the Focus AND IT WORKS FINE. Never say never

          R 1 Reply Last reply
          0
          • C carlos_rocha

            Hi! I GOT IT.It was about time...i can't believe it took me a day and a half to accomplish this. :( I think the problem is in the topMost Property.After a bit of thinking, i didn't use that property in the form designer, what i simply did was this, 2 simple instructions(that's what pisses me off): ShowWindow(Me.Handle,SW_SHOWNOACTIVATE) 'SW_SHOWNOACTIVATE = 4 setWindowPos(Me.Handle,HWND_TOPMOST, XPos, YPos, myWidth, myHeight,SWP_NOACTIVATE) 'HWND_TOPMOST=-1 'SWP_NOACTIVATE=16 The first instruction tells the window how to behave when it appears. That constant tells it to not to steal the focus from other window. The second instruction places the window where you desire with your desired behaviour.Once again the constants mean that: 1-the window will appear as TopMost 2-the window will not steal the Focus AND IT WORKS FINE. Never say never

            R Offline
            R Offline
            rudy net
            wrote on last edited by
            #5

            Thanks for sharing your findings.

            C 1 Reply Last reply
            0
            • R rudy net

              Thanks for sharing your findings.

              C Offline
              C Offline
              carlos_rocha
              wrote on last edited by
              #6

              You scratch my back, i scratch yours. PS: metaphorically speaking of course :D Never say never

              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