VS 2008 Have button enabled when coming from a certain form-VBForums
Results 1 to 10 of 10

Thread: Have button enabled when coming from a certain form

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2012
    Posts
    4

    Have button enabled when coming from a certain form

    Good day

    Quick question, I want to have a button on a form disabled when the user comes from one path, but enabled when they come from a different path.
    Example being the button (Button1) is on Form4, so when the user moves from Form3 to Form4, then Button1 is disabled. But if the user comes from Form6 to Form4 then Button1 is enabled.

    I have googled this and looked around this site to find anything close to this, but have had no luck. I have no clue on how the code would look.

    Thanks

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,241

    Re: Have button enabled when coming from a certain form

    Are we talking standard application or MDI?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    18

    Re: Have button enabled when coming from a certain form

    if any button on form4 causes you to navigate to another form then i would tell them to make button1 disabled. I would then have form6 (or other forms) make it enabled when you navigate back to form4.

    Is that any use to you or do you want example code?

  4. #4
    Loquacious User Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    24,587

    Re: Have button enabled when coming from a certain form

    Put a public sub on the form that has the button. The sub would enable the button (or you could have it take a Boolean argument and either enable or disable based on that argument). Then, call the method just before you show the form.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2012
    Posts
    4

    Re: Have button enabled when coming from a certain form

    Quote Originally Posted by sico View Post
    if any button on form4 causes you to navigate to another form then i would tell them to make button1 disabled. I would then have form6 (or other forms) make it enabled when you navigate back to form4.

    Is that any use to you or do you want example code?
    an example code would be benificial

  6. #6
    Hyperactive Member
    Join Date
    Aug 2011
    Posts
    272

    Re: Have button enabled when coming from a certain form

    On your Form3, any time you call Form4, try something like this:

    Code:
    Form4.Button1.Enabled = False
    Form4.Show

  7. #7
    Junior Member
    Join Date
    Sep 2012
    Posts
    18

    Re: Have button enabled when coming from a certain form

    Public Class Form4
    Private Sub ButtontoForm3_Click() Handles ButtontoForm3.Click
    Button1.Enabled = False
    Form3.show()
    End Sub
    End Class

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

    Public Class Form6
    Private Sub ButtontoForm4_Click() Handles ButtontoForm4.Click
    Form4.Button1.Enabled = True
    Form4.show()
    End Sub
    End Class

    There may be easier ways, depending on the number of Forms you want to Enable it and Disable it, but this is A method that should work.

  8. #8
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    88,972

    Re: Have button enabled when coming from a certain form

    Personally, I would add a constructor to Form4 with a Boolean parameter and make that the only constructor, so the only way to create an instance of Form4 is to invoke that and pass a Boolean. You then use that Boolean inside the constructor to enable or disable the Button, e.g.
    Code:
    Public Class Form4
    
        Public Sub New(enableButton As Boolean)
            InitializeComponent()
    
            Button1.Enabled = enableButton
        End Sub
    
        '...
    
    End Class
    You'd then display a Form4 instance like this:
    Code:
    Dim f4 As New Form4(True)
    
    f4.Show()
    That will display with the Button enabled or you can pass False to disable it.

    2007-2014

    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) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    New Member
    Join Date
    Dec 2012
    Posts
    4

    Re: Have button enabled when coming from a certain form

    Quote Originally Posted by sico View Post
    Public Class Form4
    Private Sub ButtontoForm3_Click() Handles ButtontoForm3.Click
    Button1.Enabled = False
    Form3.show()
    End Sub
    End Class

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

    Public Class Form6
    Private Sub ButtontoForm4_Click() Handles ButtontoForm4.Click
    Form4.Button1.Enabled = True
    Form4.show()
    End Sub
    End Class

    There may be easier ways, depending on the number of Forms you want to Enable it and Disable it, but this is A method that should work.
    I was nnot able to get it to work. I have it disabled, but when coming from form6 to form4 it wont enable

  10. #10

    Thread Starter
    New Member
    Join Date
    Dec 2012
    Posts
    4

    Re: Have button enabled when coming from a certain form

    Ignore what I just said, minor typo on my part. I was able to get it to work. Thanks for all the help, really appreciate it!

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.