472,796 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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

3
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 3725
munibe
3
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 Expert 4TB
An if statement runs only once and you want to run a loop. HTH.
Nov 16 '07 #3
Plater
7,872 Expert 4TB
Couldn't u assign a mouse click event to the picturebox itself?
Nov 16 '07 #4
munibe
3
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
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;...
0
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...
5
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...
2
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...
3
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...
5
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...
1
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...
4
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...
5
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...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.