473,386 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Form_Keydown being overridden

I'm having a weird problem with the Keydown event.

- I have a form with the KeyPreview property set to true
- I have a Form_KeyDown sub that does a bit of code for me
- I have a few control buttons on the form

Now comes the weird part. When I first launch the form, it intercepts the
key presses no problem (i'm capturing the arrow keys). However, when I click
on a button, the form no longer fires off the keydown event, pressing the
left arrow, for example, will start cycling through the other buttons.

Is there a way to return the focus or control to the form so it can capture
the arrow's being pressed and run the form_keydown code?
Jul 11 '06 #1
5 1177
There is a property on the Form that must be set.. I think it is KeyPreview
(I don't have VS up and running now). That allows the form to see it before
a control.

What happens is the control is handling it and thus eating the event before
your form ever sees it.

HTH,

Shane
"Jeffy210" <Je******@discussions.microsoft.comwrote in message
news:49**********************************@microsof t.com...
I'm having a weird problem with the Keydown event.

- I have a form with the KeyPreview property set to true
- I have a Form_KeyDown sub that does a bit of code for me
- I have a few control buttons on the form

Now comes the weird part. When I first launch the form, it intercepts the
key presses no problem (i'm capturing the arrow keys). However, when I
click
on a button, the form no longer fires off the keydown event, pressing the
left arrow, for example, will start cycling through the other buttons.

Is there a way to return the focus or control to the form so it can
capture
the arrow's being pressed and run the form_keydown code?

Jul 12 '06 #2
This thread may be a useful one for you

http://forums.microsoft.com/MSDN/Sho...38551&SiteID=1

-Sugan.

Jeffy210 wrote:
I'm having a weird problem with the Keydown event.

- I have a form with the KeyPreview property set to true
- I have a Form_KeyDown sub that does a bit of code for me
- I have a few control buttons on the form

Now comes the weird part. When I first launch the form, it intercepts the
key presses no problem (i'm capturing the arrow keys). However, when I click
on a button, the form no longer fires off the keydown event, pressing the
left arrow, for example, will start cycling through the other buttons.

Is there a way to return the focus or control to the form so it can capture
the arrow's being pressed and run the form_keydown code?
Jul 12 '06 #3
Hello, Jeffy210,

When the focus is on a Button, the arrow keys are being "pre-processed"
as navigation keys so they never reach the form's KeyDown event.

Two possibilities come to mind.

1. You could replace the Button control with your own button, inherited
from the standard button, but include an override like:

Protected Overrides Function _
IsInputKey(ByVal keyData As Keys) As Boolean
Select Case keyData
Case Keys.Down, Keys.Left, Keys.Right, Keys.Up
Return True
Case Else
Return False
End Select
End Function

2. Maybe you could "catch" the arrow keys before they are pre-processed
by overriding WndProc in your form. I have never tried this, though.
But maybe others more learned may be able to suggest how to do this, or
offer other ways around the problem.

Cheers,
Randy
Shane Story wrote:
There is a property on the Form that must be set.. I think it is KeyPreview
(I don't have VS up and running now). That allows the form to see it before
a control.

What happens is the control is handling it and thus eating the event before
your form ever sees it.

HTH,

Shane
"Jeffy210" <Je******@discussions.microsoft.comwrote in message
news:49**********************************@microsof t.com...
>>I'm having a weird problem with the Keydown event.

- I have a form with the KeyPreview property set to true
- I have a Form_KeyDown sub that does a bit of code for me
- I have a few control buttons on the form

Now comes the weird part. When I first launch the form, it intercepts the
key presses no problem (i'm capturing the arrow keys). However, when I
click
on a button, the form no longer fires off the keydown event, pressing the
left arrow, for example, will start cycling through the other buttons.

Is there a way to return the focus or control to the form so it can
capture
the arrow's being pressed and run the form_keydown code?


Jul 12 '06 #4
Okay, I understand what you mean, and I even found the "UserControl" item,
but for the life of me I can't figure out how to make it inherit the
properties of a standart button. Addionally that means I'm having trouble
figuring out where to put that code.

But all things being said, it looks like that will be the exact solution for
what I'm looking for. Thanks!

"R. MacDonald" wrote:
Hello, Jeffy210,

When the focus is on a Button, the arrow keys are being "pre-processed"
as navigation keys so they never reach the form's KeyDown event.

Two possibilities come to mind.

1. You could replace the Button control with your own button, inherited
from the standard button, but include an override like:

Protected Overrides Function _
IsInputKey(ByVal keyData As Keys) As Boolean
Select Case keyData
Case Keys.Down, Keys.Left, Keys.Right, Keys.Up
Return True
Case Else
Return False
End Select
End Function

2. Maybe you could "catch" the arrow keys before they are pre-processed
by overriding WndProc in your form. I have never tried this, though.
But maybe others more learned may be able to suggest how to do this, or
offer other ways around the problem.

Cheers,
Randy
Shane Story wrote:
There is a property on the Form that must be set.. I think it is KeyPreview
(I don't have VS up and running now). That allows the form to see it before
a control.

What happens is the control is handling it and thus eating the event before
your form ever sees it.

HTH,

Shane
"Jeffy210" <Je******@discussions.microsoft.comwrote in message
news:49**********************************@microsof t.com...
>I'm having a weird problem with the Keydown event.

- I have a form with the KeyPreview property set to true
- I have a Form_KeyDown sub that does a bit of code for me
- I have a few control buttons on the form

Now comes the weird part. When I first launch the form, it intercepts the
key presses no problem (i'm capturing the arrow keys). However, when I
click
on a button, the form no longer fires off the keydown event, pressing the
left arrow, for example, will start cycling through the other buttons.

Is there a way to return the focus or control to the form so it can
capture
the arrow's being pressed and run the form_keydown code?
Jul 12 '06 #5
Okay, actually bothered to sit down and read on User Controls and I got it
working. That rocks! Thank you very much. I can see some good uses for this
in the future.

Thank you very much!
Jeffy210

"R. MacDonald" wrote:
Hello, Jeffy210,

When the focus is on a Button, the arrow keys are being "pre-processed"
as navigation keys so they never reach the form's KeyDown event.

Two possibilities come to mind.

1. You could replace the Button control with your own button, inherited
from the standard button, but include an override like:

Protected Overrides Function _
IsInputKey(ByVal keyData As Keys) As Boolean
Select Case keyData
Case Keys.Down, Keys.Left, Keys.Right, Keys.Up
Return True
Case Else
Return False
End Select
End Function

2. Maybe you could "catch" the arrow keys before they are pre-processed
by overriding WndProc in your form. I have never tried this, though.
But maybe others more learned may be able to suggest how to do this, or
offer other ways around the problem.

Cheers,
Randy
Shane Story wrote:
There is a property on the Form that must be set.. I think it is KeyPreview
(I don't have VS up and running now). That allows the form to see it before
a control.

What happens is the control is handling it and thus eating the event before
your form ever sees it.

HTH,

Shane
"Jeffy210" <Je******@discussions.microsoft.comwrote in message
news:49**********************************@microsof t.com...
>I'm having a weird problem with the Keydown event.

- I have a form with the KeyPreview property set to true
- I have a Form_KeyDown sub that does a bit of code for me
- I have a few control buttons on the form

Now comes the weird part. When I first launch the form, it intercepts the
key presses no problem (i'm capturing the arrow keys). However, when I
click
on a button, the form no longer fires off the keydown event, pressing the
left arrow, for example, will start cycling through the other buttons.

Is there a way to return the focus or control to the form so it can
capture
the arrow's being pressed and run the form_keydown code?
Jul 12 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: John Ladasky | last post by:
Hi there, Just wanted to share a frustrating programming bug that, when I figured it out, made me gasp, and then laugh. In one of my programs I wrote... c = max(a,b) ....and I was...
2
by: Bj?rn Toft Madsen | last post by:
Hi all, The network library I use communicates with my app using a callback function. This callback function is called with the type of message, a void pointer to he actual message and a user...
3
by: Ben | last post by:
Please help: I have a class called BALL and I have some classes that inherit from BALL: BASKETBALL, BASEBALL, SOCCERBALL, MINI_SOCCERBALL, etc. I want to be able to have a single object that...
11
by: S. I. Becker | last post by:
Is it possible to determine if a function has been overridden by an object, when I have a pointer to that object as it's base class (which is abstract)? The reason I want to do this is that I want...
8
by: Allan Ebdrup | last post by:
I'm writing some code where I have have a class that implements 4 methods (class A) I only want to call these methods from the base class if they have been overridden in a sub class (Class B) I...
4
by: sultanwadood | last post by:
Hi all. I need to know how to restore or roll back to built-in function after overriding like following example. String.prototype.substr= function() { return "";} Now I want to use the one...
12
by: Ratko | last post by:
Hi all, I was wondering if something like this is possible. Can a base class somehow know if a certain method has been overridden by the subclass? I appreciate any ideas. Thanks, Ratko
6
by: wink | last post by:
I'd like to determine if a method has been overridden as was asked here: http://www.velocityreviews.com/forums/t564224-determining-whether-a-derived-class-overrides-a-virtual-memberfunction.html...
1
by: nsphelt | last post by:
I am wondering if it is possible to access the underlying property of a base class within a derived that has overridden that property. I am using VB.NET and when I use the MyBase keyword to access...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.