473,473 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Calling ProcessCmdKey in control

I am using the following code on my form to capture whether the tab
control has been pressed.

Protected Overrides Function ProcessCmdKey(ByRef msg As
System.Windows.Forms.Message, ByVal keyData As
System.Windows.Forms.Keys) As Boolean

Select Case keyData
Case Keys.Tab
MsgBox("tab pressed")
Return True

End Select

End Function

this code works fine to capture the tab press on the form but i wish
it only to occur on a specific control. what i really wish to do is to
find out if the tab has been pressed when i have got focus on a
specific control e.g. textbox1.text

Can anyone tell me how i can do this e.g. how do i call the function??
or is it a case that i must create a custom control??

Many thanks

CG
Nov 20 '05 #1
5 8587
Hi,

You have to make a control that inherits from textbox to have access
to processcmdkey.

Ken
------------------------
"Colin Graham" <cs********@hotmail.com> wrote in message
news:ee*************************@posting.google.co m...
I am using the following code on my form to capture whether the tab
control has been pressed.

Protected Overrides Function ProcessCmdKey(ByRef msg As
System.Windows.Forms.Message, ByVal keyData As
System.Windows.Forms.Keys) As Boolean

Select Case keyData
Case Keys.Tab
MsgBox("tab pressed")
Return True

End Select

End Function

this code works fine to capture the tab press on the form but i wish
it only to occur on a specific control. what i really wish to do is to
find out if the tab has been pressed when i have got focus on a
specific control e.g. textbox1.text

Can anyone tell me how i can do this e.g. how do i call the function??
or is it a case that i must create a custom control??

Many thanks

CG

Nov 20 '05 #2
but you can check the Forms ActiveControl to see if the textbox has focus.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OA**************@TK2MSFTNGP11.phx.gbl...
Hi,

You have to make a control that inherits from textbox to have access to processcmdkey.

Ken
------------------------
"Colin Graham" <cs********@hotmail.com> wrote in message
news:ee*************************@posting.google.co m...
I am using the following code on my form to capture whether the tab
control has been pressed.

Protected Overrides Function ProcessCmdKey(ByRef msg As
System.Windows.Forms.Message, ByVal keyData As
System.Windows.Forms.Keys) As Boolean

Select Case keyData
Case Keys.Tab
MsgBox("tab pressed")
Return True

End Select

End Function

this code works fine to capture the tab press on the form but i wish
it only to occur on a specific control. what i really wish to do is to
find out if the tab has been pressed when i have got focus on a
specific control e.g. textbox1.text

Can anyone tell me how i can do this e.g. how do i call the function??
or is it a case that i must create a custom control??

Many thanks

CG


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.719 / Virus Database: 475 - Release Date: 12/07/2004
Nov 20 '05 #3
Thanks very much for that its helped me alot. i now have another tiny
problem though see code below.

Protected Overrides Function ProcessCmdKey(ByRef msg As
System.Windows.Forms.Message, ByVal keyData As
System.Windows.Forms.Keys) As Boolean
If Me.ActiveControl Is yyn_WeightLoss Or _
Me.ActiveControl Is yyn_RectalBleeding Or _
Me.ActiveControl Is yyn_TubeDifficulties Or _
Me.ActiveControl Is yyn_XRayReport Or _
Me.ActiveControl Is yyn_CarriedOut _
AndAlso keyData = Keys.Tab = VK_TAB Then

fun_TabMoveNext()

ElseIf keyData = Keys.Tab And Control.ModifierKeys =
Keys.ShiftKey Then
If Me.ActiveControl Is yyn_AbdPain Or _
Me.ActiveControl Is yyn_Diarrhoea Or _
Me.ActiveControl Is yyn_PoorIntake Or _
Me.ActiveControl Is txt_OtherReason Or _
Me.ActiveControl Is dtp_ProcedureDate Then

fun_TabMoveBack()

Return True
End If
End If

Return MyBase.ProcessCmdKey(msg, keyData)

