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

Weird Form Event Occurances

P: n/a
Hi,

Don't know if anyone can cast any light on this...
I have a fairly complex C# WinForm with (amongst other) a text box and a
button.
The TextBox has events declared for KeyUp and KeyDown, the button has a
simple Click event.

Under certain circumstances (haven't worked out exactly what they are yet,
but it involves opening and closing a sub form). Pressing ENTER with the
cursor in the textbox causes the Button Click event to fire...!!
Can anyone make ANY suggestions as to where I could start troubleshooting
this?

Thanks,

ChrisM
Jun 21 '06 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Chris,

I'd have to see a sample to believe this. I think that maybe you might
be doing something you might not be aware of which results in the code being
executed.

Can you post a working sample?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"ChrisM" <ch**************@suedeyahoo.com> wrote in message
news:OI**************@TK2MSFTNGP05.phx.gbl...
Hi,

Don't know if anyone can cast any light on this...
I have a fairly complex C# WinForm with (amongst other) a text box and a
button.
The TextBox has events declared for KeyUp and KeyDown, the button has a
simple Click event.

Under certain circumstances (haven't worked out exactly what they are yet,
but it involves opening and closing a sub form). Pressing ENTER with the
cursor in the textbox causes the Button Click event to fire...!!
Can anyone make ANY suggestions as to where I could start troubleshooting
this?

Thanks,

ChrisM

Jun 21 '06 #2

P: n/a

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:Of**************@TK2MSFTNGP02.phx.gbl...
Chris,

I'd have to see a sample to believe this. I think that maybe you might
be doing something you might not be aware of which results in the code
being executed.

Can you post a working sample?


I'm sure you're right, but I've checked all the things I can think of, and
there's nothing else that calls the myButton_Click...
code. I can't really post an example as it is an integral part of a fairly
sizable application, and I don't think I can extract the code with the
problem without including most of the rest of the application...

A little more experimentation has shown that the 'KeyDown' event of the
TextBox stops receiving the Enter key when it becomes 'crosswired' with the
Buttons Click event.

I will see if I can create a small working demo of the problem, but I'm not
too hopeful.

Thanks for your reply anyway.

Chris.
Jun 21 '06 #3

P: n/a

"ChrisM" <ch**************@suedeyahoo.com> wrote in message
news:O8**************@TK2MSFTNGP02.phx.gbl...

"ChrisM" <ch**************@suedeyahoo.com> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:Of**************@TK2MSFTNGP02.phx.gbl...
Chris,

I'd have to see a sample to believe this. I think that maybe you
might
be doing something you might not be aware of which results in the code
being executed.

Can you post a working sample?


I'm sure you're right, but I've checked all the things I can think of,
and
there's nothing else that calls the myButton_Click...
code. I can't really post an example as it is an integral part of a
fairly
sizable application, and I don't think I can extract the code with the
problem without including most of the rest of the application...

A little more experimentation has shown that the 'KeyDown' event of the
TextBox stops receiving the Enter key when it becomes 'crosswired' with
the
Buttons Click event.

I will see if I can create a small working demo of the problem, but I'm
not
too hopeful.

Thanks for your reply anyway.

Chris.


OK,

It wasn't actually as hard to reproduce the problem as I thought...
I have attached a Zip file containing a sample project that shows exactly
the problem I'm having.

There are Three forms:
Form1 - An MDI Parent Form.
FormMain - A child form which represents a Menu Form.
FormDemo - Another child form that represents the form with the problem.

To reproduce the problem:
1) Run the application and you should get the Parent form containing the
Menu Form.
2) Click the button - should pull up the other child form.
3) Make sure focus is in the text box and press ENTER - should get
appropriate message.
4) Click the button - should appropriate message, and Menu Form comes to
front.
5) CLOSE Menu Form (Click on X in Top RH Corner)
6) Make sure focus is in the Textbox and press ENTER.
7) Explain that...!

If you have any problems with the attachment, and are prepared to help,
email me on this address and I can email you the code.
( Remove Blue and Suede from my email address to reply).

Thanks,

Chris.


btw, this is all running in VS2003 / Framework 1.1

Chris.
Jun 21 '06 #4

P: n/a
Chris,
What is the value of the TextBox.AcceptsReturn property?

ChrisM wrote:
Hi,

