如何用鼠标点击在picturebox的图像上做标记
鼠标点击图像,在点击处画一个圆。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace PictureDemo
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void pictureBox1_Click(object sender, EventArgs e){//得到鼠标相对于pictureBox左上角的位置Point p1=pictureBox1.PointToClient(Control.MousePosition);Image imageBmp = pictureBox1.Image;using (Graphics g = Graphics.FromImage(imageBmp)){g.SmoothingMode = SmoothingMode.AntiAlias; //抗锯齿g.PixelOffsetMode = PixelOffsetMode.HighQuality; //高质量g.InterpolationMode = InterpolationMode.High; //差值算法Color penColor = Color.Green;Pen pens = new Pen(penColor, 1); //定义画笔(线条)Brush brushs = new SolidBrush(penColor); //定义画刷(填充)g.DrawEllipse(pens, p1.X, p1.Y, 50, 50);//画圆弧线条g.FillEllipse(brushs, p1.X, p1.Y, 50, 50);//填充圆弧}pictureBox1.Image = imageBmp;}}
}