none
Button Won't Disable RRS feed

  • Question

  • I have a number of buttons on a form.  When the Start button is clicked I want to disable a number of the buttons:

     Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
    
                    Dim saveCursor As Cursor = Me.Cursor
            Me.Cursor = Cursors.WaitCursor
    
            btnPasteCLip.Enabled = False  'no more messing with the URLs
            btnPasteLast.Enabled = False
            If btnPasteLast.Enabled = True Then
                MsgBox("sorry, it is still Enabled!")
            End If
            btnType.Enabled = False
            btnStart.Enabled = False
    
            pnlURLs.Enabled = False  'no more messing with the URLs
    
            Sleep(100)
            Me.Update()

    ... and then following the code above the button click routines a lot of cpu processing.  

    The problem is that one button, btnPasteLast does not display as disabled!  I.E it still appears Enabled.  All of the other disabling that you see above appears instantly on the form.  By using the debugger I can see that the button is actually disabled.  And the fact that the message ("sorry, it is still Enabled") does not appears also proves that btnPasteLast is disabled.  

    I thought that maybe somehow the form was just not getting a chance to reflect all changes and so added the Me.Update and, for good measure, SLeep.  Didn't help.

    Does anyone have any idea what might be happening?  I sure don't. 

    I would sure appreciate any thoughts anyone might have.

    Thanks,  Bob



    Friday, June 13, 2014 9:49 PM

Answers

  • "I thought that maybe somehow the form was just not getting a chance to reflect all changes and so added the Me.Update and, for good measure, SLeep.  Didn't help."

    What's for sure is that Sleep will never help in a WinForms application. If anything, it will make things worse.

    "Does anyone have any idea what might be happening?  I sure don't."

    I presume that you already made sure that you disable the correct button. I suppose the only remaining explanation is that you have some code which re-enable the button - perhaps a timer or some other kind of event does it.

    • Marked as answer by eBob.com Saturday, June 14, 2014 2:16 PM
    Saturday, June 14, 2014 7:32 AM
    Moderator

All replies

  • "I thought that maybe somehow the form was just not getting a chance to reflect all changes and so added the Me.Update and, for good measure, SLeep.  Didn't help."

    What's for sure is that Sleep will never help in a WinForms application. If anything, it will make things worse.

    "Does anyone have any idea what might be happening?  I sure don't."

    I presume that you already made sure that you disable the correct button. I suppose the only remaining explanation is that you have some code which re-enable the button - perhaps a timer or some other kind of event does it.

    • Marked as answer by eBob.com Saturday, June 14, 2014 2:16 PM
    Saturday, June 14, 2014 7:32 AM
    Moderator
  • Thanks very much for your reply Mike.  YES!  I did have other code which was re-enabling the button.  But it took your question to make me realize it.  (I really should not be writing code past my bedtime.)

    Thanks again,  Bob

    Saturday, June 14, 2014 2:16 PM