473,396 Members | 1,933 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,396 software developers and data experts.

How to capture key

Hi there,

Can someone enlighten me on how to trap a keystroke in my "PropertyGrid"
override. I see functions or properrites at the control or form level
called:

OnKeyDown
OnKeyPress
OnKeyUp
OnPreviewKeyDown
ProcessKeyPreview
ProcessDialogKey
ProcessCmdKey
KeyPreview
IsInputKey

and there are probably more. I've overrided "OnKeyDown()" in my derived
"PropertyGrid" class but it's not being called. Some others are called
however such as "ProcessCmdKey" but I need to understand what's going on
here (since I suspect that "OnKeyDown()" is really the correct function).
Can anyone point me in the right direction. Thanks.
Apr 12 '07 #1
8 9623
Hello Larry,

the MS PropertyGrid has an internal grid and this is this one that
receives the keyboard events. If you really want to have a handler for
those events, you can access the internal grid (type is
System.Windows.Forms.PropertyGridInternal.Property GridView) with
myPropGrid.Controls[2]. But depending on your needs, this can be
tricky to play inside the private parts of the grid.

Best regards,

Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart PropertyGrid for .Net and MFC
Microsoft PropertyGrid Resource List - http://www.propertygridresourcelist.com
On Apr 12, 10:47 am, "Larry Smith" <no_spam@_nospam.comwrote:
Hi there,

Can someone enlighten me on how to trap a keystroke in my "PropertyGrid"
override. I see functions or properrites at the control or form level
called:

OnKeyDown
OnKeyPress
OnKeyUp
OnPreviewKeyDown
ProcessKeyPreview
ProcessDialogKey
ProcessCmdKey
KeyPreview
IsInputKey

and there are probably more. I've overrided "OnKeyDown()" in my derived
"PropertyGrid" class but it's not being called. Some others are called
however such as "ProcessCmdKey" but I need to understand what's going on
here (since I suspect that "OnKeyDown()" is really the correct function).
Can anyone point me in the right direction. Thanks.

Apr 12 '07 #2
the MS PropertyGrid has an internal grid and this is this one that
receives the keyboard events. If you really want to have a handler for
those events, you can access the internal grid (type is
System.Windows.Forms.PropertyGridInternal.Property GridView) with
myPropGrid.Controls[2]. But depending on your needs, this can be
tricky to play inside the private parts of the grid.
Thanks for the feedback. Are you saying that this particular control doesn't
follow the normal (and expected) rules IOW. I'm not sure why they would do
this since it's abnormal to say the least. In any case, if you know this for
a fact (have you confirmed it with MSFT?) then I'll have to rely on
"ProcessCmdKey()" instead. I'd rather not rely on undocumented techniques.

