473,763 Members | 7,622 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Textbox input restriction on the Keypressed event procedure

8 New Member
Hi mates,

I have written the code below on VB 2005 to try and restrict input on a textbox.
This code works very well on VB 2005 and its controls.

However my project's User interface (controls) are developed using Microsoft expression Blend and then I import the interface on VB 2005 and start coding.
Everything works well, however the code below does not work simply because the keyPress event is not available for my User interface.
So I'm wondering where else I can put the code below, or anything that might help.

Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
  2.  
  3.     Dim num As String = TextBox1.Text
  4.     If IsNumeric(e.KeyChar) And num.Length < 10 Then
  5.         e.Handled = False
  6.     ElseIf AscW(e.KeyChar) = 8 Then
  7.         e.Handled = False
  8.     Else
  9.         e.Handled = True
  10.     End If
  11. End Sub
Oct 6 '07 #1
0 1716

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4378
by: Joe Su | last post by:
Is there a way to make a control based on Windows.Forms.TextBox, and it has a TextChanging event fired before Text property value change. otherwise there are two properties in the event args 1. ChangedText : it is the text after changed 2. Cancel : if user set Cancel to True then cancel the change of text, and do not fire the TextChanged event Expecting... *** Sent via Developersdex http://www.developersdex.com ***
9
10118
by: Jerry | last post by:
In limiting textbox input to 500 characters I would like to include a dynamic count of characters input while the user is typing into a textbox. This would obviously be a client side control, possibly a custom validator with a function written in javascript. Has anyone done this? Does someone have an example? Regards
5
23036
by: PD | last post by:
The TextChanged event is not being called when I hit the "Enter" key. Yet it does for the "Tab" key. I set a break point in the Page_Load event and the TextChanged event and none of these get called when I hit the 'Enter' key. After typing in letters in the textbox, if I hit the 'Tab' key or click outside the text box with my mouse, the event fires. Here's the code: <form id="frmArticle" name="frmArticle" method="post" runat="server">
7
2237
by: Peter D.C. | last post by:
Hi I want to update data hold in several textbox controls on an asp.net form. But it seems like it is the old textbox values that is "re-updates" through a stored procedure who updates a SQL tabel. I know the SP works, because a smalldatetime-field in the database is changed. I've tried to disable viewstate on all textbox controls. Any ideas to solve this problem.
2
2636
by: active | last post by:
I have a picturebox usercontrol sitting on a usercontrol. I need a KeyPress event in the PictureBox. I suppose I could have a property in the pictureBox that is accessed by a call in a KeyPressed event in the UserControl. Right? Kind of kludge - is there a more direct way? The usercontrol needs no KeyPress event at all and the Picturebox needs them all.
4
3624
by: Tim Osborne | last post by:
Hi At first blush this seemed like it should be so simple. Guess again. I want to only allow numeric characters and hexadecimal values in a TextBox, anything else should be ignored, and maybe a beep be issued. So I figure I need a KeyDown event and I just have to mark it as Handled, right?
14
14634
by: teddysnips | last post by:
WINDOWS FORMS I've a form that has a textbox that allows the user to enter a string. On the LostFocus event, the textbox formats the string into a preferred format. However, if the user presses the "Save" button while the textbox has the focus, the LostFocus code doesn't run at the right time, so that the "Save" function is dealing with an incorrectly formatted string and the whole caboodle goes splat.
0
11999
by: Anonieko | last post by:
Are there any javascript codes there? Answer: Yes On the PageLoad event call InitialClientControsl as follows /// <summary> /// This will add client-side event handlers for most of the form controls so
2
4909
by: =?Utf-8?B?SmVycnkgSg==?= | last post by:
Hello, I am using asp.net 2003 using C#. I am creating textboxes dynamically and want to validate to make sure the user can only input an integer. I don't think I can use the validators because I don't know what the ID of the textbox is ahead of time. I am trying to do it with javascript with a tableCell.Attributes.Add. I'm not sure I can do what I am trying.
0
9387
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
10148
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
9823
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
8822
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
6643
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
5270
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
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
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
3
2794
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.