Results 1 to 8 of 8

Thread: [RESOLVED] [2005] Button Toggles after performing action

  1. #1

    Thread Starter
    Lively Member Bandet Ace's Avatar
    Join Date
    Jun 2008
    Posts
    73

    Resolved [RESOLVED] [2005] Button Toggles after performing action

    The current program i am working has a rather large GUI. I'm trying to tone it down by making a button preform the opposite action after it has been clicked.

    In my case i want the button to
    Code:
    tabcontrol1.sendtoback()
    and after being clicked and sending it to back change to
    Code:
    tabcontrol1.bringtofront()
    And so forth every time the button is clicked it will change to the opposite reaction.

    Has anyone done this before?

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [2005] Button Toggles after performing action

    Hey,

    You could create a variable at a top level scope, and you the click of your button:

    Code:
    If myVariable = False Then
        tabcontrol1.sendtoback()
        myVariable = True
    Else
        tabcontrol1.bringtofront()
        myVariable = False
    End If
    Hope that helps!!

    Gary

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: [2005] Button Toggles after performing action

    i'd use a static variable within the button_click event

    vb Code:
    1. static myVariable as boolean = False
    2. If myVariable = False Then
    3.     tabcontrol1.sendtoback()
    4.     myVariable = True
    5. Else
    6.     tabcontrol1.bringtofront()
    7.     myVariable = False
    8. End If

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [2005] Button Toggles after performing action

    What do BringToFront and SendToBack do? They adjust the z-index of the control. You simply need to check whether the z-index of the TabControl is zero or not. If it is then call SendToBack. If it's not then call BringToFront. The z-index of a control is its index in its container's Controls collection:
    vb.net Code:
    1. If Me.Controls.IndexOf(Me.TabControl1) = 0 Then
    2.     Me.TabControl1.SendToBack()
    3. Else
    4.     Me.TabControl1.BringToFront()
    5. End If
    That's untested but I can't see why it wouldn't work.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Lively Member
    Join Date
    Jan 2007
    Posts
    96

    Re: [RESOLVED] [2005] Button Toggles after performing action

    nvm... already resolved.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [2005] Button Toggles after performing action

    Quote Originally Posted by youthbytes
    nvm... already resolved.
    I realised that from the "[RESOLVED]" in the thread title but I was trying to provide some useful information to improve your understanding of what was happening.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] [2005] Button Toggles after performing action

    Hey,

    I don't think that post was aimed at you jm, the way I read that was that youthbytes was going to suggest something, and then decided not to as he/she realized that the thread was already resolved. I could be wrong, but I don't think anything was meant by it

    Gary

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [2005] Button Toggles after performing action

    Quote Originally Posted by gep13
    Hey,

    I don't think that post was aimed at you jm, the way I read that was that youthbytes was going to suggest something, and then decided not to as he/she realized that the thread was already resolved. I could be wrong, but I don't think anything was meant by it

    Gary
    Ah, it appears you're correct. I assumed it was the OP posting that. Should look a bit closer, shouldn't I?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width