On a completely unrelated matter however, I know that individual
"PropertyGrid" rows can't be colorized. Do you know a way to pull this off
even if I have to rely on undocumented techniques. I've looked into it and
can't find a way so far (since there seems to be no stable row-based window
behind the scenes until the user actually starts editing the row). Note that
I'm a very experienced C++ developer so hacking into it won't be a problem
if you can get me started (it's a necessary evil I need to explore). Thanks.
Apr 12 '07 #3
Hello Larry,

Why do you say it's abnormal? The internal grid has the focus so this
is absolutely normal that it gets the keyboard events.
Indeed I think you're better to rely on a public solution. But you
should override ProcessKeyPreview instead of ProcessCmdKey which is
more intended for command keys (accelerator and menu shortcuts).
ProcessKeyPreview gives the opportunity to the parent to process the
key before or instead of the child.

Concerning colors, you won't be able to change them on a per property
basis. Sorry for the plug but only a solution like Smart PropertyGrid
will let you customize most of the aspects of the grid. Getting into
the internals of the MSPG has its limits.

Best regards,

Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart PropertyGrid for .Net and MFC
Microsoft PropertyGrid Resource List - http://www.propertygridresourcelist.com
On Apr 12, 2:59 pm, "Larry Smith" <no_spam@_nospam.comwrote:
the MS PropertyGrid has an internal grid and this is this one that
receives the keyboard events. If you really want to have a handler for
those events, you can access the internal grid (type is
System.Windows.Forms.PropertyGridInternal.Property GridView) with
myPropGrid.Controls[2]. But depending on your needs, this can be
tricky to play inside the private parts of the grid.

Thanks for the feedback. Are you saying that this particular control doesn't
follow the normal (and expected) rules IOW. I'm not sure why they would do
this since it's abnormal to say the least. In any case, if you know this for
a fact (have you confirmed it with MSFT?) then I'll have to rely on
"ProcessCmdKey()" instead. I'd rather not rely on undocumented techniques.

On a completely unrelated matter however, I know that individual
"PropertyGrid" rows can't be colorized. Do you know a way to pull this off
even if I have to rely on undocumented techniques. I've looked into it and
can't find a way so far (since there seems to be no stable row-based window
behind the scenes until the user actually starts editing the row). Note that
I'm a very experienced C++ developer so hacking into it won't be a problem
if you can get me started (it's a necessary evil I need to explore). Thanks.

Apr 12 '07 #4
Thanks again for the feedback.
Why do you say it's abnormal? The internal grid has the focus so this
is absolutely normal that it gets the keyboard events.
I say it's abnormal because an "OnKeyDown()" override should be called
AFAIK. It's a published function which originates from the "Control" base
class no less. Unless I'm missing something I don't see why it's not being
called.
Indeed I think you're better to rely on a public solution. But you
should override ProcessKeyPreview instead of ProcessCmdKey which is
more intended for command keys (accelerator and menu shortcuts).
ProcessKeyPreview gives the opportunity to the parent to process the
key before or instead of the child.
My control is self-contained so it needs to handle its own keystrokes. I've
already played with "ProcessKeyPreview()" but will take another look. Since
it's low-level however I figured that "OnKeyDown()" was likely more
appropriate. The variety of keystroke functions/properties available is
bewildering given the absence of adequate documentation.
Concerning colors, you won't be able to change them on a per property
basis. Sorry for the plug but only a solution like Smart PropertyGrid
will let you customize most of the aspects of the grid. Getting into
the internals of the MSPG has its limits.
You're right of course and I'm puzzled why MSFT never gave us control over
this (color, font, etc.). It's basic. It's also particularly important for
my own app so I'll likely replace "PropertyGrid" by the second release
(first release is pending this fall). Note that I didn't pursue your own
control for a variety of reasons not the least of which is that it came to
my attention too late. I also require localization in potentially many
languages. What languages does yours support? Note BTW (FYI) that Mark
Rideout (manager of the "DataGridView" control at MSFT) has also posted
this:

http://blogs.msdn.com/markrideout/ar...08/510700.aspx

It's unofficial and likely needs work (haven't looked at it in detail) but
it serves as an excellent starting point to replace the "PropertyGrid"
(IMO). Thanks again for your help.
Apr 12 '07 #5
No, OnKeyDown() shouldn't be called for the PropertyGrid. The
PropertyGrid acts as a container (the PropertyGrid class) and is
composed of the toolstrip, the internal grid and the label (comment
area). When the internal grid has the focus, it receives the keyboard
events and handle them. The parent container's virtual methods like
OnKeyDown won't be called simply because the keystrokes are not
directed to it. To be aware of the keys typed, you can override
ProcessKeyPreview or subscribe to the events of the internal grid
(Controls[2].KeyDown += ......). But not that in the second
possibility, the keys will still be handled by the child. In the first
solution you can "eat" the keys messages.

So, this is what happens normally. However I agree that MS should have
provided a way to make the container aware of these events in a more
"natural" way. FYI, SPG forwards the events automatically to the
parent.

Concerning localization, neither SPG or MSPG support a particular
language. This is up to the client application to load the correct
strings and to supply them via Description and DisplayName attributes.
Note that SPG also enables on the fly modification of these
properties.

