From: Alex K. on 7 May 2010 16:14 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
From: Alex K. on 7 May 2010 16:16 forgot to mention: I am using VS 2005 in XP Sp3 "Alex K." wrote: > 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
From: Peter Duniho on 7 May 2010 21:33 Alex K. wrote: > [...] > 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. The user _does_ always get the confirmation. They just happen to dismiss it before it's been around long enough for them to see it. As for clearing the keyboard buffer, no….NET doesn't have anything for that. But even if it did, it wouldn't help. There will _always_ be a point in time during which the user can enter input that would dismiss the MessageBox before the user's had a chance to see it. A better solution would be for you to implement your own modal dialog for the purpose. It's fairly trivial to design a regular Form sub-class that will show the information the way you want. Once you've done that, you can include a timer in the Form, override the OnFormClosing() method, and if the timer hasn't expired yet, cancel the close. That will ensure that any input to close the Form sub-class before whatever minimum time you choose has passed will be ignored. Pete
From: Johnny Jörgensen on 8 May 2010 04:09 Why not just do: private void buttonSave_Click(object sender, System.EventArgs e) { buttonSave.Enabled = false; DoSomething(); SaveObject(); MessageBox("Object saved"); buttonSave.Enabled = true; } ??? /Johnny J. -----Ursprungligt meddelande----- Från: Alex K. [mailto:AlexK(a)discussions.microsoft.com] Anslaget den: den 7 maj 2010 22:14 Anslaget i: microsoft.public.dotnet.languages.csharp Konversation: how to clear keyboard buffer? Ämne: how to clear keyboard buffer? 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
From: Harlan Messinger on 8 May 2010 07:31 Alex K. wrote: > 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. If there are users to whom this is happening, I would classify it as a problem those users have with using a computer rather than a problem they are having with your application, and therefore outside the scope of my concern. People who use the keyboard to activate button controls either know how to do that, in which case there isn't a problem for your to fix, or don't, in which case their problem is pervasive and they are doomed unless they figure out what they are doing wrong. Having a single application out there that has special code to save these people from themselves in exactly one instance isn't really doing them a big favor.
|
Next
|
Last
Pages: 1 2 Prev: help me! Next: Delegate Called via System.Reflection.Emit Returning Wrong Value |