-
Aug 8th, 2015, 04:54 AM
#1
Thread Starter
Member
[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.
-
Aug 8th, 2015, 06:53 AM
#2
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.
-
Aug 8th, 2015, 08:54 AM
#3
Thread Starter
Member
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.
-
Aug 8th, 2015, 09:34 AM
#4
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.
-
Aug 9th, 2015, 05:05 AM
#5
Thread Starter
Member
Re: Enable / Disable button
Done. Found out how it works. Thanks!
-
Aug 10th, 2015, 04:30 AM
#6
Registered User
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)
{
}
-
Aug 10th, 2015, 08:19 AM
#7
Re: Enable / Disable button
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|