[RESOLVED] Enable / Disable button
Hello guys!
I am trying to create a button to enable / dsiable a bunch of code.
I would like to use the same button. In the first ''click'' i would like to enable the code (i.e. Play sound file) and in the second "click" to disable the code (i.e. Stop sound file)
How can I do that?
THanks.
Re: Enable / Disable button
I'm not 100% sure what you mean by enable and disable code because that's not actually possible but, basically, you would use a Button to toggle a flag like this:
Code:
Private flag As Boolean
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.flag = Not Me.flag
'...
End Sub
You can then act or not based on that flag.
Re: Enable / Disable button
I have found a code to embed a sound file to the project
http://www.vbforfree.com/how-to-play...al-basic-2010/
So far everything is fine, sound plays good. The problem is that, I have a button to play the sound and I want to click the same button to stop the sound...
That project is a sample to embed .wav and .midi files. The .wav code has one button (play sound). The .midi code has two buttons (play sound/ stop sound). I am tryind to convert the .midi code to .wav, so I can have at least a ''stop'' button. Still no luck..
I was wondering if there is a way to write down some lines of code, to use the same button to play / stop the .wav sound.
Re: Enable / Disable button
The code example you are using is calling the Play method of a SoundPlayer object. Have you read the documentation for that SoundPlayer class? If not, why not? If you want to know how to use a type then reading the Help for that type should be the obvious first step. If you'd done that then you would have quickly seen that it also has a Stop method. Do as I've already told you and then simply call Play or Stop based on the flag.
Re: Enable / Disable button
Done. Found out how it works. Thanks!
Re: Enable / Disable button
You can use this code
protected void Page_Load(object sender, EventArgs e)
{
btnClick.Attributes.Add("onclick", "this.disabled=true");
}
protected void Test(object sender, EventArgs e)
{
}
Re: Enable / Disable button
Quote:
Originally Posted by
camycent
You can use this code
protected void Page_Load(object sender, EventArgs e)
{
btnClick.Attributes.Add("onclick", "this.disabled=true");
}
protected void Test(object sender, EventArgs e)
{
}
That's not going to help, given that this is not for ASP.NET.