4 Replies - 474 Views - Last Post: 09 October 2012 - 09:20 PM Rate Topic: -----

#1 mattcash83  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 23-June 12

Determining which control called a subclass

Posted 04 October 2012 - 06:31 PM

I want to use one timer to momentarily (and separately) change the background image of some buttons as they are pressed. What I need to know is how to determine which "button" called the timer, so that only that button image changes. I thought I could do some IF Then's, but I cannot figure out how to check for the control that started the timer. Here is what I tried (to no avail):

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        If sender Is StopButton Then
            StopButton.BackgroundImage = WindowsApplication1.My.Resources.Resources.StopButton2
            Timer2.Stop()
        End If
    End Sub



I take it sender is not the right choice.....

Thanks for any help on this!

Is This A Good Question/Topic? 0
  • +

Replies To: Determining which control called a subclass

#2 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Determining which control called a subclass

Posted 04 October 2012 - 08:02 PM

View Postmattcash83, on 04 October 2012 - 06:31 PM, said:

I want to use one timer to momentarily (and separately) change the background image of some buttons as they are pressed. What I need to know is how to determine which "button" called the timer, so that only that button image changes. I thought I could do some IF Then's, but I cannot figure out how to check for the control that started the timer.
Thanks for any help on this!


I think I'd probably use Timer.Tag to tell me what set the timer.

    Private Sub btnStop_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        ' do stuff
        Timer1.Tag = "btnStop"
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        Select Case Timer1.Tag.ToString
            Case "btnStop"
                'do stuff
            Case "btnGo"
                'do stuff
        End Select
    End Sub


Was This Post Helpful? 1
  • +
  • -

#3 mattcash83  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 23-June 12

Re: Determining which control called a subclass

Posted 09 October 2012 - 04:04 PM

Lar3ry,

Thank you for the suggestion of using .tag, I was unaware it existed! Thanks a lot!
Was This Post Helpful? 0
  • +
  • -

#4 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Determining which control called a subclass

Posted 09 October 2012 - 08:02 PM

View Postmattcash83, on 09 October 2012 - 04:04 PM, said:

Thank you for the suggestion of using .tag, I was unaware it existed! Thanks a lot!


Many controls have a .Tag property. I have developed the habit of looking for it when I need a variable that fits well with the purpose of the control. Glad it helped.
Was This Post Helpful? 0
  • +
  • -

#5 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1057
  • View blog
  • Posts: 4,097
  • Joined: 02-July 08

Re: Determining which control called a subclass

Posted 09 October 2012 - 09:20 PM

The sender object is the class raising the event.

Private Sub btnOne_click(sender As Object, e As EventArgs)
  'sender here is a Button wrapped up in an Object 
  'fully legal since it is derived from Object
End Sub


The sender object in your example was a Timer. Make sense?

This post has been edited by _HAWK_: 09 October 2012 - 09:20 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1