I have a FMain and other Form1 into the panel what is your parent, a GridView into the Form1 and I do the following:
1. I scroll the gridview with the mouse wheel and we can see that the rows move.
2. I have a KeyPress Event on the Form1 to detect that you press ESC. But when I scroll, and then press ESC I don't detect the ESC press on the Form1.
Where is the event at that time? Can someone tell me what I can do to find out?
Which event is in use
- gambafeliz
- Posts: 141
- Joined: Friday 2nd September 2022 7:50pm
- Location: I live in the same city as Picasso
Which event is in use
For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you.
- gambafeliz
- Posts: 141
- Joined: Friday 2nd September 2022 7:50pm
- Location: I live in the same city as Picasso
Re: Which event is in use
I have observed that FMain receives the ESC but how do I return ESC to Form1 without the user noticing.
Can I forward ESC from FMain to Form1 somehow? any other good solution?
Can I forward ESC from FMain to Form1 somehow? any other good solution?
For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you.
- cogier
- Site Admin
- Posts: 1126
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Which event is in use
Can you post an example program, so we can see what you mean.
- BruceSteers
- Posts: 1578
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Which event is in use
If you are in the FMain Form_KeyPress() event handler then all the Key.class info is live so you could just call the Form_KeyPress() event in Form1.
(providing they both use Form_Keypress())
In FMain you should be able to do this..
(providing they both use Form_Keypress())
In FMain you should be able to do this..
Public Sub Form_KeyPress()
Form1.Form_KeyPress()
End
Public methods with an underscore are hidden from other classes in the IDE auto-complete but they can still be used.If at first you don't succeed , try doing something differently.
BruceS
BruceS
- gambafeliz
- Posts: 141
- Joined: Friday 2nd September 2022 7:50pm
- Location: I live in the same city as Picasso
Re: Which event is in use
It seems that your proposal works.
But I return the focus to Form1 from FMain's KeyPress and then do...
with Desktop.SendKeys in FMain but I don't know how to send ESCAPE, any idea about it. Thanks.
But I return the focus to Form1 from FMain's KeyPress and then do...
with Desktop.SendKeys in FMain but I don't know how to send ESCAPE, any idea about it. Thanks.
For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you.
- gambafeliz
- Posts: 141
- Joined: Friday 2nd September 2022 7:50pm
- Location: I live in the same city as Picasso
Re: Which event is in use
Hey BruceS your proposal is amazing
For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you.
- BruceSteers
- Posts: 1578
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Which event is in use
SendKeys should not be needed Because the Key class is valid.gambafeliz wrote: ↑Thursday 10th November 2022 6:10pm It seems that your proposal works.
But I return the focus to Form1 from FMain's KeyPress and then do...
with Desktop.SendKeys in FMain but I don't know how to send ESCAPE, any idea about it. Thanks.
Ie.
in the FMain Form_KeyPress() event if Key.Code = Key.Esc and you call the Fom1.Form_KeyPress() method then Key.Code will be the same as you are still inside the FMain KeyPress event.
cool , glad it works.
Another option is to not let Form1 loose focus.
pressing a button on another form looses the form1 focus so it no longer gets the keypress event , so you could call Form1.SetFocus after any button click on the other form that steals the focus to put it back.
If at first you don't succeed , try doing something differently.
BruceS
BruceS
- gambafeliz
- Posts: 141
- Joined: Friday 2nd September 2022 7:50pm
- Location: I live in the same city as Picasso
Re: Which event is in use
But prevent me from stealing the Esc keystroke? give me an example
I tell you because I press Esc but at that moment I don't know what receives it, let's say the parent and not Form1 as I expected.
I tell you because I press Esc but at that moment I don't know what receives it, let's say the parent and not Form1 as I expected.
For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you.
- BruceSteers
- Posts: 1578
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Which event is in use
It's about what has focus.gambafeliz wrote: ↑Thursday 10th November 2022 6:55pm But prevent me from stealing the Esc keystroke? give me an example
I tell you because I press Esc but at that moment I don't know what receives it, let's say the parent and not Form1 as I expected.
If you press a button or any other control that is on FMain then that control has the focus and so does FMain.
So a keypress then goes to FMain Keypress event.
If you press a control on Form1 then Form1 has focus.
So if you have a button on FMain called, btnDoSomething it should do this..
Public Sub btnDoSomething_Click()
' run some code
Form1.SetFocus ' return focus to Form1 when finished
End
Or if you need to monitor the escape key during the function reset the focus first
Public Sub btnDoSomething_Click()
Form1.SetFocus ' return focus to Form1 before starting
' run some code
End
Maybe you have it working okay, this was just an alternative suggestion.
If at first you don't succeed , try doing something differently.
BruceS
BruceS
- gambafeliz
- Posts: 141
- Joined: Friday 2nd September 2022 7:50pm
- Location: I live in the same city as Picasso
Re: Which event is in use
Hello
First thank you all for your help. Thanks.
I'll tell you in summary:
The Form1.Form_KeyPress() proposal works but something mysterious is going on that I can't figure out. I tell you but without providing code.
I load data into a GridView and when I click on a row it reloads this GridView with another query. And when I hit ESC I go back to the previous query and load it into the same GridView. Since I remember these queries, I load them into a String array and remove or add queries based on Click or Esc.
The problem is that when I use Form1.Form_KeyPress() in FMain, it works but when it repeats the KeyPress() code in Form1, although I follow it and see that it does everything right, the GridView freezes with the data it had, and it doesn't I don't know where I don't know what happens with the data I upload.
My solution: When Esc is lost and stolen by FMain instead of using Form1.Form_KeyPress(), I use Form1.SetFocus() but this has another problem and that is that the user's Esc key is lost, and I have no choice but to to make the user think that he did not press well and when he repeats Esc then everything is fine, but this for me is a rookie mistake.
What is your opinion? Thanks.
First thank you all for your help. Thanks.
I'll tell you in summary:
The Form1.Form_KeyPress() proposal works but something mysterious is going on that I can't figure out. I tell you but without providing code.
I load data into a GridView and when I click on a row it reloads this GridView with another query. And when I hit ESC I go back to the previous query and load it into the same GridView. Since I remember these queries, I load them into a String array and remove or add queries based on Click or Esc.
The problem is that when I use Form1.Form_KeyPress() in FMain, it works but when it repeats the KeyPress() code in Form1, although I follow it and see that it does everything right, the GridView freezes with the data it had, and it doesn't I don't know where I don't know what happens with the data I upload.
My solution: When Esc is lost and stolen by FMain instead of using Form1.Form_KeyPress(), I use Form1.SetFocus() but this has another problem and that is that the user's Esc key is lost, and I have no choice but to to make the user think that he did not press well and when he repeats Esc then everything is fine, but this for me is a rookie mistake.
What is your opinion? Thanks.
For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you.