How do I get the currently running form or dialog in my application using VB.Net?
-
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)
-
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)
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 -
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, 2007Thanks alot :)
-- "Keyboard not found. Press < F1 > to RESUME. " Source unknown (appears in many common BIOSes as a real error message)
-
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, 2007This 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)
-
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)
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 -
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, 2007It 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)
-
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)
-
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)
-
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)
-
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)
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