Hope that helps.

Best regards,

Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart PropertyGrid for .Net and MFC
Microsoft PropertyGrid Resource List - http://www.propertygridresourcelist.com
On Apr 12, 5:43 pm, "Larry Smith" <no_spam@_nospam.comwrote:
Thanks again for the feedback.
Why do you say it's abnormal? The internal grid has the focus so this
is absolutely normal that it gets the keyboard events.

I say it's abnormal because an "OnKeyDown()" override should be called
AFAIK. It's a published function which originates from the "Control" base
class no less. Unless I'm missing something I don't see why it's not being
called.
Indeed I think you're better to rely on a public solution. But you
should override ProcessKeyPreview instead of ProcessCmdKey which is
more intended for command keys (accelerator and menu shortcuts).
ProcessKeyPreview gives the opportunity to the parent to process the
key before or instead of the child.

My control is self-contained so it needs to handle its own keystrokes. I've
already played with "ProcessKeyPreview()" but will take another look. Since
it's low-level however I figured that "OnKeyDown()" was likely more
appropriate. The variety of keystroke functions/properties available is
bewildering given the absence of adequate documentation.
Concerning colors, you won't be able to change them on a per property
basis. Sorry for the plug but only a solution like Smart PropertyGrid
will let you customize most of the aspects of the grid. Getting into
the internals of the MSPG has its limits.

You're right of course and I'm puzzled why MSFT never gave us control over
this (color, font, etc.). It's basic. It's also particularly important for
my own app so I'll likely replace "PropertyGrid" by the second release
(first release is pending this fall). Note that I didn't pursue your own
control for a variety of reasons not the least of which is that it came to
my attention too late. I also require localization in potentially many
languages. What languages does yours support? Note BTW (FYI) that Mark
Rideout (manager of the "DataGridView" control at MSFT) has also posted
this:

http://blogs.msdn.com/markrideout/ar...08/510700.aspx

It's unofficial and likely needs work (haven't looked at it in detail) but
it serves as an excellent starting point to replace the "PropertyGrid"
(IMO). Thanks again for your help.

Apr 12 '07 #6
No, OnKeyDown() shouldn't be called for the PropertyGrid. The
PropertyGrid acts as a container (the PropertyGrid class) and is
composed of the toolstrip, the internal grid and the label (comment
area). When the internal grid has the focus, it receives the keyboard
events and handle them. The parent container's virtual methods like
OnKeyDown won't be called simply because the keystrokes are not
directed to it. To be aware of the keys typed, you can override
ProcessKeyPreview or subscribe to the events of the internal grid
(Controls[2].KeyDown += ......). But not that in the second
possibility, the keys will still be handled by the child. In the first
solution you can "eat" the keys messages.
Ok, thanks for the primer. While I don't agree with this behaviour (it's
inconsistent and counterintuitive) we live in a world of imperfection.
So, this is what happens normally. However I agree that MS should have
provided a way to make the container aware of these events in a more
"natural" way. FYI, SPG forwards the events automatically to the
parent.
How easy would it be to port my code to your grid. Is it compatible with the
native grid (can we feed it the same way) or am I'm faced with a lot of
redevelopment. Note that I've rolled my own custom "TypeConverter" and
"TypeDescriptionProvider" classes (overrding "GetProperties()" where req'd)
and I don't want to tear it all apart at this stage (since it's working
now).
Concerning localization, neither SPG or MSPG support a particular
language. This is up to the client application to load the correct
strings and to supply them via Description and DisplayName attributes.
Note that SPG also enables on the fly modification of these
properties.
Ok, thanks. I didn't know whether your grid had any of its own native
strings or not.
Apr 12 '07 #7
Larry,

if you want to know more about SPG I propose that you contact me
through the VisualHint helpdesk. I don't think this is the proper
place here... ;)