Don't know if anyone can cast any light on this...
I have a fairly complex C# WinForm with (amongst other) a text box and a
button.
The TextBox has events declared for KeyUp and KeyDown, the button has a
simple Click event.

Under certain circumstances (haven't worked out exactly what they are yet,
but it involves opening and closing a sub form). Pressing ENTER with the
cursor in the textbox causes the Button Click event to fire...!!
Can anyone make ANY suggestions as to where I could start troubleshooting
this?

Thanks,

ChrisM

Jun 21 '06 #5

P: n/a
FALSE, but changing it to TRUE doesn't seem to help...

Thanks anyway. If you want to have a play, see my other post in this thread
with a sample project attached...

Cheers,

Chris.
"cds_tf_1" <cd******@hotmail.com> wrote in message
news:O8**************@TK2MSFTNGP02.phx.gbl...
Chris,
What is the value of the TextBox.AcceptsReturn property?

ChrisM wrote:
Hi,

Don't know if anyone can cast any light on this...
I have a fairly complex C# WinForm with (amongst other) a text box and a
button.
The TextBox has events declared for KeyUp and KeyDown, the button has a
simple Click event.

Under certain circumstances (haven't worked out exactly what they are
yet, but it involves opening and closing a sub form). Pressing ENTER with
the cursor in the textbox causes the Button Click event to fire...!!
Can anyone make ANY suggestions as to where I could start troubleshooting
this?

Thanks,

ChrisM

Jun 21 '06 #6

P: n/a
"ChrisM" <ch**************@suedeyahoo.com> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...

"ChrisM" <ch**************@suedeyahoo.com> wrote in message
news:O8**************@TK2MSFTNGP02.phx.gbl...

"ChrisM" <ch**************@suedeyahoo.com> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:Of**************@TK2MSFTNGP02.phx.gbl...
Chris,

I'd have to see a sample to believe this. I think that maybe you
might
be doing something you might not be aware of which results in the code
being executed.

Can you post a working sample?
I'm sure you're right, but I've checked all the things I can think of,
and
there's nothing else that calls the myButton_Click...
code. I can't really post an example as it is an integral part of a
fairly
sizable application, and I don't think I can extract the code with the
problem without including most of the rest of the application...

A little more experimentation has shown that the 'KeyDown' event of the
TextBox stops receiving the Enter key when it becomes 'crosswired' with
the
Buttons Click event.

I will see if I can create a small working demo of the problem, but I'm
not
too hopeful.

Thanks for your reply anyway.

Chris.


OK,

It wasn't actually as hard to reproduce the problem as I thought...
I have attached a Zip file containing a sample project that shows exactly
the problem I'm having.

There are Three forms:
Form1 - An MDI Parent Form.
FormMain - A child form which represents a Menu Form.
FormDemo - Another child form that represents the form with the problem.

To reproduce the problem:
1) Run the application and you should get the Parent form containing the
Menu Form.
2) Click the button - should pull up the other child form.
3) Make sure focus is in the text box and press ENTER - should get
appropriate message.
4) Click the button - should appropriate message, and Menu Form comes to
front.
5) CLOSE Menu Form (Click on X in Top RH Corner)
6) Make sure focus is in the Textbox and press ENTER.
7) Explain that...!

If you have any problems with the attachment, and are prepared to help,
email me on this address and I can email you the code.
( Remove Blue and Suede from my email address to reply).

Thanks,

Chris.


btw, this is all running in VS2003 / Framework 1.1


Very weird! I've run your code and get exactly the same (inexplicable)
results.

If it's any help, I've also run it in VS2005 and Framework 2.0, and there it
behaves properly, so it looks like it's some sort of bug in the Framework
1.1. Sorry, no more time to investigate now. Good luck!

Chris Jobson
Jun 21 '06 #7

P: n/a
Chris,
Just for informational purposes, I don't think this group allows for
attachments. Even if it does, many people use the online Web - based version
of the reader, which definitely does not allow for same. So, you'll need to
post code samples "inline" in your message.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"ChrisM" wrote:
FALSE, but changing it to TRUE doesn't seem to help...

Thanks anyway. If you want to have a play, see my other post in this thread
with a sample project attached...

Cheers,

Chris.
"cds_tf_1" <cd******@hotmail.com> wrote in message
news:O8**************@TK2MSFTNGP02.phx.gbl...
Chris,
What is the value of the TextBox.AcceptsReturn property?

ChrisM wrote:
Hi,

