473,606 Members | 3,100 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Overriding ProcessKeyPrevi ew, Enter WM_KEYDOWN...

Hi,

I have 3 questions regarding the code below:

1) Why can't I trap the KEYDOWN while I can trap KEYUP?
2) Is it correct that I use Return True within the IF-Statement? (I've
already read the documentation but it is rather hard to understand so please
don't refer to it :)
3) Many examples in the newsgroups use Return MyBase.ProcessK eyPreview(m) as
the last code line while I have used Return MyBase.ProcessK eyEventArgs(m)
according to the MSDN, is this correct or is it a typo in MSDN? (watch for
line breaks in the url)

ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwind owsformscontrol classpr
ocesskeypreview topic.htm

I aslo wonder if my code is correct as to subtitude Enter key with Tab in a
specifik column of the a datagrid. It seems to function well when trapping
the WM_KEYUP but to get the desired effect I need
to trap the WM_KEYDOWN, and doesn't work!

Protected Overrides Function ProcessKeyPrevi ew(ByRef m As
System.Windows. Forms.Message) As Boolean
Dim keyCode As Keys = CType(m.WParam. ToInt32, Keys) And Keys.KeyCode
Const WM_KEYDOWN As Integer = &H100
Const WM_KEYUP As Integer = &H101

If m.Msg = WM_KEYDOWN AndAlso keyCode = Keys.Enter _
AndAlso DataGridColumnS tyle1.TextBox Is ActiveControl _
AndAlso DataGrid1.DataS ource.GetType Is GetType(DataVie w) Then
SendKeys.Send(" {Tab}")
Return True
End If
Return MyBase.ProcessK eyEventArgs(m)
End Function

--
Thanks in advance
Ali Eghtebas Sweden
Jul 19 '05 #1
3 4177
> 1) Why can't I trap the KEYDOWN while I can trap KEYUP?
??? Whats happening when you try to trap keydown?
2) Is it correct that I use Return True within the IF-Statement? (I've
already read the documentation but it is rather hard to understand so please don't refer to it :)
The return value is dependant on what the function does. If you process the
key return true, if you don't, return false.
3) Many examples in the newsgroups use Return MyBase.ProcessK eyPreview(m) as the last code line while I have used Return MyBase.ProcessK eyEventArgs(m)
according to the MSDN, is this correct or is it a typo in MSDN? (watch for
line breaks in the url)
I can't see where ProcessKeyEvent Args appears anywhere, but it's wrong
anyway. It should be:

Return MyBase.ProcessK eyPreview(m)

This is because you are overriding the function, and so you are now letting
the original function process the key. The original function, that you
overrode, is not called, because you have overridden it, so calling that
line will call the original function and return the value that the original
function would have done.

(I hope that make sense)

Also, just FYI, Theres a better way to select the next control in a form,
other than sending the 'Tab' key (if you've seen my post about simulating
keystrokes earlier you'll realise I think it's bad). If you look at the
Me.SelectNextCo ntrol method, you can select the next control, based on the
ActiveControl:

Me.SelectNextCo ntrol(Me.Active Control, True)

More information on this:
<WatchForWrappi ng>
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwind owsformscontrol classse
lectnextcontrol topic.htm
</WatchForWrappin g>

--
Happy to help,
-- Tom Spink
(th**********@n tlworld.com)

" There's no place like 127.0.0.1 "

Please respond to the newsgroup,
so all can benefit.
One Day,
"Ali Eghtebas" <al***@home.s e> wrote in message
news:eO******** ******@tk2msftn gp13.phx.gbl... Hi,

I have 3 questions regarding the code below:

1) Why can't I trap the KEYDOWN while I can trap KEYUP?
2) Is it correct that I use Return True within the IF-Statement? (I've
already read the documentation but it is rather hard to understand so please don't refer to it :)
3) Many examples in the newsgroups use Return MyBase.ProcessK eyPreview(m) as the last code line while I have used Return MyBase.ProcessK eyEventArgs(m)
according to the MSDN, is this correct or is it a typo in MSDN? (watch for
line breaks in the url)

ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwind owsformscontrol classpr ocesskeypreview topic.htm

I aslo wonder if my code is correct as to subtitude Enter key with Tab in a specifik column of the a datagrid. It seems to function well when trapping
the WM_KEYUP but to get the desired effect I need
to trap the WM_KEYDOWN, and doesn't work!

Protected Overrides Function ProcessKeyPrevi ew(ByRef m As
System.Windows. Forms.Message) As Boolean
Dim keyCode As Keys = CType(m.WParam. ToInt32, Keys) And Keys.KeyCode Const WM_KEYDOWN As Integer = &H100
Const WM_KEYUP As Integer = &H101