Best regards,

Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart PropertyGrid for .Net and MFC
Microsoft PropertyGrid Resource List - http://www.propertygridresourcelist.com
On Apr 12, 7:33 pm, "Larry Smith" <no_spam@_nospam.comwrote:
No, OnKeyDown() shouldn't be called for the PropertyGrid. The
PropertyGrid acts as a container (the PropertyGrid class) and is
composed of the toolstrip, the internal grid and the label (comment
area). When the internal grid has the focus, it receives the keyboard
events and handle them. The parent container's virtual methods like
OnKeyDown won't be called simply because the keystrokes are not
directed to it. To be aware of the keys typed, you can override
ProcessKeyPreview or subscribe to the events of the internal grid
(Controls[2].KeyDown += ......). But not that in the second
possibility, the keys will still be handled by the child. In the first
solution you can "eat" the keys messages.

Ok, thanks for the primer. While I don't agree with this behaviour (it's
inconsistent and counterintuitive) we live in a world of imperfection.
So, this is what happens normally. However I agree that MS should have
provided a way to make the container aware of these events in a more
"natural" way. FYI, SPG forwards the events automatically to the
parent.

How easy would it be to port my code to your grid. Is it compatible with the
native grid (can we feed it the same way) or am I'm faced with a lot of
redevelopment. Note that I've rolled my own custom "TypeConverter" and
"TypeDescriptionProvider" classes (overrding "GetProperties()" where req'd)
and I don't want to tear it all apart at this stage (since it's working
now).
Concerning localization, neither SPG or MSPG support a particular
language. This is up to the client application to load the correct
strings and to supply them via Description and DisplayName attributes.
Note that SPG also enables on the fly modification of these
properties.

Ok, thanks. I didn't know whether your grid had any of its own native
strings or not.

Apr 13 '07 #8
if you want to know more about SPG I propose that you contact me
through the VisualHint helpdesk. I don't think this is the proper
place here... ;)
Yes, this isn't the proper venue. Will be in touch in the near future.
Thanks again for your help here.
Apr 13 '07 #9

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

Similar topics

0
by: Mark Barinstein | last post by:
Hello. W2K, db2 v7, FP10a. Before now our replication worked properly. But some days ago capture suddenly stopped loggin and filling cd tables without any messages. The last message was like...
2
by: Jose | last post by:
There's something for me to learn with this example, i'm sure :) Given this text: "....." and my first attempt at capture the groups: "(?:\)" RegExTest gives me what i expect: 6 captured...
0
by: Tsunami | last post by:
Hi to all: I have a big problem and I write to ask for help. Sorry if this message does not arrive to the apropriate group. I have selected them paying attention but I am not sure to do it well....
4
by: jxiang | last post by:
I created a child form that is much bigger than the MDI form in VB.Net. I am trying to capture the whole child form and save as an image or sent to printer. I tried to use BitBlt to capture the...
2
by: py | last post by:
I need to take a screen shot of the computer screen. I am trying to use PIL and I saw there is ImageGrab...however it only works on Windows. Is there a platform-independent ability to work...
4
by: gwhite1 | last post by:
I use this code to capture a screen in a regular VB 2005 windows app. It works great! I found the code in google. But when I create a windows service it does not capture the screen. It only...
0
by: Roger | last post by:
I am in the process of installing DB2 Replication V 8.2 for Z/os on my test system. When I start the ASNSTRC (capture) with RRS shutdown, it switches to CAF and starts up. However, if I have RRS...
0
by: j101 | last post by:
I am attempting to set up Q Capture on RH Linux (x86_64) using DB2 9 fp2, but there seems to be a general problem loading a specify MQ shared library "/opt/mqm/lib/libmqm_r.so". I have MQ v6...
2
by: pampululu | last post by:
hello, I try to use directx.capture in my web application, I use visual studio web developper 2005 express with c# for code behind. I can list the webcam available on computer, no probem, my...
1
by: sangith | last post by:
Hi, I tried the packet capture module program. I did a file transfer using ftp from this host to another server. But when I ran the program, it was just hanging off and it did not print the...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.