C#窗体程序如何输入坐标在图片上画点?

2024-12-15 16:53:28
推荐回答(2个)
回答1:

Point m_Pnt; public Form1() { InitializeComponent(); m_Pnt = new Point( -1, -1 ); pictureBox1.MouseClick += new MouseEventHandler(pictureBox1_MouseClick); pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint); } void pictureBox1_MouseClick(object sender, MouseEventArgs e) { // 这里模仿文本框修改坐标点,同时刷新下picturebox,鼠标点哪里,哪里就会画一个红点 m_Pnt = e.Location; pictureBox1.Invalidate(); } private void pictureBox1_Paint(object sender, PaintEventArgs e) { e.Graphics.FillEllipse( Brushes.Red, m_Pnt.X - 2, m_Pnt.Y - 2, 5, 5 ); }

回答2:

用gdi+画图即可,我给你写了个例子,鼠标点击picturebox,在点击出画点,用文本框输入的话类似的。