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. How do I get the currently running form or dialog in my application using VB.Net?

How do I get the currently running form or dialog in my application using VB.Net?

Scheduled Pinned Locked Moved Visual Basic
helpquestioncsharpcareer
10 Posts 3 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.
  • P Offline
    P Offline
    Polymorpher
    wrote on last edited by
    #1

    Ok, basically it goes something like this, I have written a key logger of sorts for my application. What it does is to trap the F1-F12 keys, when they are pressed it raises an event letting me know which one was pressed. I need to be able to call the appropriate sub in whatever form or dialog is currently running in my application. Any ideas? Thanks in advance for any help guys.

    -- "Keyboard not found. Press < F1 > to RESUME. " Source unknown (appears in many common BIOSes as a real error message)

    D N 3 Replies Last reply
    0
    • P Polymorpher

      Ok, basically it goes something like this, I have written a key logger of sorts for my application. What it does is to trap the F1-F12 keys, when they are pressed it raises an event letting me know which one was pressed. I need to be able to call the appropriate sub in whatever form or dialog is currently running in my application. Any ideas? Thanks in advance for any help guys.

      -- "Keyboard not found. Press < F1 > to RESUME. " Source unknown (appears in many common BIOSes as a real error message)

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Form.ActiveForm will return the form with the focus in your app.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      P 2 Replies Last reply
      0
      • D Dave Kreskowiak

        Form.ActiveForm will return the form with the focus in your app.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        P Offline
        P Offline
        Polymorpher
        wrote on last edited by
        #3

        Thanks alot :)

        -- "Keyboard not found. Press < F1 > to RESUME. " Source unknown (appears in many common BIOSes as a real error message)

        1 Reply Last reply
        0
        • D Dave Kreskowiak

          Form.ActiveForm will return the form with the focus in your app.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          P Offline
          P Offline
          Polymorpher
          wrote on last edited by
          #4

          This doesn't seem to be working...It keeps returning nothing from form.activeform...here is a link that shows the debug i was doing: My Debug Session

          -- "Keyboard not found. Press < F1 > to RESUME. " Source unknown (appears in many common BIOSes as a real error message)

          D 1 Reply Last reply
          0
          • P Polymorpher

            This doesn't seem to be working...It keeps returning nothing from form.activeform...here is a link that shows the debug i was doing: My Debug Session

            -- "Keyboard not found. Press < F1 > to RESUME. " Source unknown (appears in many common BIOSes as a real error message)

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            How about Me.ActiveForm. Of course, that will only work if the code is in a form class. It won't work outside of a form.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            P 1 Reply Last reply
            0
            • D Dave Kreskowiak

              How about Me.ActiveForm. Of course, that will only work if the code is in a form class. It won't work outside of a form.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007

              P Offline
              P Offline
              Polymorpher
              wrote on last edited by
              #6

              It is under a modual with my Sub Main. The only way I could make it work so far is to use Private Sub mKeyLogger_KeyPressed(ByVal theKey As System.Windows.Forms.Keys, ByVal isDown As Boolean) Handles mKeyLogger.KeyPressed If isDown Then Dim f As Form = mFrmMain.ActiveMdiChild If Not f Is Nothing Then If TypeOf f Is IHandlesDirectInput Then DirectCast(f, IHandlesDirectInput).HandleInput(theKey, isDown) End If End If End If End Sub The problem with this is that it limits me to only MDI childre, and not a dialog that could be showing...I need the top level form or dialog at the time the key is pressed so that I can dispatch the key directly to that form or dialog and let it handle it.

              -- "Keyboard not found. Press < F1 > to RESUME. " Source unknown (appears in many common BIOSes as a real error message)

              D 1 Reply Last reply
              0
              • P Polymorpher

                Ok, basically it goes something like this, I have written a key logger of sorts for my application. What it does is to trap the F1-F12 keys, when they are pressed it raises an event letting me know which one was pressed. I need to be able to call the appropriate sub in whatever form or dialog is currently running in my application. Any ideas? Thanks in advance for any help guys.

                -- "Keyboard not found. Press < F1 > to RESUME. " Source unknown (appears in many common BIOSes as a real error message)

                N Offline
                N Offline
                nlarson11
                wrote on last edited by
                #7

                Expand the event to include the form object so that you can call it's routine

                1 Reply Last reply
                0
                • P Polymorpher

                  Ok, basically it goes something like this, I have written a key logger of sorts for my application. What it does is to trap the F1-F12 keys, when they are pressed it raises an event letting me know which one was pressed. I need to be able to call the appropriate sub in whatever form or dialog is currently running in my application. Any ideas? Thanks in advance for any help guys.

                  -- "Keyboard not found. Press < F1 > to RESUME. " Source unknown (appears in many common BIOSes as a real error message)

                  N Offline
                  N Offline
                  nlarson11
                  wrote on last edited by
                  #8

                  better yet, expand the event and pass the delegate that you want the logger to call...

                  P 1 Reply Last reply
                  0
                  • N nlarson11

                    better yet, expand the event and pass the delegate that you want the logger to call...

                    P Offline
                    P Offline
                    Polymorpher
                    wrote on last edited by
                    #9

                    As is ANY form implementing the interface WILL be called if it is in the front, except for dialogs...There is no way to expand the event to include the form, the event is fired from the key logger which has no knowledge of the form that will receive the event. The key logger simply sees the trapped key being pressed and raises an event saying it was pressed and letting me know if its state is up or down. passing delegates would require the form to know about the key logger and the key logger to know about the form, violating the principle of least privilege...besides if there was a way of knowing which form is in front from the key logger, then the same can be done from the event, its just a matter of how to find the current form or dialog that is running in the front of the application.

                    -- "Keyboard not found. Press < F1 > to RESUME. " Source unknown (appears in many common BIOSes as a real error message)

                    1 Reply Last reply
                    0
                    • P Polymorpher

                      It is under a modual with my Sub Main. The only way I could make it work so far is to use Private Sub mKeyLogger_KeyPressed(ByVal theKey As System.Windows.Forms.Keys, ByVal isDown As Boolean) Handles mKeyLogger.KeyPressed If isDown Then Dim f As Form = mFrmMain.ActiveMdiChild If Not f Is Nothing Then If TypeOf f Is IHandlesDirectInput Then DirectCast(f, IHandlesDirectInput).HandleInput(theKey, isDown) End If End If End If End Sub The problem with this is that it limits me to only MDI childre, and not a dialog that could be showing...I need the top level form or dialog at the time the key is pressed so that I can dispatch the key directly to that form or dialog and let it handle it.

                      -- "Keyboard not found. Press < F1 > to RESUME. " Source unknown (appears in many common BIOSes as a real error message)

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #10

                      Well, it's definately not working as advertised. I never use it, so all I have to go on is the documentation. Hmmm... Well. Quick and drity, it's possible to set a Shared variable from the Form.Activate event of each form you want to handle.

                      A guide to posting questions on CodeProject[^]
                      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                           2006, 2007

                      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