Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   VB Help (http://www.chiefdelphi.com/forums/showthread.php?t=105251)

BlueNova 31-03-2012 13:58

VB Help
 
Crazy Original Idea here (ok, not very crazy... or original... but still useful)

A spot to put any questions/advice for programming in VB

I'll Start.

I currently have a program where I create labels in code, and then using the "addhandler" function, set it so that when you click on those labels, they trigger the "boardclick" function. My question is: how do I know which label I clicked on (I have 100 different labels)?
I have a working solution of getting the mouse position when you click on them, and then figuring it out based off of that, but I'm looking for something more elegant.

My code looks like this:

For X = 0 To 9
For Y = 0 To 9
GameBoard(X, Y) = New Label
'Go through and set properties such as size, color, position, etc.
pnlBoard.Controls.Add(GameBoard(X, Y))
AddHandler GameBoard(X, Y).Click, AddressOf BoardClick
Next
Next

Private Sub BoardClick()
'Insert Code Here
'As you can see, I have 100 labels that could possibly trigger this event, I want to know which one it was, any suggestions?
End Sub

atsanders 31-03-2012 23:48

Re: VB Help
 
Private Sub BoardClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim labelClicked as String = sender.Name
End Sub

BlueNova 01-04-2012 12:43

Re: VB Help
 
Works Great, thanks


All times are GMT -5. The time now is 00:44.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi