473,670 Members | 2,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to override a TextBox's KeyPress event

Hi,

How do I override a TextBox's KeyPress evnt? And how do we use it?
Thanks for help.
Jason
Aug 7 '08 #1
2 6262
Hi
Set the KeyPressEventAr gs.Handled to True to cancel the event.
--
---------------------------
Thanks,
Ibrahim

Software Consultant - Web Development, GB
"Jason Huang" wrote:
Hi,

How do I override a TextBox's KeyPress evnt? And how do we use it?
Thanks for help.
Jason
Aug 7 '08 #2
On 7 août, 11:04, "Jason Huang" <JasonHuang8... @hotmail.comwro te:
Hi,

How do I override a TextBox's KeyPress evnt? * And how do we use it?
Thanks for help.

Jason
I think your question is related to the one you asked a few days ago,
about handling Return in a textbox ?

In the designer, select your textbox (say it's called textBox1),
choose the properties by typing F4, select the events pane by clicking
on the, er, thunder strike icon at the top of the property sheet,
place your cursor inside the "KeyPress" event and type Return. It will
create this method in your code :

private void textBox1_KeyPre ss(object sender, KeyPressEventAr gs e)
{
}

Edit it so :

private void textBox1_KeyPre ss(object sender, KeyPressEventAr gs e)
{
if (e.KeyChar == 13)
{
e.Handled = true;
// Do something : validate your input,
// close your form, whatever
}
}

Just replace the comments with whatever you want to do when the return
key is pressed inside the textbox.

Michel
Aug 7 '08 #3

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

Similar topics

1
4267
by: David Smith | last post by:
What I want to be able to do: A textbox is available that the user can enter information into. Specifically (for the purposes of this post), the user is asked to enter a number, and that number has an upper limit. I want to do validation on what the user enters as they type it in. I set up an event handler for KeyPress that restricts them from being able to enter non-numeric characters (only allowing numbers, decimal point, control...
0
2609
by: Hal Gibson | last post by:
Because of a legacy (originally DOS) Sub Procedure "AlphaInput" that is called in thousands of places in our code, I need to be able to set a variable, "KeyedString",to the value of TextBox.Text (KeyedString originally was set by tracking each individual key pressed, independently of textbox.text) Since we're setting KeyedString during the keypress event, Textbox.Text is always one character behind.
4
1913
by: Fool | last post by:
Hi, I want a rich textbox that dynamically highlights particular words immediately after they are typed. Just looking for some general tips... I tried putting some code in a sub that handles the textchanged event for that textbox. The issue here is that the focus jumps to the words to be highlighted (naturally, I suppose, since my technique is to search for specific words, select them, and highlight them). But I
7
4577
by: scottiedog | last post by:
Hi How can I send a char to Textbox so that KeyPress event is called? I have a button and with a click I would like to send a char, e.g. "C", to the Textbox. But Textbox1_KeyPress is not catching the event (I can step thru KeyPress ok but nothing goes to TextBox). KeyPress itself works fine with key stroke via keyboard Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Clic Dim e2 As New...
1
6839
by: Steve | last post by:
I would like to override the IsInputKey function in order to trap the arrow up/down keys in the Key Events. I understand that arrow keys don't have a char representation and thus, hard to trap. Someone wrote this override for IsInputKey in C# which apparently worked, and I tried to convert it to VB.Net but not working. Here is the C# version and following - my conversion. It would be great if anyone out there knows how to do this...
6
3198
by: Avi G | last post by:
Hi, what is the code to limit a textbox that will accept only text and not number private void button1_Click(object sender, EventArgs e) { if (textBox1.Text = "numbers") { // do something }
21
9156
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on the cancel button, the textbox.validating is being called. I don't want it to be since they are exiting the screen the validation doesn't have to be done. How can I do that.
3
2119
by: windy | last post by:
I got a question about keypress event on textbox: I found that the keypress event doesn't invoked when i press the "." button on alphabetic keyboard, however if i use numberpad's "." button keypress event is invoked. Any idea and solutions? Thanks.
8
5744
by: nil | last post by:
Hello all, It's urgent... i want to add autocomplete textbox facility in my application like google. as you type it suggests option to the user..i want the same kind of facility...i know i can do only with ajax(xml and javascript) but i want to fetch possible values from database and want to show as the user types in text box.
0
8384
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
8896
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
8810
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8590
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7410
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...
1
6211
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5683
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
4208
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...
1
2798
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

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.