473,379 Members | 1,252 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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_KeyPress(object sender, System.EventArgs e)

{

this.textBox2.Text = 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 3050
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_KeyPress(object sender, System.EventArgs e)

{

this.textBox2.Text = 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.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(this.tex tBox3_KeyPress);

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.KeyChangd 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_TextChanged.

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.machin AT dot.state.fl.uswrote
in message news:Om**************@TK2MSFTNGP02.phx.gbl...
Hi,

Are you sure that the textBox3.KeyChangd 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********@yada.comwrote in message
news:%2****************@TK2MSFTNGP05.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_TextChanged.

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.machin AT dot.state.fl.us>
wrote in message news:Om**************@TK2MSFTNGP02.phx.gbl...
>Hi,

Are you sure that the textBox3.KeyChangd 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 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.machin AT dot.state.fl.uswrote
in message news:OD**************@TK2MSFTNGP04.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********@yada.comwrote in message
news:%2****************@TK2MSFTNGP05.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_TextChanged.

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.machin AT dot.state.fl.us>
wrote in message news:Om**************@TK2MSFTNGP02.phx.gbl...
>>Hi,

Are you sure that the textBox3.KeyChangd 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 3 '06 #6

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

Similar topics

1
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...
4
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...
1
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...
3
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...
3
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...
3
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...
2
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...
4
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.