|
-
July 20th, 2009, 12:44 AM
#1
how to mark a cross on the picture in the picture box using c#
i wanted to mark a cross on the image in the picture box once i click the mouse there will be a marking like cross or dot , as i wanted to track back the time and signal at that point , i do not want to just draw . ty
-
July 20th, 2009, 01:09 AM
#2
Re: how to mark a cross on the picture in the picture box using c#
You can handle the PictureBox's MouseDown and/or MouseUp events. The MouseEventArgs parameter holds the information you need.
Not sure what you mean by time and signal? DateTime.Now ?
PictureBox.Invalidate() will cause it to be redrawn. Do all of your drawing in the PictureBox's Paint handler.
Last edited by rliq; July 20th, 2009 at 01:12 AM.
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
-
July 20th, 2009, 01:20 AM
#3
Re: how to mark a cross on the picture in the picture box using c#
This draw a circle, but you get the idea....
Code:
public partial class Form1 : Form
{
List<Point> _points = new List<Point>();
public Form1()
{
InitializeComponent();
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
PictureBox pb = sender as PictureBox;
_points.Add(e.Location);
pb.Invalidate(); // can be optimised by passing a Rectangle the same size as that used in the Paint handler
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
foreach (Point p in _points)
{
g.DrawEllipse(Pens.Black, new Rectangle(p.X - 5, p.Y - 5, 10, 10));
}
}
}
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
-
July 20th, 2009, 01:26 AM
#4
Re: how to mark a cross on the picture in the picture box using c#
For a cross (as in a plus sign) replace the Paint handler with this:
Code:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
foreach (Point p in _points)
{
Point pt1 = new Point(p.X, p.Y - 10);
Point pt2 = new Point(p.X, p.Y + 10);
Point pt3 = new Point(p.X - 10, p.Y);
Point pt4 = new Point(p.X + 10, p.Y);
g.DrawLine(Pens.Black, pt1, pt2);
g.DrawLine(Pens.Black, pt3, pt4);
}
}
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
-
July 20th, 2009, 01:45 AM
#5
Re: how to mark a cross on the picture in the picture box using c#
You can add a Label control to display the time of the click as follows:
Code:
List<Point> _points = new List<Point>();
public Form1()
{
InitializeComponent();
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
PictureBox pb = sender as PictureBox;
_points.Add(e.Location);
pb.Invalidate();
Label lbl = new Label();
pb.Controls.Add(lbl);
lbl.Location = new Point(e.Location.X + 4, e.Location.Y + 4);
lbl.Text = DateTime.Now.ToLongTimeString();
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Point ptCurrent = new Point(0,0);
foreach (Point p in _points)
{
Point pt1 = new Point(p.X, p.Y - 10);
Point pt2 = new Point(p.X, p.Y + 10);
Point pt3 = new Point(p.X - 10, p.Y);
Point pt4 = new Point(p.X + 10, p.Y);
g.DrawLine(Pens.Black, pt1, pt2);
g.DrawLine(Pens.Black, pt3, pt4);
}
}
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|