another question

  • Thread starter Thread starter dawn
  • Start date Start date
D

dawn

Hi,

I know I must be becoming a pain in the ass, but i've encountered yet
another little problem :

I catch an enter keypress with the KeyPress event handler....it does what it
needs to do.....but then after that it still fire the event for the button
that is active at that moment.

I've set e.Handled = true; but it still does that, any way i can resolve
this?

thanks (again :-))
 
dawn,

It should fire the event. The click event is separate from a key press
event. The Handled property is used to indicate if the key press has been
handled. However, pressing the space bar on a button has the effect of
clicking it. If you want to get around this, then for your button, I would
have a module level variable that is set to true when the space bar is
pressed. Then, in the click event handler for your button, check to see if
the flag is true. If it is, do nothing, otherwise, do your processing.

However, this makes me wonder, since the space key and clicking the
button has the same desired effect, why not just handle the click event and
write the code in one place?

Hope this helps.
 
Well, it doesn't have the desired the desired effect....i press the spacebar
and it does what it needs to do....but then it fires the click event (which
I don't need)....so i'll try it with the flag.

thanks for ur help
Nicholas Paldino said:
dawn,

It should fire the event. The click event is separate from a key press
event. The Handled property is used to indicate if the key press has been
handled. However, pressing the space bar on a button has the effect of
clicking it. If you want to get around this, then for your button, I would
have a module level variable that is set to true when the space bar is
pressed. Then, in the click event handler for your button, check to see if
the flag is true. If it is, do nothing, otherwise, do your processing.

However, this makes me wonder, since the space key and clicking the
button has the same desired effect, why not just handle the click event and
write the code in one place?

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

dawn said:
Hi,

I know I must be becoming a pain in the ass, but i've encountered yet
another little problem :

I catch an enter keypress with the KeyPress event handler....it does
what
it
needs to do.....but then after that it still fire the event for the button
that is active at that moment.

I've set e.Handled = true; but it still does that, any way i can resolve
this?

thanks (again :-))
 
I think what Nicholas said might be rephrased (forgive me Nicholas if I'm
wrong) this way:

In standard windows forms, pressing the space bar when a button has focus
has the same effect as clicking on the button. Are you absolutely sure you
really want to change this standard behavior for your application? (I'm a
BIG proponent of leaving standard behavior as is, BTW.) If not, then you
can really just write your code in the click event. (But I take it from
your questions that is not the "desired" effect.)

dawn said:
Well, it doesn't have the desired the desired effect....i press the spacebar
and it does what it needs to do....but then it fires the click event (which
I don't need)....so i'll try it with the flag.

thanks for ur help
Nicholas Paldino said:
dawn,

It should fire the event. The click event is separate from a key press
event. The Handled property is used to indicate if the key press has been
handled. However, pressing the space bar on a button has the effect of
clicking it. If you want to get around this, then for your button, I would
have a module level variable that is set to true when the space bar is
pressed. Then, in the click event handler for your button, check to see if
the flag is true. If it is, do nothing, otherwise, do your processing.

However, this makes me wonder, since the space key and clicking the
button has the same desired effect, why not just handle the click event and
write the code in one place?

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

dawn said:
Hi,

I know I must be becoming a pain in the ass, but i've encountered yet
another little problem :

I catch an enter keypress with the KeyPress event handler....it does
what
it
needs to do.....but then after that it still fire the event for the button
that is active at that moment.

I've set e.Handled = true; but it still does that, any way i can resolve
this?

thanks (again :-))
 
Back
Top