473,698 Members | 2,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

deny keystroke Textbox Tab key not Working?

Hi,

I am trying to allow users to only be able to enter numeric numbers
into a textbox. The problem is that I cannot move focus with the tab
key even if I allow it as an allowable key stroke. I have successfully
achieved this thanks to abit of code I found from within these forums
(thanks who ever posted it!):

Protected Overrides Function ProcessDialogKe y(ByVal keydata As
System.Windows. Forms.Keys) As Boolean
If txtboxAB.Focuse d Then
Select Case keydata
Case Keys.D0, Keys.D1, Keys.D2, Keys.D3, Keys.D4,
Keys.D5, Keys.D6, Keys.D7, _
Keys.D8, Keys.D9, Keys.Back, Keys.Decimal,
Keys.OemPeriod, Keys.NumPad0, Keys.NumPad1, Keys.NumPad2,
Keys.NumPad3, _
Keys.NumPad4, Keys.NumPad5, Keys.NumPad6, Keys.NumPad7, Keys.NumPad8,
Keys.NumPad9, Keys.Delete, KEYS.TAB 'accept digits only
Return False
Case Else
Return True
End Select
Else
Return MyBase.ProcessD ialogKey(keydat a)
End If
End Function

The problem I have is that the Keys.TAB does not seem to work. When it
goes into the function it detects that a TAB key has been pressed (the
same as the rest of the number keys) however it does not move the
focus to the next textbox. Does anyone know how I can make this work??

PowaGuy
Nov 21 '05 #1
5 2095
> Protected Overrides Function ProcessDialogKe y(ByVal keydata As
System.Windows. Forms.Keys) As Boolean
If txtboxAB.Focuse d Then
Select Case keydata
Case Keys.D0, Keys.D1, Keys.D2, Keys.D3, Keys.D4,
Keys.D5, Keys.D6, Keys.D7, _
Keys.D8, Keys.D9, Keys.Back, Keys.Decimal,
Keys.OemPeriod, Keys.NumPad0, Keys.NumPad1, Keys.NumPad2,
Keys.NumPad3, _
Keys.NumPad4, Keys.NumPad5, Keys.NumPad6, Keys.NumPad7, Keys.NumPad8,
Keys.NumPad9, Keys.Delete, KEYS.TAB 'accept digits only
Return False
-- allow the base class to handle these keys in the normal way instead of
returning false.
replace 'Return False' with 'Return MyBase.ProcessD ialogKey(keydat a)'
Case Else
Return True
End Select
Else
Return MyBase.ProcessD ialogKey(keydat a)
End If
End Function


If you are going to be using this kind of a textbox often, I would suggest
you create a user control derived from the textbox and override the
ProcessCmdKey method in your user control adding this code there so that you
don't have to do it over and over again whenever you need this
functionality.

hope this helps..
Imran.
Nov 21 '05 #2
> ProcessCmdKey method in your user control adding this code there so that
you


sorry - I meant ProcessDialogKe y method.

Imran.
Nov 21 '05 #3
This change will allow for the tab key to be processed correctly.

Protected Overrides Function ProcessDialogKe y(ByVal keydata As System.Windows. Forms.Keys) As Boolean
  &nb sp;      If TextBox1.Focuse d Then
  &nb sp;     &nb sp;     Select Case keydata
  &nb sp;     &nb sp;     &nb sp;   Case Keys.D0, Keys.D1, Keys.D2, Keys.D3, Keys.D4, Keys.D5, Keys.D6, Keys.D7, _
  &nb sp;     &nb sp;     &nb sp;     &nb sp;     &nb sp;     &nb sp;     &nb sp;   Keys.D8, Keys.D9, Keys.Back, Keys.Decimal, Keys.OemPeriod, Keys.NumPad0, Keys.NumPad1, Keys.NumPad2, Keys.NumPad3, _
  &nb sp;     &nb sp;     &nb sp;     &nb sp;  Keys.NumPad4, Keys.NumPad5, Keys.NumPad6, Keys.NumPad7, Keys.NumPad8, Keys.NumPad9, Keys.Delete, Keys.Tab
  &nb sp;     &nb sp;     &nb sp;     &nb sp;  Return MyBase.ProcessD ialogKey(keydat a)
  &nb sp;     &nb sp;     &nb sp;   Case Else
  &nb sp;     &nb sp;     &nb sp;     &nb sp;  Return True
  &nb sp;     &nb sp;     End Select
  &nb sp;      Else
  &nb sp;     &nb sp;     Return MyBase.ProcessD ialogKey(keydat a)
  &nb sp;      End If
  &nb sp; End Function



