473,548 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to draw square dot when fire mouse click on image in picturebox C#

19 New Member
HI,
i need help on how to draw a square dot when fire mouse click:
-onto image in picturebox

-the dot size is 10px X 10px

-and return the position of dots (x,y) values.

here i try some code but missing in somewhere, please help me,

thanks

Regards
Aznimah

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace RedDotAnnotate
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         Bitmap OriginalImage;
  20.         Point myPts = Point.Empty;
  21.  
  22.         private void button1_Click(object sender, EventArgs e)
  23.         {
  24.             //Open File Dialog to load image files
  25.             openFileDialog1.FileName = "";
  26.             openFileDialog1.Title = "Images";
  27.  
  28.             //Filter the filedialog, so that it will show only the mentioned format images
  29.             openFileDialog1.Filter = "PNG Image(*.png)|*.png|JPG Image(*.jpg)|*.jpg|BMP Image(*.bmp)|*.bmp";
  30.             openFileDialog1.ShowDialog();
  31.  
  32.             if (openFileDialog1.FileName.ToString() != "")
  33.             {
  34.                 pictureBox1.ImageLocation = openFileDialog1.FileName.ToString();
  35.                 OriginalImage = new Bitmap(openFileDialog1.FileName.ToString());
  36.             }
  37.  
  38.             // butSave.Enabled = true;
  39.         }
  40.  
  41.         private void pictureBox1_mouseDown(object sender, MouseEventArgs e)
  42.         {
  43.             Point myPts = new Point(e.X, e.Y);
  44.             Bitmap b = (Bitmap)pictureBox1.Image;
  45.             Graphics g = Graphics.FromImage(b);
  46.            // myPts.add(new Point(e.X, e.Y));
  47.             Invalidate();
  48.             pictureBox1.Image = b;
  49.  
  50.         }
  51.        // List<Point> myPts = new List<Point>();
  52.  
  53.         private void pictureBox1_Paint(object sender, PaintEventArgs e)
  54.         {
  55.  
  56.             Graphics g = e.Graphics;
  57.             foreach (Point p in myPts)
  58.             {
  59.                 g.DrawEllipse(new Pen(Color.Green), p.X, p.Y, 10, 10);
  60.  
  61.             }            
  62.  
  63.         } 
  64.  
  65.     }
  66.  
  67.   }
  68.  
Aug 17 '10 #1
1 4368
GaryTexmo
1,501 Recognized Expert Top Contributor
Can you please clarify?

You want to draw a square around where you click, and return the values of the pixels within that box?

Thanks!
Aug 18 '10 #2

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

Similar topics

5
3075
by: MikeLory | last post by:
Hi All. I was looking for this script for some time now But still didmf fined a salution. Pls help I need a script that simulates a left mouse click on specified area of the screen when the page is loaded. Any idea? Thank you
0
1212
by: Sakharam Phapale | last post by:
Hi All, How to insert the image into the richtextbox control and catch the mouse click event of that image. Thanks in Advance, Sakharam Phapale
24
11353
by: aam | last post by:
hi, im trying to figure out how i can program the mouse to automatically click on a button of a web page that i'm viewing.i do not have control over the page.i would also like to set up an adjustable timer with it where the mouse can be set to click every so many seconds (1-10).i'm having trouble figuring out how to do and code this.thanks for...
3
2879
by: chsadaki | last post by:
HI I am working on a project for the university, I need to know if there is a method in php that returns the x,y of the mouse click. cos I need it to allocate some positions on a map of my city. thanx in advance shameram sadaki
18
22062
by: eliss.carmine | last post by:
Is it possible to simulate a mouse click in the window I made (it's a Form), but not give it focus? I tried using WinAPI's mouseevent and SendMessage of WM_LBUTTONDOWN/WM_LBUTTONUP as suggested by the folks in #winapi on EFnet, but I think those require the window to have focus. Either that, or I'm doing something else wrong. The click...
3
1790
by: =?Utf-8?B?SmVycnk=?= | last post by:
I have the following code and it returns the x and y coordinates in the text box, but when I click the mouse on say 362,61 does not bring up form2.Any suggestions? Thanks, Jerry Private Sub PictureBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick Dim mouseX As Integer =...
1
4463
by: =?Utf-8?B?Umlz?= | last post by:
Hi, I have an image displayed in a PictureBox and the displayed image is resized and centred. When I click on the image, I can get the coordinates relative to the PictureBox but I would like the coordinates to be relative to the image. I've tried using PointToClient but this gives me wrong values (eg. negative x). Is there a PictureBox...
1
1292
by: Anuhas | last post by:
Dear experts, I need to change the background image of a windows form at an event of a mouse click. Please give me the relavent method and codes. Anuhas
0
1532
by: Frank Rizzo | last post by:
I have a form with a lot of controls on it. How can I detect when the mouse leaves the form? I've tried wiring up a MouseLeave event for every single control, but that does not work because those events fire all the time as the mouse passes over controls. I've tried wiring up form's MouseLeave event, but that does not work either because if...
0
7444
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...
0
7711
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. ...
0
6039
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...
1
5367
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...
0
5085
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...
0
3497
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...
0
3478
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1932
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
1
1054
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.