473,586 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ 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(B yRef 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 8604
Hi,

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

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

Protected Overrides Function ProcessCmdKey(B yRef 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***@bellsout h.net> wrote in message
news:OA******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

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

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

Protected Overrides Function ProcessCmdKey(B yRef 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(B yRef msg As
System.Windows. Forms.Message, ByVal keyData As
System.Windows. Forms.Keys) As Boolean
If Me.ActiveContro l Is yyn_WeightLoss Or _
Me.ActiveContro l Is yyn_RectalBleed ing Or _
Me.ActiveContro l Is yyn_TubeDifficu lties Or _
Me.ActiveContro l Is yyn_XRayReport Or _
Me.ActiveContro l Is yyn_CarriedOut _
AndAlso keyData = Keys.Tab = VK_TAB Then

fun_TabMoveNext ()

ElseIf keyData = Keys.Tab And Control.Modifie rKeys =
Keys.ShiftKey Then
If Me.ActiveContro l Is yyn_AbdPain Or _
Me.ActiveContro l Is yyn_Diarrhoea Or _
Me.ActiveContro l Is yyn_PoorIntake Or _
Me.ActiveContro l Is txt_OtherReason Or _
Me.ActiveContro l Is dtp_ProcedureDa te Then

fun_TabMoveBack ()

Return True
End If
End If

Return MyBase.ProcessC mdKey(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(B yVal forward As Boolean) As
Boolean
Dim ac As Control = Me.ActiveContro l
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.ProcessT abKey(forward)
End Function

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

Protected Overrides Function ProcessCmdKey(B yRef msg As
System.Windows. Forms.Message, ByVal keyData As
System.Windows. Forms.Keys) As Boolean
If Me.ActiveContro l Is yyn_WeightLoss Or _
Me.ActiveContro l Is yyn_RectalBleed ing Or _
Me.ActiveContro l Is yyn_TubeDifficu lties Or _
Me.ActiveContro l Is yyn_XRayReport Or _
Me.ActiveContro l Is yyn_CarriedOut _
AndAlso keyData = Keys.Tab = VK_TAB Then

fun_TabMoveNext ()

ElseIf keyData = Keys.Tab And Control.Modifie rKeys =
Keys.ShiftKey Then
If Me.ActiveContro l Is yyn_AbdPain Or _
Me.ActiveContro l Is yyn_Diarrhoea Or _
Me.ActiveContro l Is yyn_PoorIntake Or _
Me.ActiveContro l Is txt_OtherReason Or _
Me.ActiveContro l Is dtp_ProcedureDa te Then

fun_TabMoveBack ()

Return True
End If
End If

Return MyBase.ProcessC mdKey(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
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?
0
1551
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 struggled to get the code right. Could you pleas eprovide some sample code or some pointers how to achieve what I want Thanks a lot in a advance -- ...
1
11663
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. protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { const int WM_KEYDOWN = 0x100; const int WM_SYSKEYDOWN = 0x104;
0
1629
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 fine, but there are some things I don't understand, and I could use some advice. 1) The ProcessCmdKey takes a Windows message, and I feel like I...
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...
0
1436
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 primera captura ... pero para controlar dentro de una datagrid, por ejemplo, si han pulsado ctrl+inicio , cmo puedo hacerlo? Muchas gracias y un...
2
6074
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 key alone, the KeyData value is 131089. But all the possibilities I'm finding in the Keys enumeration are the following: Keys.ControlKey = 17...
1
8293
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: http://www.dotnet247.com/247reference/msgs/52/262224.aspx In this procedure, MS suggested to use SendKeys.Send(" "), but I am finding that this locks my machine, and SendWait() causes an infinite loop...
5
6143
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...
0
7912
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, well explore What is ONU, What Is Router, ONU & Routers main...
0
8338
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...
1
7959
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...
0
8216
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6614
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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 we have to send another system
1
1449
muto222
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.