Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to get information from the object event

Status
Not open for further replies.

solo1234

Programmer
Jun 25, 2007
39
NL
Hello vb dotnet users,

Via a class we can create pictureboxes and an event. Interesting is to know in the event what is the name or position of the object what caused the event.

Used code:

Public Class PlaatsPictureBox
Private Shared ipb_count As Integer = 0

Public Shared Sub pb(ByVal frm As Form)
Dim npb As New PictureBox

With npb
ipb_count += 1
.Name = "picturebox_" & Str(ipb_count)
.Image = Drawing.Image.FromFile("D:\flow\pictures\join.jpg")
.Size = New Size(52, 52)
.Location = frm.PointToClient(System.Windows.Forms.Form.MousePosition)
AddHandler .MouseDown, AddressOf evt_pb_click
frm.Controls.Add(npb)
.BringToFront()
End With
End Sub
End Class

Module Module1
Public Sub evt_pb_click(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
MsgBox(e.Button) 'gives no information
MsgBox(e.Clicks) 'gives no information
MsgBox(e.Delta) 'gives no information
MsgBox(e.X) 'gives no information
MsgBox(sender.GetType.????????????????????????????) 'gives no information
End Sub
End Module

 
simple as you know: sender.name / sender.location
 

:) nice work solo1234. But do not ever use objects of type System.Object without casting to proper type. If you follow this tip, there are far less chances that you will get unexpected program behaviours. Invalid casting or no casting raises nasty problems.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top