Consulting

Results 1 to 7 of 7

Thread: Change button focus

  1. #1
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location

    Change button focus

    I've got three buttons, each button when focus= true shows a different image. What I want to do is when you click button2 then that image appears and I want the image for button 1 to be set to false. The same with the third button. Essentially only show one image at a time depending on what button is selected. Any ideas?
    Peace of mind is found in some of the strangest places.

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    can we see the workbook or at least the code?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Steve what I am working on is not Excel. Just VB. Heres the code if anyone is interested.

    Private Sub btnAirplane_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAirplane.Click
            If btnAirplane.Focus = True Then
                PBAirplane.Visible = True
            End If
        End Sub
    Two other buttons are similar.
    Peace of mind is found in some of the strangest places.

  4. #4
    VBAX Regular
    Joined
    Nov 2008
    Posts
    44
    Location
    I'm not sure I understand correctly, but in your example code, wouldn't "If btnAirplane.Focus = True Then" always evaluate to True? btnAirplane was clicked, and therefore it has the focus.

    Do you want different things to happen when the user does rollovers on the buttons vs. when they click the buttons?

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Would something like the following work?
    [VBA]
    Private Sub btnAirplane_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAirplane.Click
    If btnAirplane.Focus = True Then
    PBAirplane.Visible = True
    image1.visible = False
    image2.visible = False
    End If
    End Sub
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    I came up with that Steve while waiting. That works ut was hoping for somethig w/o so many If statements. Select Case maybe? Also to disable all image when the form loads would you put first thing in the class something like

    private sub disableall()
    pb1.visible = false
    pb2.visible = false
    pb3.visible = false
    end sub
    Peace of mind is found in some of the strangest places.

  7. #7
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location

    Make button invisible using WS change event

    Cant seem to find this in the forum. If you have a button you created on your worksheet from the forms toolbar, what is the syntax to make it visible/not visible?
    Peace of mind is found in some of the strangest places.

Posting Permissions

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