Powerguy wrote:

Hi, I am trying to allow users to only be able to enter numeric numbers into a textbox. The problem is that I cannot move focus with the tab key even if I allow it as an allowable key stroke. I have successfully achieved this thanks to abit of code I found from within these forums (thanks who ever posted it!): Protected Overrides Function ProcessDialogKe y(ByVal keydata As System.Windows. Forms.Keys) As Boolean If txtboxAB.Focuse d Then Select Case keydata Case Keys.D0, Keys.D1, Keys.D2, Keys.D3, Keys.D4, Keys.D5, Keys.D6, Keys.D7, _ Keys.D8, Keys.D9, Keys.Back, Keys.Decimal, Keys.OemPeriod, Keys.NumPad0, Keys.NumPad1, Keys.NumPad2, Keys.NumPad3, _ Keys.NumPad4, Keys.NumPad5, Keys.NumPad6, Keys.NumPad7, Keys.NumPad8, Keys.NumPad9, Keys.Delete, KEYS.TAB 'accept digits only Return False Case Else Return True End Select Else Return MyBase.ProcessD ialogKey(keydat a) End If End Function The problem I have is that the Keys.TAB does not seem to work. When it goes into the function it detects that a TAB key has been pressed (the same as the rest of the number keys) however it does not move the focus to the next textbox. Does anyone know how I can make this work?? PowaGuy

Nov 21 '05 #4
Powerguy,

When you want another sample, this works as well when somebody paste a
charachter in the textbox .

I hope this helps?

Cor

Private Sub textbox1_KeyUp( ByVal sender As Object, _
ByVal e As System.Windows. Forms.KeyEventA rgs) Handles textbox1.KeyUp
If e.KeyValue <> 8 Then
If Not IsNumeric(TextB ox1.Text) Then
If TextBox1.Text.L ength > 0 Then
MessageBox.Show ("Only numeric is allowed")
TextBox1.Select ionStart = TextBox1.Text.L ength - 1
TextBox1.Select ionLength = 1
End If
End If
End If
End Sub
Private Sub TextBox1_Valida ting(ByVal sender _
As Object, ByVal e As System.Componen tModel.CancelEv entArgs) _
Handles TextBox1.Valida ting
If TextBox1.Text.L ength > 0 Then
If Not IsNumeric(TextB ox1.Text) Then
MessageBox.Show ("There was an error pasting")
TextBox1.Focus( )
e.Cancel = True
End If
End If
End Sub
///
Hi,

I am trying to allow users to only be able to enter numeric numbers
into a textbox. The problem is that I cannot move focus with the tab
key even if I allow it as an allowable key stroke. I have successfully
achieved this thanks to abit of code I found from within these forums
(thanks who ever posted it!):

Protected Overrides Function ProcessDialogKe y(ByVal keydata As
System.Windows. Forms.Keys) As Boolean
If txtboxAB.Focuse d Then
Select Case keydata
Case Keys.D0, Keys.D1, Keys.D2, Keys.D3, Keys.D4,
Keys.D5, Keys.D6, Keys.D7, _
Keys.D8, Keys.D9, Keys.Back, Keys.Decimal,
Keys.OemPeriod, Keys.NumPad0, Keys.NumPad1, Keys.NumPad2,
Keys.NumPad3, _
Keys.NumPad4, Keys.NumPad5, Keys.NumPad6, Keys.NumPad7, Keys.NumPad8,
Keys.NumPad9, Keys.Delete, KEYS.TAB 'accept digits only
Return False
Case Else
Return True
End Select
Else
Return MyBase.ProcessD ialogKey(keydat a)
End If
End Function

The problem I have is that the Keys.TAB does not seem to work. When it
goes into the function it detects that a TAB key has been pressed (the
same as the rest of the number keys) however it does not move the
focus to the next textbox. Does anyone know how I can make this work??

PowaGuy

Nov 21 '05 #5
Thanks Imran and Cor!

Both your posts helped me alot. Imran, my testbox's can now accept
and process the TAB keys correctly. I did have a problem with the
shift + Tab key combination thou but I managed to figure it out as
follows:

