473,770 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get location of a picturebox by clicking on it in C#?

3 New Member
Hi, i have a problem about picturebox control. if you may help me, i will be so happy. i have a picturebox named pic_map, and i added a button named customer_button , my wish is to add a new small picturebox on the map_picture and the new added picturebox should have click event to get the location of it when it is clicked.

i have written some code in C# but when clicking the small picturebox it just gets the location of the last added one, not the one that i clicked on .

here is my code:

pic_map: main picturebox

i global int, initial value=0
Expand|Select|Wrap|Line Numbers
  1. private void pic_map_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  2. {
  3.        x=e.X;
  4.        y=e.Y;
  5.       if((e.Button==MouseButtons.Left)&&(tag==1))
  6.      {
  7.            i=i+1;
  8. musteri=new Bitmap("f:musteri_button.jpg");
  9. //                    node[j]=new PictureBox();
  10. //                    node[j].Image=musteri;
  11. }
Nov 16 '07 #1
4 3819
munibe
3 New Member
Hi, i have a problem about picturebox control. if you may help me, i will be so happy. i have a picturebox named pic_map, and i added a button named btn_customer to my form, my wish is to add new small picturebox to the coordinates that the user click on the pic_map and the new added picturebox should have click event to get the location of it when it is clicked and also be a member of the picturebox array.

after clicking the btn_customer, the coordinate thet user click on the pic_map there should be added a new picturebox with a tag number increasing 1 every time.

i have written some code in C# but when clicking one of the small picturebox it just gets the location of the last added one, not the one that i clicked on .

here is my code:

Expand|Select|Wrap|Line Numbers
  1. pic_map: main picturebox
  2.  
  3. i global int, initial value=0
  4.  
  5. musteri=new Bitmap("f:musteri_button.jpg");
  6. PictureBox [] node; //global
  7.  
  8. private void pic_map_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  9. {
  10.        x=e.X;
  11.        y=e.Y;
  12. node=new PictureBox[50];
  13.       if((e.Button==MouseButtons.Left)&&(tag==1))
  14.      {
  15.          i=i+1;
  16.         node[j]=new PictureBox();
  17.         node[j].Image=musteri;
  18.        node[i].Size=new System.Drawing.Size(36,26);
  19.        node[i].Location=new System.Drawing.Point(x,y);
  20.        node[i].Visible=true;
  21.        node[i].Name="node"+i;
  22.        node[i].Click += new System.EventHandler(this.node_Click);
  23.        node[i].Tag=i;
  24.        this.pic_map.Controls.Add(node[i]);
  25. private void btn_customer_Click(object sender, System.EventArgs e)
  26. {
  27.     tag=1;
  28. }
  29.  
  30. private void node_Click(object sender, EventArgs e)
  31. {
  32. int a,b;   
  33.    a=node[Convert.ToUInt32(((PictureBox)sender).Tag)].Location.X;
  34.    b=node[Convert.ToUInt32(((PictureBox)sender).Tag)].Location.Y;
  35. }
Please help me, thanks for your consider....
Nov 16 '07 #2
kenobewan
4,871 Recognized Expert Specialist
An if statement runs only once and you want to run a loop. HTH.
Nov 16 '07 #3
Plater
7,872 Recognized Expert Expert
Couldn't u assign a mouse click event to the picturebox itself?
Nov 16 '07 #4
munibe
3 New Member
An if statement runs only once and you want to run a loop. HTH.
Thanks, i have tried to use a loop, but could'nt find a way to get the clicked location while in the loop, if i define the x, y coordinate by manuel it works, but it does'nt allow getting the coordinates from picturebox while looping, or i could'nt find a way...

if you have an idea please confirm, thanks again
Nov 16 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1954
by: Tim Bücker | last post by:
Hello. I want to render in a picturebox (pbD3DSurface) using DirectDraw. This is working more or less but the coordinates are always screen oriented and not pictureBox oriented. x = 10; //+this.Location.X+this.pbD3DSurface.Location.X; y = 10; //+this.pbD3DSurface.Location.Y+this.Location.Y; back.DrawCircle(x, y, 5); //back = surface
0
3884
by: akh | last post by:
I want to use de Drag and Drop ´s event to move a picture box from a form and within a Picture Box. But I have behaviour if the MyPBox As PictureBox as the Globale varible or not Thanks for your help, Here is the code.
5
11121
by: Christopher Kurtis Koeber | last post by:
Dear All, This may sound like an elementary question but how do you implement scrollbars for the Picturebox control. Do I have to create my own code to do this or is there some property that I can set? Thank you very much for your time and consideration in this matter! Christopher Koeber
2
10341
by: kalp suth via DotNetMonster.com | last post by:
I want to create arrows using lines on a picture in the picture box. On clicking the button "btnShowAll", the image is loaded and the lines drawn. "RGSShowAll()" calls "DrawObjs()" which does the actual drawing work. But after displaying all the arrows in a flick, the arrows disappers. I have debugged and came to know that the "Paint" event of the picturebox is refreshing the image, so the work done on the CreateGraphics created object is...
3
63439
by: Tom | last post by:
I have a picturebox on my VB.NET form. The picturebox size mode is set to stretched. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and display (in the status bar) the image coordinates of the mouse location. However, if I use the picturebox's MouseMove event, I am getting the coordinates of the mouse over the PICTUREBOX, not the actual image underneath that (which is stretched)....
5
4563
by: toby | last post by:
Hi there, Is it possible to create an array of picturebox controls during run-time. I wish to create a new image/picturebox everytime a user clicks the button on a form, and they need to be objects so that the user can move/drag them around. The only examples I can find dont work as I am using VB Express (2005?)
1
18956
by: Steven Garrad | last post by:
Hi All, I have a pictureBox control inside of a panel control. The pictureBox is larger than the panel control and I have the panel control set true for AutoScroll so the panel displays scrolling bars. I would like the user to be able to click and drag the image and for it to move around within the panel control. How would I do this?
4
3714
by: Jim McGivney | last post by:
In C# on Form1 I genetate an array of PictureBoxes and populate each with an image as seen in the code below. Later on I want to access a specific PictureBox to change its image, but I keep getting the error "The name 'PictureBox1' does not exist in the current context" The code I use to try to access the PictureBox is "PictureBox1.Image = HoldBitMap; " where kount is an integer. I know the answer is probably in using the Controls...
5
5380
by: AWW | last post by:
XP VB 2005 running an example from help that creates a picturebox in code - the picturebox is not created. If I comment out the "Dim Box as New PictureBox" and create it in Design mode - the example works. I have tried Show, Enabled, Visible, and even BackColor. Why does a help example not work? and why does Design creation work? Thanks - I hope.
0
9453
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
10254
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
10099
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8929
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7451
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
6710
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
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.