473,372 Members | 1,153 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,372 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 8084
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.