By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

Calling ProcessCmdKey in control

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
Thank you very much worked perfectly.
Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.