Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't disable a button 1

Status
Not open for further replies.

forrestcupp

Programmer
Jul 22, 2006
25
I have a form where a certain button plays an audio file that is about 3 seconds long. I am using System.Media.SoundPlayer.PlaySync() because I don't want the user to do anything while the audio is playing. So my code is something like.

button.Enabled = false;
MySound.PlaySync();
button.Enabled = true;

My problem is that even though I have disabled the button, it still accepts clicks. So if I click the button 10 times while the audio plays for 3 seconds, it will repeat the audio 10 times. I want to truly disable the button so that it will not accept clicks. I don't understand the point of graying out a button if it isn't truly disabled. I have also tried:

button.Click -= new EventHandler(MyClick);
MySound.PlaySync();
button.Click += new EventHandler(MyClick);

That didn't work either. Any help would be appreciated.
 
I just found the solution thanks to a man named Kevin Delafield. It is as follows:

button.Enabled = false;
button.Update();
MySound.PlaySync();
Application.DoEvents();
button.Enabled = true;

this worked perfectly.
 
Thanks, Forrest, for posting what you found.

----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top