Don't know if anyone can cast any light on this...
I have a fairly complex C# WinForm with (amongst other) a text box and a
button.
The TextBox has events declared for KeyUp and KeyDown, the button has a
simple Click event.

Under certain circumstances (haven't worked out exactly what they are
yet, but it involves opening and closing a sub form). Pressing ENTER with
the cursor in the textbox causes the Button Click event to fire...!!
Can anyone make ANY suggestions as to where I could start troubleshooting
this?

Thanks,

ChrisM


Jun 22 '06 #8

P: n/a
Peter,
Thanks for your message. I wasn't sure how many people would be able to get
at the attachment.
In order to show what I'm trying to explain however, requires a complete
mini-project containing 3 forms, too much code to sensibly include in-line
IMHO.
The best I can say is if anyone is interested in trying to help, or just
wants to see what is happening, I can email them the zip file for them to
look at. Hence my offer to email it to any interested parties.

Thanks,

Chris.

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:95**********************************@microsof t.com...
Chris,
Just for informational purposes, I don't think this group allows for
attachments. Even if it does, many people use the online Web - based
version
of the reader, which definitely does not allow for same. So, you'll need
to
post code samples "inline" in your message.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"ChrisM" wrote:
FALSE, but changing it to TRUE doesn't seem to help...

Thanks anyway. If you want to have a play, see my other post in this
thread
with a sample project attached...

Cheers,

Chris.
"cds_tf_1" <cd******@hotmail.com> wrote in message
news:O8**************@TK2MSFTNGP02.phx.gbl...
> Chris,
> What is the value of the TextBox.AcceptsReturn property?
>
> ChrisM wrote:
>> Hi,
>>
>> Don't know if anyone can cast any light on this...
>> I have a fairly complex C# WinForm with (amongst other) a text box and
>> a
>> button.
>> The TextBox has events declared for KeyUp and KeyDown, the button has
>> a
>> simple Click event.
>>
>> Under certain circumstances (haven't worked out exactly what they are
>> yet, but it involves opening and closing a sub form). Pressing ENTER
>> with
>> the cursor in the textbox causes the Button Click event to fire...!!
>> Can anyone make ANY suggestions as to where I could start
>> troubleshooting
>> this?
>>
>> Thanks,
>>
>> ChrisM


Jun 22 '06 #9

P: n/a
Hi,
AcceptReturn only apply when the textbox is multiline
"ChrisM" <ch**************@suedeyahoo.com> wrote in message
news:Oq**************@TK2MSFTNGP04.phx.gbl...
FALSE, but changing it to TRUE doesn't seem to help...

Thanks anyway. If you want to have a play, see my other post in this
thread with a sample project attached...

Cheers,

Chris.
"cds_tf_1" <cd******@hotmail.com> wrote in message
news:O8**************@TK2MSFTNGP02.phx.gbl...
Chris,
What is the value of the TextBox.AcceptsReturn property?

ChrisM wrote:
Hi,

Don't know if anyone can cast any light on this...
I have a fairly complex C# WinForm with (amongst other) a text box and a
button.
The TextBox has events declared for KeyUp and KeyDown, the button has a
simple Click event.

Under certain circumstances (haven't worked out exactly what they are
yet, but it involves opening and closing a sub form). Pressing ENTER
with the cursor in the textbox causes the Button Click event to
fire...!!
Can anyone make ANY suggestions as to where I could start
troubleshooting this?

Thanks,

ChrisM


Jun 22 '06 #10

P: n/a
Hi,

What you are seeing is the expected behavior I think.

First if you want to accept the Enter you need to set the textbox to
multiline. if you do not want to show it you can cancel it in the keydown
handler.

Another possible solution is to put the button as TabIndex = 0 and the
textbox as tabindex =1. that very simple change will prevent the "enter" to
be processed by the next control

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"ChrisM" <ch**************@suedeyahoo.com> wrote in message
news:O8**************@TK2MSFTNGP02.phx.gbl...

"ChrisM" <ch**************@suedeyahoo.com> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:Of**************@TK2MSFTNGP02.phx.gbl...
Chris,

I'd have to see a sample to believe this. I think that maybe you
might
be doing something you might not be aware of which results in the code
being executed.

Can you post a working sample?


I'm sure you're right, but I've checked all the things I can think of,
and
there's nothing else that calls the myButton_Click...
code. I can't really post an example as it is an integral part of a
fairly
sizable application, and I don't think I can extract the code with the
problem without including most of the rest of the application...