If m.Msg = WM_KEYDOWN AndAlso keyCode = Keys.Enter _
AndAlso DataGridColumnS tyle1.TextBox Is ActiveControl _
AndAlso DataGrid1.DataS ource.GetType Is GetType(DataVie w) Then
SendKeys.Send(" {Tab}")
Return True
End If
Return MyBase.ProcessK eyEventArgs(m)
End Function

--
Thanks in advance
Ali Eghtebas Sweden

Jul 19 '05 #2
The issue was solved by overriding ProcessCmdKey instead ;)
This might be an issue in .Net Framework 1.1.
--
Regards
Ali Eghtebas Sweden

"Ali Eghtebas" <al***@home.s e> wrote in message
news:e6******** ******@TK2MSFTN GP10.phx.gbl...
1) Why can't I trap the KEYDOWN while I can trap KEYUP? ??? Whats happening when you try to trap keydown?


Actually what happens is that nothing happens since the execution never

gets into the If-Statement where I want to replace the Enter key with Tab key.
NOTE that I use .Net Framework 1.1.
This must be a bug or something since according to the documentation I
should be able to trap both KEYDOWN and KEYUP, which seems to only apply on KEYUP in this case.
To be more specifik m.Msg = WM_KEYUP returns True while m.Msg = WM_KEYDOWN
returns FALSE!
3) Many examples in the newsgroups use Return MyBase.ProcessK eyPreview(m)
as
the last code line while I have used Return MyBase.ProcessK eyEventArgs(m) according to the MSDN, is this correct or is it a typo in MSDN? (watch for line breaks in the url)
I can't see where ProcessKeyEvent Args appears anywhere, but it's wrong
anyway. It should be:

Return MyBase.ProcessK eyPreview(m)

This is because you are overriding the function, and so you are now

letting
the original function process the key. The original function, that you
overrode, is not called, because you have overridden it, so calling that
line will call the original function and return the value that the

original
function would have done.

(I hope that make sense)

This makes sence to me and that is also what I thought but the only
confusing thing about it is MSDN:
"Notes to Inheritors: When overriding the ProcessKeyPrevi ew method in a
derived class, a control should return true to indicate that it has
processed the key. For keys that are not processed by the control, the
result of calling the base class's ProcessKeyEvent Args method should be
returned."
Also, just FYI, Theres a better way to select the next control in a form, other than sending the 'Tab' key (if you've seen my post about simulating keystrokes earlier you'll realise I think it's bad). If you look at the
Me.SelectNextCo ntrol method, you can select the next control, based on the ActiveControl:

Me.SelectNextCo ntrol(Me.Active Control, True)

More information on this:
<WatchForWrappi ng>

ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwind owsformscontrol classse
lectnextcontrol topic.htm
</WatchForWrappin g>


The reason I want to replace the Enter Key with Tab is not that I want

give the focus to the next control on my form. I do this since in the last row in a DataGrid when editing a Cell the Enter Key doesn't assign the new value to the Cell since this is the last row and hence there is no next row to move
the focus on. I simply send Replace the Enter with Tab there to make the
change in the Cell and trigger other code within
CurrentCellChan ged.
One Day,
"Ali Eghtebas" <al***@home.s e> wrote in message
news:eO******** ******@tk2msftn gp13.phx.gbl...
Hi,

I have 3 questions regarding the code below:

1) Why can't I trap the KEYDOWN while I can trap KEYUP?
2) Is it correct that I use Return True within the IF-Statement? (I've
already read the documentation but it is rather hard to understand so

please
don't refer to it :)
3) Many examples in the newsgroups use Return

MyBase.ProcessK eyPreview(m)
as
the last code line while I have used Return

MyBase.ProcessK eyEventArgs(m) according to the MSDN, is this correct or is it a typo in MSDN? (watch for line breaks in the url)

ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwind owsformscontrol classpr
ocesskeypreview topic.htm

I aslo wonder if my code is correct as to subtitude Enter key with Tab in
a
specifik column of the a datagrid. It seems to function well when

trapping the WM_KEYUP but to get the desired effect I need
to trap the WM_KEYDOWN, and doesn't work!

Protected Overrides Function ProcessKeyPrevi ew(ByRef m As
System.Windows. Forms.Message) As Boolean
Dim keyCode As Keys = CType(m.WParam. ToInt32, Keys) And

Keys.KeyCode
Const WM_KEYDOWN As Integer = &H100
Const WM_KEYUP As Integer = &H101

