-1
我正在嘗試使用圖片框並挑選出2點(照片中的眼睛)。我會用g.DrawString
挑出兩點,在這裏我將畫出2個不同的'x'。現在的問題是我卡住了,如果用戶把'x'放在錯誤的位置上,我想調整它。是否有任何代碼可以使g.DrawString
'x'能夠移動?如何讓C#中的g.drawstring在放入圖片框後進行調整
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Camera
{
public partial class CamDisplay : Form
{
public CamDisplay()
{
InitializeComponent();
this.pictureBox1.ImageLocation = @"C:\center90\center90(1).jpg";
}
bool MousedClicked = true;
bool MouseClicked2 = true;
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
base.OnMouseClick(e);
if (MousedClicked == true)
{
txtXaxis.Text = e.X.ToString();
txtYaxis.Text = e.Y.ToString();
MousedClicked = false;
using (Graphics g = Graphics.FromHwnd(pictureBox1.Handle))
{
using (Font myFont = new Font("Calibri", 8))
{
g.DrawString("X", myFont, Brushes.Red, new PointF(e.X, e.Y));
}
}
}
else if (MouseClicked2 == true)
{
txtRXaxis.Text = e.X.ToString();
txtRYaxis.Text = e.Y.ToString();
MouseClicked2 = false;
using (Graphics g = Graphics.FromHwnd(pictureBox1.Handle))
{
using (Font myFont = new Font("Calibri", 8))
{
g.DrawString("X", myFont, Brushes.Red, new PointF(e.X, e.Y));
}
}
}
else
{
MousedClicked = false;
MouseClicked2 = false;
}
}
private void CamDisplay_MouseEnter(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
pictureBox1.Cursor = Cursors.Hand;
}
}
}
我在我的代碼中添加是否可以給我一些建議,我應該做出改變? – user3766178
我很抱歉拖延很久,我一直很忙。快速瀏覽一下你的代碼,看起來你是直接在鼠標點擊事件上繪製窗口。這將是對上述建議(2)的變化。刷新窗口/控件實際上應該「擦除」兩個標記。嘗試調用pictureBox1.Refresh()。 –