A little more experimentation has shown that the 'KeyDown' event of the
TextBox stops receiving the Enter key when it becomes 'crosswired' with
the
Buttons Click event.

I will see if I can create a small working demo of the problem, but I'm
not
too hopeful.

Thanks for your reply anyway.

Chris.


OK,

It wasn't actually as hard to reproduce the problem as I thought...
I have attached a Zip file containing a sample project that shows exactly
the problem I'm having.

There are Three forms:
Form1 - An MDI Parent Form.
FormMain - A child form which represents a Menu Form.
FormDemo - Another child form that represents the form with the problem.

To reproduce the problem:
1) Run the application and you should get the Parent form containing the
Menu Form.
2) Click the button - should pull up the other child form.
3) Make sure focus is in the text box and press ENTER - should get
appropriate message.
4) Click the button - should appropriate message, and Menu Form comes to
front.
5) CLOSE Menu Form (Click on X in Top RH Corner)
6) Make sure focus is in the Textbox and press ENTER.
7) Explain that...!

If you have any problems with the attachment, and are prepared to help,
email me on this address and I can email you the code.
( Remove Blue and Suede from my email address to reply).

Thanks,

Chris.

Jun 22 '06 #11

P: n/a
Hi,
Thanks for your reply.

I can't really change the Tab Order on my real application, as the tab order
that is set up is the required one. That is, the user needs to go to the
TextBox before they press the button (If they choose to press the button).
I don't want the ENTER to appear in the textbox, the idea is someone enters
some text in the box, and presses ENTER to perform an operation on that text
(in the actual application, it is a Search box). The button performs a
totally different task.

The strange thing is that at first, it all works as expected, pressing ENTER
in the TextBox fires that event, and clicking on the button fires the Click
event. It is only after changing to the second form and back that things
work differently. That is what is confusing me.

If you haven't tried the example project that I wrote to illustrate the
problem, and are still interested, I suggest that you have a look, as it
really does make the problem much clearer than my explanation.

Cheers,

Chris.

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:%2****************@TK2MSFTNGP03.phx.gbl...
Hi,

What you are seeing is the expected behavior I think.

First if you want to accept the Enter you need to set the textbox to
multiline. if you do not want to show it you can cancel it in the keydown
handler.

Another possible solution is to put the button as TabIndex = 0 and the
textbox as tabindex =1. that very simple change will prevent the "enter"
to be processed by the next control

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"ChrisM" <ch**************@suedeyahoo.com> wrote in message
news:O8**************@TK2MSFTNGP02.phx.gbl...

"ChrisM" <ch**************@suedeyahoo.com> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:Of**************@TK2MSFTNGP02.phx.gbl...
Chris,

I'd have to see a sample to believe this. I think that maybe you
might
be doing something you might not be aware of which results in the code
being executed.

Can you post a working sample?
I'm sure you're right, but I've checked all the things I can think of,
and
there's nothing else that calls the myButton_Click...
code. I can't really post an example as it is an integral part of a
fairly
sizable application, and I don't think I can extract the code with the
problem without including most of the rest of the application...

A little more experimentation has shown that the 'KeyDown' event of the
TextBox stops receiving the Enter key when it becomes 'crosswired' with
the
Buttons Click event.

I will see if I can create a small working demo of the problem, but I'm
not
too hopeful.

Thanks for your reply anyway.

Chris.


OK,

It wasn't actually as hard to reproduce the problem as I thought...
I have attached a Zip file containing a sample project that shows exactly
the problem I'm having.

There are Three forms:
Form1 - An MDI Parent Form.
FormMain - A child form which represents a Menu Form.
FormDemo - Another child form that represents the form with the problem.

To reproduce the problem:
1) Run the application and you should get the Parent form containing the
Menu Form.
2) Click the button - should pull up the other child form.
3) Make sure focus is in the text box and press ENTER - should get
appropriate message.
4) Click the button - should appropriate message, and Menu Form comes to
front.
5) CLOSE Menu Form (Click on X in Top RH Corner)
6) Make sure focus is in the Textbox and press ENTER.
7) Explain that...!

If you have any problems with the attachment, and are prepared to help,
email me on this address and I can email you the code.
( Remove Blue and Suede from my email address to reply).

Thanks,

Chris.


Jun 23 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.