If m.Msg = WM_KEYDOWN AndAlso keyCode = Keys.Enter _
AndAlso DataGridColumnS tyle1.TextBox Is ActiveControl _
AndAlso DataGrid1.DataS ource.GetType Is GetType(DataVie w) Then
SendKeys.Send(" {Tab}")
Return True
End If
Return MyBase.ProcessK eyEventArgs(m)
End Function

--
Thanks in advance
Ali Eghtebas Sweden


Jul 19 '05 #3
Glad you've got it sorted!!
"Notes to Inheritors: When overriding the ProcessKeyPrevi ew method in a
derived class, a control should return true to indicate that it has
processed the key. For keys that are not processed by the control, the
result of calling the base class's ProcessKeyEvent Args method should be
returned."
Technically this is correct, though I see why you might find it confusing.
It's all about how the new events in VB are delegate methods. It simply
means call the base class' version of the method to make sure it gets
notified of the message.

--
Happy to help,
-- Tom Spink
(th**********@n tlworld.com)

" There's no place like 127.0.0.1 "

Please respond to the newsgroup,
so all can benefit.
One Day,
"Ali Eghtebas" <al***@home.s e> wrote in message
news:#m******** ******@TK2MSFTN GP12.phx.gbl...
The issue was solved by overriding ProcessCmdKey instead ;)
This might be an issue in .Net Framework 1.1.
--
Regards
Ali Eghtebas Sweden

"Ali Eghtebas" <al***@home.s e> wrote in message
news:e6******** ******@TK2MSFTN GP10.phx.gbl... > 1) Why can't I trap the KEYDOWN while I can trap KEYUP?
??? Whats happening when you try to trap keydown?
Actually what happens is that nothing happens since the execution never

gets
into the If-Statement where I want to replace the Enter key with Tab key.
NOTE that I use .Net Framework 1.1.
This must be a bug or something since according to the documentation I
should be able to trap both KEYDOWN and KEYUP, which seems to only apply

on
KEYUP in this case.
To be more specifik m.Msg = WM_KEYUP returns True while m.Msg = WM_KEYDOWN returns FALSE!
> 3) Many examples in the newsgroups use Return

MyBase.ProcessK eyPreview(m)
as
> the last code line while I have used Return

MyBase.ProcessK eyEventArgs(m)
> according to the MSDN, is this correct or is it a typo in MSDN? (watch
for
> line breaks in the url)

I can't see where ProcessKeyEvent Args appears anywhere, but it's wrong
anyway. It should be:

Return MyBase.ProcessK eyPreview(m)

This is because you are overriding the function, and so you are now

letting
the original function process the key. The original function, that you
overrode, is not called, because you have overridden it, so calling
that line will call the original function and return the value that the

original
function would have done.

(I hope that make sense)

This makes sence to me and that is also what I thought but the only
confusing thing about it is MSDN:
"Notes to Inheritors: When overriding the ProcessKeyPrevi ew method in a
derived class, a control should return true to indicate that it has
processed the key. For keys that are not processed by the control, the
result of calling the base class's ProcessKeyEvent Args method should be
returned."
Also, just FYI, Theres a better way to select the next control in a

form, other than sending the 'Tab' key (if you've seen my post about simulating keystrokes earlier you'll realise I think it's bad). If you look at the Me.SelectNextCo ntrol method, you can select the next control, based on the ActiveControl:

Me.SelectNextCo ntrol(Me.Active Control, True)

More information on this:
<WatchForWrappi ng>

ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwind owsformscontrol classse
lectnextcontrol topic.htm
</WatchForWrappin g>


The reason I want to replace the Enter Key with Tab is not that I want

give
the focus to the next control on my form. I do this since in the last

row in
a DataGrid when editing a Cell the Enter Key doesn't assign the new
value to
the Cell since this is the last row and hence there is no next row to

move the focus on. I simply send Replace the Enter with Tab there to make the
change in the Cell and trigger other code within
CurrentCellChan ged.
One Day,
"Ali Eghtebas" <al***@home.s e> wrote in message
news:eO******** ******@tk2msftn gp13.phx.gbl...
> Hi,
>
> I have 3 questions regarding the code below:
>
> 1) Why can't I trap the KEYDOWN while I can trap KEYUP?
> 2) Is it correct that I use Return True within the IF-Statement? (I've > already read the documentation but it is rather hard to understand so please
> don't refer to it :)
> 3) Many examples in the newsgroups use Return

MyBase.ProcessK eyPreview(m)
as
> the last code line while I have used Return

