473,763 Members | 7,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.mousedow n 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 8120
Hello,

"Scott Mackay" <sc******@nildr am.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 MyRuntimePictur eBox.MouseDown, AddressOf MyMouseDownHand ler
'///
Public Sub MyMouseDownHand ler(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******@nildr am.co.uk> wrote in message
news:3f******** *************** @mercury.nildra m.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.mousedow n 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******@nildr am.co.uk> wrote in message
news:3f******** *************** @mercury.nildra m.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.mousedow n 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(send er,
PictureBox)
'///

--
Happy to help,
-- Tom Spink
(th**********@n tlworld.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******@nildr am.co.uk> wrote in message
news:3f******** *************** @mercury.nildra m.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******@nildr am.co.uk> wrote in message
news:3f******** *************** @mercury.nildra m.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.mousedow n 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******@nildr am.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
16320
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
371
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 MouseUp handlers as below, but it never gets out of the while loop. this.PicBox.MouseDown += new MouseEventHandler(this.StartMapDrag); this.PicBox.MouseUp += new MouseEventHandler(this.EndMapDrag); private void StartMapDrag(object sender,...
2
2670
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 listbox. 1. Reorder items using drag and drop with the mouse. 2. Delete items eg by double-clicking or some other mouse-related action.
4
1422
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 and display in pictureboxes pcbCam1, pcbCam2, pcbCam4, pcbCam6, pcbCam7, and pcbCam8. So far the code works for one picture box not the others. Also when I reenter a different date the counter (+1) messes up....HELP
0
933
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 buttons that I put in pictureboxes on top of the main picturebox. In other words, if the color behind my button is 247,247,247 I would want my custom button (picturebox) to have the same background hue. Unfortunately, I've tried every way to...
3
1778
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 System.Windows.Forms.PictureBox(); this.pictureBox4 = new System.Windows.Forms.PictureBox(); this.pictureBox5 = new System.Windows.Forms.PictureBox(); To This:
8
1619
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, true); When I tried to debug it, it seems to react fine to a left mouse click, but it totally ignores the right mouse click.
7
1503
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 issues carefully? Thanks, Markus
2
1045
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 folder in the program then he needs to create pictureboxes to show a thumbnail of them so you can see wich photo it is. (like acdsee does...:) ) Does anybody have an idea? Thanks! Paul
0
9386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10144
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9822
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7366
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.