473,788 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

KeyPress question

I am new to C# and wanted to capture the KeyPress for a textbox.

I created some code as follows:

private void textBox3_KeyPre ss(object sender, System.EventArg s e)

{

this.textBox2.T ext = sender.ToString ();

}

When I ran the code in debug, this function wasn't even entered. How can I
capture the KeyPress event (or Keydown)?

Bonus question: Why aren't all the methods listed in the IDE when in code
view? In VB they are?

Aug 2 '06 #1
5 3083
Henry Jones wrote:
I am new to C# and wanted to capture the KeyPress for a textbox.

I created some code as follows:

private void textBox3_KeyPre ss(object sender, System.EventArg s e)

{

this.textBox2.T ext = sender.ToString ();

}

When I ran the code in debug, this function wasn't even entered. How can I
capture the KeyPress event (or Keydown)?

Hi Henry,

Looks to me like you haven't wired the TextBox's KeyPress event up to
your method, like this:

this.textBox3.K eyPress += new
System.Windows. Forms.KeyPressE ventHandler(thi s.textBox3_KeyP ress);

That will then result in the textbox keypress event firing and then
kicking off your method.

HTH

Dave
Aug 2 '06 #2
Hi,

Are you sure that the textBox3.KeyCha ngd event is being assigned?

Bonus question: Why aren't all the methods listed in the IDE when in code
view? In VB they are?
What you mean with this? all the method are listed in the dropdown where the
class member are listed.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Aug 2 '06 #3
On my form I added a textbox called textBox4. When I look at the drop down
on the members list on Code View, I only see textBox4. No methods are
listed. If I double click on the textBox4, I will then see
textBox4_TextCh anged.

If you do the same thing in VB, you will see all the methods for the
textBox4. I was wondering why this doesn't happen in C#. I am using Visual
Studio 2003.
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us wrote
in message news:Om******** ******@TK2MSFTN GP02.phx.gbl...
Hi,

Are you sure that the textBox3.KeyCha ngd event is being assigned?

>Bonus question: Why aren't all the methods listed in the IDE when in
code
view? In VB they are?

What you mean with this? all the method are listed in the dropdown where
the class member are listed.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Aug 2 '06 #4
Hi,

VB and C# are different in that aspect ( I think C# approach is better ) ,
In the design view select the textbox, go to property, select Events ( a
little thunder icon ) and there you have all the events, double click the
one you need and a stub method will be generated for you.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Henry Jones" <he********@yad a.comwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
On my form I added a textbox called textBox4. When I look at the drop
down on the members list on Code View, I only see textBox4. No methods
are listed. If I double click on the textBox4, I will then see
textBox4_TextCh anged.

If you do the same thing in VB, you will see all the methods for the
textBox4. I was wondering why this doesn't happen in C#. I am using
Visual Studio 2003.
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >
wrote in message news:Om******** ******@TK2MSFTN GP02.phx.gbl...
>Hi,

Are you sure that the textBox3.KeyCha ngd event is being assigned?

>>Bonus question: Why aren't all the methods listed in the IDE when in
code
view? In VB they are?

What you mean with this? all the method are listed in the dropdown where
the class member are listed.
--
--
Ignacio Machin,
ignacio.mach in AT dot.state.fl.us
Florida Department Of Transportation


Aug 3 '06 #5
Ignacio,

Thanks for the tip on how to get the events. You are right, it is more
elegant than the way VB does it.

Henry

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us wrote
in message news:OD******** ******@TK2MSFTN GP04.phx.gbl...
Hi,

VB and C# are different in that aspect ( I think C# approach is better ) ,
In the design view select the textbox, go to property, select Events ( a
little thunder icon ) and there you have all the events, double click the
one you need and a stub method will be generated for you.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Henry Jones" <he********@yad a.comwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
>On my form I added a textbox called textBox4. When I look at the drop
down on the members list on Code View, I only see textBox4. No methods
are listed. If I double click on the textBox4, I will then see
textBox4_TextC hanged.