MyBase.ProcessK eyEventArgs(m)
> according to the MSDN, is this correct or is it a typo in MSDN? (watch
for
> line breaks in the url)
>
>

ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwind owsformscontrol classpr > ocesskeypreview topic.htm
>
> I aslo wonder if my code is correct as to subtitude Enter key with Tab
in
a
> specifik column of the a datagrid. It seems to function well when

trapping
> the WM_KEYUP but to get the desired effect I need
> to trap the WM_KEYDOWN, and doesn't work!
>
> Protected Overrides Function ProcessKeyPrevi ew(ByRef m As
> System.Windows. Forms.Message) As Boolean
> Dim keyCode As Keys = CType(m.WParam. ToInt32, Keys) And
Keys.KeyCode
> Const WM_KEYDOWN As Integer = &H100
> Const WM_KEYUP As Integer = &H101
>
> If m.Msg = WM_KEYDOWN AndAlso keyCode = Keys.Enter _
> AndAlso DataGridColumnS tyle1.TextBox Is ActiveControl _
> AndAlso DataGrid1.DataS ource.GetType Is GetType(DataVie w)

Then > SendKeys.Send(" {Tab}")
> Return True
> End If
> Return MyBase.ProcessK eyEventArgs(m)
> End Function
>
> --
> Thanks in advance
> Ali Eghtebas Sweden



Jul 19 '05 #4

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

Similar topics

3
336
by: Ali Eghtebas | last post by:
Hi, I have 3 questions regarding the code below: 1) Why can't I trap the KEYDOWN while I can trap KEYUP? 2) Is it correct that I use Return True within the IF-Statement? (I've already read the documentation but it is rather hard to understand so please don't refer to it :) 3) Many examples in the newsgroups use Return MyBase.ProcessKeyPreview(m) as the last code line while I have used Return MyBase.ProcessKeyEventArgs(m)
1
384
by: Susanne Christe | last post by:
Hi Folks, I'm trying to override protected ProcessCmdKey function in writing my a custom MyDataGrid. I get the Keys I want, but it takes no effect to MyDataGrid, if I try for example execute myDataGrid.Select(rowNum); MessageBox.Show is coming up, but this takes no effect on Select or Focus. Anybody knows why?
1
1770
by: Diogo Alves - Software Developer | last post by:
I'm tring to override the combination all the combination like this one Ctrl + Shift + . I just can't catch it... I have already done this for ctrl + or Shift + but for both at same timeI can't do it.... Can someone tell me how to do it Here is an example of how I am doing this: if ((msg.Msg == WM_KEYDOWN) && (keyCode == Keys.Down))
5
4134
by: Niks | last post by:
I have a list control. On doubleclick of list item, a new dlg opens. Now, i want to handle 'OnEnter Key'also. i.e. When a list item is selected & Enter key is pressed, the new dlg shd open I tried implementing with NM_RETURN. But, the application does not catch this msg Also i tried with LVN_KEYDOWN. void CListExDlg::OnKeydownList(NMHDR* pNMHDR, LRESULT* pResult) LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR // TODO: Add your control...
4
2536
by: jibran | last post by:
Hello. I have wrapped the DataGrid control with my own class (SmartDataGrid) adding some necessary functionality. My current webform has 2 SmartDataGrids. The first is populated by selected information from a drop down box. The second datagrid is populated by viewing details from a row of the first datagrid. When editing individual rows (in either datagrid), clicking the enter key in any editable textbox calls my inital search...
3
13890
by: Melson | last post by:
hi can anyone help me how can i capture ENTER keystroke when the cell in datagrid is in editing mode. I'm now creating a data entry form with primary key in header and details in datagrid. So when user key in the details in datagrid, I would like user to choose product code by pressing ENTER key in the datagrid and a Product Code dialog will appear for him to choose.
4
6235
by: zacks | last post by:
Is there any way to distinguish the keypad Enter key from the standard Return key?
0
1753
by: Raj | last post by:
Windows application C#: I have a datagrid, in the 2nd column the user has to press the enter key between the contents and once entered the data from the cursor point till end should move to next line and removing those content from the first line. I am able to achive this by overrideing ProcessKeyPReview method but randomly the contents of the previous lines are displayed in next line not the removed contents(contents are removed from...
5
6144
by: Peted | last post by:
Hello, i am lookinf for the best way to trap any alphanumeric keypress in all multi key combminations and execute some code For example , i have a form visible using the form.showdialog method, then the user can press keys A, D, E, F, T, and C to peform a function. What i want is that if a user presses A, or a, or SHIFT A or CNTRL A that it executes the same code, BUT NOT IF ALT A is pressed. The same
0
8036
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7978
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8461
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8448
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8126
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6796
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5470
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3948
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4010
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.