473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

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 8088
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JJ | last post by:
Hi All, I need to create a MouseDown event for a picture box . Am I doing the following right? pictureBox.MouseDown += new System.WinForms.MouseEventHandler(pictureBox_MouseDown) Then
1
by: Jon Cosby | last post by:
I need an event handler for dragging the cursor on a PictureBox. The existing events only include handlers for dragging and dropping objects over the controls. I'm trying to use the MouseDown and...
2
by: John Dann | last post by:
This question has arisen from an earlier thread but is really a separate issue: I have a VB.Net listbox control on a form. I want to be able to do 2 things with items displayed within the one...
4
by: KitKat | last post by:
Problem trying to figure this out, using a combo box selection I need to go to each folder, Cam 1, Cam 2, Cam 4, Cam 6, Cam 7,and Cam 8 and display each picture (from selection) from each folder...
0
by: Blarneystone | last post by:
I am pulling my hair out over this one. I've got a picturebox with just a simple gradient as the background for my interface. It is in 16bit RGB color. I've created some pictures I'll use as...
3
by: TheLostLeaf | last post by:
How do I change this : this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.pictureBox2 = new System.Windows.Forms.PictureBox(); this.pictureBox3 = new...
8
by: Louis | last post by:
I was trying to display a custom context menu in javascript. I wanted to capture a right mouse click. I added an eventListener to a "div" like this.. element,addEventListener ("click", myfunc,...
7
by: Markus Pitha | last post by:
Hello, I still have massive problems with handling with pointers when I use them through methods or much more complicated constructs. Do you have any good and helpful links which describe these...
2
by: djpaul | last post by:
Heey! For my program i need to create pictureboxes on the fly. After adding pictures to the database with a surten folder you can eddit the pictures or the text that's with it. But when i select a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.