If you do the same thing in VB, you will see all the methods for the
textBox4. I was wondering why this doesn't happen in C#. I am using
Visual Studio 2003.
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >
wrote in message news:Om******** ******@TK2MSFTN GP02.phx.gbl...
>>Hi,

Are you sure that the textBox3.KeyCha ngd event is being assigned?
Bonus question: Why aren't all the methods listed in the IDE when in
code
view? In VB they are?
What you mean with this? all the method are listed in the dropdown where
the class member are listed.
--
--
Ignacio Machin,
ignacio.machi n AT dot.state.fl.us
Florida Department Of Transportation



Aug 3 '06 #6

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

Similar topics

1
3504
by: dave | last post by:
I've designed a nice little App that works something like a spreadsheet using the MSHFlexgrid control. Many users are inclined to press the tab key, expecting the program to respond like excel would but it doesn't. It simply leaves the MSHFlexgrid ang they loose the data they were entering in the particular cell. Is there some way I can receive the tab keypress in some event processing routine so I can respond as I do with a return...
4
8990
by: phil_gg04 | last post by:
Dear Javascript Experts, I'm currently implementing Anyterm, a terminal emulator on a web page. It consists of an Apache module, some XmlHTTP and a bit of Javascript. The idea is to give you shell access to your server from (almost) anywhere; other solutions to the problem tend to require access to ports other than 80 and Java. The very primitive first attempt is at http://chezphil.org/anyterm/. A more functional version will be...
1
6197
by: Darren Coleman | last post by:
I need help with 2 keyboard/input questions 1. How do i caputre all keypress events for my application/form? 2. How do I determine which keyboard sent the keypress? What i'm doing is using a USB Barcode scanner, windows sees the scanner as a keyboard. When the scanner reads a barcode it decodes the barcode and sends in the decoded values in as keypresses from a keyboard. I want to be able to tell the diffrence between a keypress from a...
3
3072
by: Terry Olsen | last post by:
Is there anyway to cause a KeyPress event in a datagrid cell? The only way I get a keypress event is if none of the cells are selected. I was hoping to have the program respond to a certain keypress while in a cell of a datagrid but it doesn't fire the keypress event.
3
1875
by: Just Me | last post by:
I noticed that I don't get KeyDown nor KetPress events if NumLock is not on. I can probably find a workaround but it would be nice to know what the rules are. Can anyone tell me when KeyPress event is raised and when it isn't. Thanks
3
7278
by: Nikolay Evseev | last post by:
Hi, I am trying to trace down the Enter key in my Form.KeyPress event handler. The KeyPreview property is set to false, so I'd assume that all key presses should go through my form's KeyPress event handler, right? Ok. If the focus is set to any other control than a button, then the above event handler fires, but if the focus is on a button, then I've no way to know that the Enter key has been pressed or not, because in that case pressing...
2
8002
by: Bob | last post by:
In that event, how can you find out if the keypress event was in a certain column? Say you have datagridview1, columnname1, columnName2 You want to do something only with the keypress event of column2, do nothing special with column1 Private Sub Datagrid1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Datagrid1.KeyPress If Me.datagrid1......... Then - how do you specify its for...
4
2802
by: Jeff | last post by:
....still new at this. ...hopefully a simple question Is there some practical way of altering the function of a keypress in Visual Web.net 2005 using VB without causing a postback on each keypress? For example: A have a listbox with a number of selections. The up and down keyboard keys change the indicated listbox selection and by default the <tabkey takes the focus away from the listbox and onto a button that will submit the selection. I'm...
2
19297
by: Tony Johansson | last post by:
Hello! I have created a Control that consist of a label and a textbox.I have called this class ctlLabelTextbox. public partial class ctlLabelTextbox : UserControl { .... } The class that I have created for this purpose is derived from class UserControl.
0
10366
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
9969
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
8993
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
7518
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
6750
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
5399
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
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3675
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.