By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,143 Members | 1,908 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,143 IT Pros & Developers. It's quick & easy.

KeyPress question

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.