Protected Overrides Function ProcessDialogKe y(ByVal keydata As
System.Windows. Forms.Keys) As Boolean
If txtboxAB.Focuse d Or txtboxBC.Focuse d Or txtboxAC.Focuse d Or
txtboxAE.Focuse d Or txtboxBE.Focuse d Or _
txtboxCE.Focuse d Or txtboxHA.Focuse d Or txtboxHB.Focuse d Or
txtboxHC.Focuse d Or txtboxER.Focuse d Or txtboxHE.Focus Then
Select Case keydata
Case Keys.D0, Keys.D1, Keys.D2, Keys.D3, Keys.D4,
Keys.D5, Keys.D6, Keys.D7, _
Keys.D8, Keys.D9, Keys.Back, Keys.Decimal,
Keys.OemPeriod, Keys.NumPad0, Keys.NumPad1, Keys.NumPad2,
Keys.NumPad3, _
Keys.NumPad4, Keys.NumPad5, Keys.NumPad6, Keys.NumPad7, Keys.NumPad8,
Keys.NumPad9, Keys.Delete, Keys.Tab, Keys.ShiftKey, (Keys.Shift +
keys.Tab) <--- to get Shift and Tab key to work!
Return MyBase.ProcessD ialogKey(keydat a)
Case Else
Return True
End Select
Else
Return MyBase.ProcessD ialogKey(keydat a)
End If
End Function

Cor, I forgot completely about the context menu and copying and
pasting. I actually didn't want the textbox to beable to have this
functionality so I managed to iliminate it with the following:

Dim cm As New ContextMenu
txtboxAB.Contex tMenu = cm

Thanks again you guys, you helped me a heap!

Powaguy
Nov 21 '05 #6

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

Similar topics

7
6221
by: hokieghal99 | last post by:
Does anyone know of a keystroke logger that has been written in Python for Windows machines? I'd like to see such a script and use it as a point of reference for a real-time backup project that I'm working on. Basically, I'd like to be able to capture all keystrokes from the keyboard buffer and write them to a text file so I could reporduce emails, documents, etc. in the event of file loss that occurs between nightly backups. For example,...
7
2040
by: Byron | last post by:
I'm looking for a way to deny a move from the current listbox item. For instance, if the user is editing the record associated with the current listbox item I want to deny a move within the listbox until they have saved the changes. Is there any way to deny a move from the current item so the SelectedIndexChanged event never fires no matter move the movement was attempted? Whether the user uses the cursor keys or mouse to try and leave...
6
1371
by: Herb Stull | last post by:
Does anyone know of a way to count keystrokes client side? My users want to know how many characters they've typed into a textbox. Picky, picky, picky! Thanks, Herb
4
12161
by: Dan | last post by:
hi ng. i have a strange behaviour when i want to control who can access a web application by setting web.config like: <authorization> <allow users="DOMAIN\ACCOUNT,..." /> <deny users="*" /> the authorization is working fine, but the user receives the standard "The page cannot be displayed"
2
5226
by: Tim::.. | last post by:
Hi can someone please tell me why this web.config file doesn't deny access to all for the folder it is in??? I have the web.config file in a folder called contents but for some reason I can still access this folder. I am using Forms authentification and I just can't get it to work! PLEASE help... Thanks
1
5287
by: Joseph Geretz | last post by:
I'm noticing that when my DataGrid has focus, it handles the Enter key by advancing to the next row in the grid. This neutralizes Forms's current defined AcceptButton. My primary question: is there any quick way to configure the Grid not to handle the Enter key? I do not see any property control which might configure this behavior. My secondary question: If there's no quick solution via Grid configuration, then how do I get the...
3
2891
by: =?Utf-8?B?QmVybmFyZG8gU2FsYXphciBuZXdi?= | last post by:
Hi everybody... i need help with this issue: i have a textbox control with the focus. at side, i have a datagridview control populated with some data. i need to control behavior of dgv control from textbox. when i press pagedown/pageup key (in textbox), i need to send that key to dgw, to move the data up/down, but, without loss the focus in textbox. i already studied the sendkeys.send, but i dont know how to send a key to control, the...
3
1455
OuTCasT
by: OuTCasT | last post by:
Hi Got 2 textboxes and a totals label. i want to be able to add values in the first textbox and when i press enter it should fill the labels value with that value and the focus should be moved to the next textbox, when i add a value into that textbox the labels value must increase with that value aswell. can anyone hlp
3
1794
by: MLH | last post by:
Suppose I wanna type 12345 into a texbox on a form. After each keystroke, can I read 1, then 12, then 123 then 1234 and finally 12345? If so, how is this done?
0
8674
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
8603
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
9157
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
8861
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7725
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
5860
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
4369
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...
2
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.