469,627 Members | 1,092 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,627 developers. It's quick & easy.

handling mousedown for dynamic pictureboxes

Hi,

I'm using visual studio dotnet 2002 programming in vb

can anyone tell me how I can handle the mousedown event for pictureboxes I
create dynamically at runtime?
I've tried setting the mousedown to handle mybase.mousedown but it doesn't
detect the mousedown event until I move out of the pictureboxes I have
created (only works on the part of the form where I don't have any
pictureboxes). I also cannot set the mousedown event to handle my array of
pictureboxes as they are not a valid handle.

regards,

Scott M.

----
remove the "remove spam" and change (at) to @ to reply
----
Nov 19 '05 #1
7 7751
Hello,

"Scott Mackay" <sc******@nildram.co.uk> schrieb:
can anyone tell me how I can handle the mousedown
event for pictureboxes I create dynamically at runtime?


Have a look at the AddHandler and RemoveHandler keywords.

HTH,
Herfried K. Wagner
--
MVP VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 19 '05 #2
Hi, you can use AddHandler to add an event handler for an, erm, event :)

'///
AddHandler MyRuntimePictureBox.MouseDown, AddressOf MyMouseDownHandler
'///
Public Sub MyMouseDownHandler(ByVal sender As Object, ByVal e As
MouseEventArgs)
Nov 19 '05 #3
Hi, thanks for the reply - that worked a treat

regards,

Scott M.
"Scott Mackay" <sc******@nildram.co.uk> wrote in message
news:3f***********************@mercury.nildram.net ...
Hi,

I'm using visual studio dotnet 2002 programming in vb

can anyone tell me how I can handle the mousedown event for pictureboxes I
create dynamically at runtime?
I've tried setting the mousedown to handle mybase.mousedown but it doesn't
detect the mousedown event until I move out of the pictureboxes I have
created (only works on the part of the form where I don't have any
pictureboxes). I also cannot set the mousedown event to handle my array of pictureboxes as they are not a valid handle.

regards,

Scott M.

----
remove the "remove spam" and change (at) to @ to reply
----

Nov 19 '05 #4
Hi again,

okay follow up question:

now that I have handled the clicking of one of my array of pictureboxes, how
can I tell which picturebox within the array I have clicked on?

regards,

Scott M.

"Scott Mackay" <sc******@nildram.co.uk> wrote in message
news:3f***********************@mercury.nildram.net ...
Hi,

I'm using visual studio dotnet 2002 programming in vb

can anyone tell me how I can handle the mousedown event for pictureboxes I
create dynamically at runtime?
I've tried setting the mousedown to handle mybase.mousedown but it doesn't
detect the mousedown event until I move out of the pictureboxes I have
created (only works on the part of the form where I don't have any
pictureboxes). I also cannot set the mousedown event to handle my array of pictureboxes as they are not a valid handle.

regards,

Scott M.

----
remove the "remove spam" and change (at) to @ to reply
----

Nov 19 '05 #5
Hi Scott,

The sender argument of the event handler will be the PictureBox that was
clicked. It's defined as an Object, so cast it to a PictureBox and then loop
through your array until you find a match.

Regards,
Fergus.

=============================
Public Shared Moan
Sender - now what kind of name is that ?
I've never read Sender and thought "ah,
that must be the control that the event
occurred with/in/at/to."
End Moan
Nov 19 '05 #6
Hi, your attached method has a sender argument, which can be casted to the
PictureBox which was clicked:

'///
Dim pbClicked As PictureBox
If TypeOf sender Is PictureBox Then pbClicked = DirectCast(sender,
PictureBox)
'///

--
Happy to help,
-- Tom Spink
(th**********@ntlworld.com)

"Go down with your server"

http://dotnetx.betasafe.com >> On The Mend

Please respond to the newsgroup,
so all can benefit
"Scott Mackay" <sc******@nildram.co.uk> wrote in message
news:3f***********************@mercury.nildram.net ...
Hi again,

okay follow up question:

now that I have handled the clicking of one of my array of pictureboxes, how can I tell which picturebox within the array I have clicked on?

regards,

Scott M.

"Scott Mackay" <sc******@nildram.co.uk> wrote in message
news:3f***********************@mercury.nildram.net ...
Hi,

I'm using visual studio dotnet 2002 programming in vb

can anyone tell me how I can handle the mousedown event for pictureboxes I create dynamically at runtime?
I've tried setting the mousedown to handle mybase.mousedown but it doesn't detect the mousedown event until I move out of the pictureboxes I have
created (only works on the part of the form where I don't have any
pictureboxes). I also cannot set the mousedown event to handle my array

of
pictureboxes as they are not a valid handle.

regards,

Scott M.

----
remove the "remove spam" and change (at) to @ to reply
----


Nov 19 '05 #7
Hello,

"Scott Mackay" <sc******@nildram.co.uk> schrieb:
now that I have handled the clicking of one of my array of pictureboxes, how can I tell which picturebox within the array I have clicked on?


See:

Creating Control Arrays in Visual Basic .NET and Visual C# .NET
http://msdn.microsoft.com/library/?u...VisualCNET.asp

HTH,
Herfried K. Wagner
--
MVP VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by JJ | last post: by
1 post views Thread by Jon Cosby | last post: by
3 posts views Thread by TheLostLeaf | last post: by
8 posts views Thread by Louis | last post: by
7 posts views Thread by Markus Pitha | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.