End Function

Im trying to catch the shift tab for navigation through the tab
control i.e., shift + tab (back) and tab (Forward). My problem seems
to be that it sees the shift key as a tab key key and moves forwards
when i press shift and im on one of the fields for moving forwards.
any idea who i can trap for purely just shift + tab?? ive read a few
other threads with no avail.

Thanks

CG
Nov 20 '05 #4
OK, so then you should be working in the ProcessTabKey Method.

Protected Overrides Function ProcessTabKey(ByVal forward As Boolean) As
Boolean
Dim ac As Control = Me.ActiveControl
If forward Then
If ac Is TextBox1 Then
fun_TabMoveNext()
Return True
End If
Else
If ac Is TextBox1 Then
fun_TabMoveBack()
Return True
End If
End If
Return MyBase.ProcessTabKey(forward)
End Function

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Colin Graham" <cs********@hotmail.com> wrote in message
news:ee**************************@posting.google.c om...
Thanks very much for that its helped me alot. i now have another tiny
problem though see code below.

Protected Overrides Function ProcessCmdKey(ByRef msg As
System.Windows.Forms.Message, ByVal keyData As
System.Windows.Forms.Keys) As Boolean
If Me.ActiveControl Is yyn_WeightLoss Or _
Me.ActiveControl Is yyn_RectalBleeding Or _
Me.ActiveControl Is yyn_TubeDifficulties Or _
Me.ActiveControl Is yyn_XRayReport Or _
Me.ActiveControl Is yyn_CarriedOut _
AndAlso keyData = Keys.Tab = VK_TAB Then

fun_TabMoveNext()

ElseIf keyData = Keys.Tab And Control.ModifierKeys =
Keys.ShiftKey Then
If Me.ActiveControl Is yyn_AbdPain Or _
Me.ActiveControl Is yyn_Diarrhoea Or _
Me.ActiveControl Is yyn_PoorIntake Or _
Me.ActiveControl Is txt_OtherReason Or _
Me.ActiveControl Is dtp_ProcedureDate Then

fun_TabMoveBack()

Return True
End If
End If

Return MyBase.ProcessCmdKey(msg, keyData)

End Function

Im trying to catch the shift tab for navigation through the tab
control i.e., shift + tab (back) and tab (Forward). My problem seems
to be that it sees the shift key as a tab key key and moves forwards
when i press shift and im on one of the fields for moving forwards.
any idea who i can trap for purely just shift + tab?? ive read a few
other threads with no avail.

Thanks

CG

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.719 / Virus Database: 475 - Release Date: 12/07/2004
Nov 20 '05 #5
Thank you very much worked perfectly.
Nov 20 '05 #6

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

Similar topics

1
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...
0
by: stardv | last post by:
I am trying to override ProcessCmdKey to either bind the data on “Enter” key pressed or return the value of the current cell when enter is pressed on it, whatever would be easier. I have...
1
by: Paul | last post by:
Hi, I am still confused the different between ProcessCmdKey and ProcessDialogKey. When to use it? I write a simple user control and these 2 override functions looks the same to me. ...
0
by: Rachel Suddeth | last post by:
I have been overriding the ProcessCmdKey in my forms because I want to handle some keystrokes that seem to disappear if I try to use the regular key handling events. It seems to be working just...
4
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...
0
by: Pablo Melero | last post by:
Buenas tardes, necesitara me ayudseis a conseguir controlar desde la funcin ProcesscmdKey la pulsacin de dos teclas a la vez ... no lo consigo de ninguna manera, parece que solo permite la...
2
by: Phil Galey | last post by:
I'm using the ProcessCmdKey event to capture various keys that are pressed. However, I'm having trouble capturing the combination of the CTRL key and, say, the DOWN key. If I just press the CTRL...
1
by: John Richardson | last post by:
I'm trying to override the SHIFT-SPACE "negative feature" in the Winforms datagrid, to only be a space. The following link describes this:...
5
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...
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,...
1
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.