0

Ok, I have one sub and I have it handleing different events of different objects. So my problem is I want to determine which event was triggered from which object. Can anyone help me out?

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Teme64
0

I have one sub and I have it handleing different events of different objects. So my problem is I want to determine which event was triggered from which object.

Could you please post your code.

0

here is my subroutine:

Private Sub PictureBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox81.DragDrop, PictureBox82.DragDrop, PictureBox83.DragDrop, PictureBox84.DragDrop, PictureBox85.DragDrop, PictureBox86.DragDrop, PictureBox87.DragDrop
        'this is where my problem is, i want to know which object's event was triggered so i can change the image of it.
        {I dont know which picturebox}.Image = e.Data.GetData(DataFormats.Bitmap)
    End Sub
0

Ok, here's how I tested

Private Sub PictureBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.Click, PictureBox2.Click
  '
  If sender.Equals(PictureBox1) Then
    MessageBox.Show("I'm PictureBox1", "Who Am I", MessageBoxButtons.OK, MessageBoxIcon.Information)
  End If
  If sender.Equals(PictureBox2) Then
    MessageBox.Show("I'm PictureBox2", "Who Am I", MessageBoxButtons.OK, MessageBoxIcon.Information)
  End If

End Sub

And your code should go like this

Private Sub PictureBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop, PictureBox2.DragDrop
  'this is where my problem is, i want to know which object's event was triggered so i can change the image of it.
  '{I dont know which picturebox}.Image = e.Data.GetData(DataFormats.Bitmap)
  If sender.Equals(PictureBox1) Then
    PictureBox1.Image = CType(e.Data.GetData(DataFormats.Bitmap), Image)
  End If
  If sender.Equals(PictureBox2) Then
    PictureBox2.Image = CType(e.Data.GetData(DataFormats.Bitmap), Image)
  End If

End Sub

HTH

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.