[RESOLVED] Enable / Disable button-VBForums
Results 1 to 7 of 7

Thread: [RESOLVED] Enable / Disable button

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2010
    Location
    Greece
    Posts
    55

    Resolved [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.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,597

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2010
    Location
    Greece
    Posts
    55

    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.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,597

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2010
    Location
    Greece
    Posts
    55

    Re: Enable / Disable button

    Done. Found out how it works. Thanks!

  6. #6
    Registered User
    Join Date
    Jul 2015
    Posts
    3

    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)
    {

    }

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,597

    Re: Enable / Disable button

    Quote Originally Posted by camycent View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.