A
Alex K.
Hi all
On my form I have buttonSAVE button. The buttonSave_Click procedure looks
like this:
private void buttonSave_Click(object sender, System.EventArgs e)
{
DoSomething();
SaveObject();
MessageBox("Object saved");
}
When users use mouse to click the button, everything is fine. But there is a
problem when they use space bar on keyboard:
if you move focus (using TAB key) to SAVE button and then press space bar
two times very quickly, the save procedure successfully executes without
showing confirmation MessageBox. I guess, MessageBox does not appear on the
screen because second stroke of space bar closes it before it is drawn.
As a result, user does not confirmation that object is saved. Even worse, if
you press space bar 4 times, the object will be saved 2 times without
confirmation!
I'd like to make sure user always gets the confirmation, i.e. MessageBox
always shows and waits until user closes it explicitly, ignoring all pending
key strokes that might be in the buffer at the moment when SaveObject()
procedure ends.
I tried to call Application.DoEvents() right before MessageBox.Show, but
that resolved only part of the problem: if I hit space bar twice, I will get
eventually two MessageBoxes, but object is already saved twice when I see the
first message box! All this is extremely confusing. I'd like to avoid second
saving until user sees and aknowledges first confirmation. I think, if I
could clear the keyboard buffer before showing MessageBox (as I used to do in
MS DOS), that would resolve the problem.
Is there not-very-tricky way to do this?
Thank you
On my form I have buttonSAVE button. The buttonSave_Click procedure looks
like this:
private void buttonSave_Click(object sender, System.EventArgs e)
{
DoSomething();
SaveObject();
MessageBox("Object saved");
}
When users use mouse to click the button, everything is fine. But there is a
problem when they use space bar on keyboard:
if you move focus (using TAB key) to SAVE button and then press space bar
two times very quickly, the save procedure successfully executes without
showing confirmation MessageBox. I guess, MessageBox does not appear on the
screen because second stroke of space bar closes it before it is drawn.
As a result, user does not confirmation that object is saved. Even worse, if
you press space bar 4 times, the object will be saved 2 times without
confirmation!
I'd like to make sure user always gets the confirmation, i.e. MessageBox
always shows and waits until user closes it explicitly, ignoring all pending
key strokes that might be in the buffer at the moment when SaveObject()
procedure ends.
I tried to call Application.DoEvents() right before MessageBox.Show, but
that resolved only part of the problem: if I hit space bar twice, I will get
eventually two MessageBoxes, but object is already saved twice when I see the
first message box! All this is extremely confusing. I'd like to avoid second
saving until user sees and aknowledges first confirmation. I think, if I
could clear the keyboard buffer before showing MessageBox (as I used to do in
MS DOS), that would resolve the problem.
Is there not-very-tricky way to do this?
Thank you