鼠标单击的点显示为*并与线交会处,它将给出消息. [英] mouse click point show as * and meet line then it will give messege.
本文介绍了鼠标单击的点显示为*并与线交会处,它将给出消息.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友,
我有此代码用于画线到图片框,现在我想当用户单击图片框,然后将微粒点显示为星点(例如*,@ ,.)作为点显示.
2.并且我希望每当它越界时它就会发出警报,我正在尝试bt无法正常工作.
dear friends ,
i have this code for drawline over to picturebox and now i want when user click the picturebox then particuler point show as a starpoint(like *,@,.) show as a point.
2. And i want whenever it cross the line then it will give the alert , i am trying bt not work properly.
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
pointArray[iNumberofClicks].X = e.X;
pointArray[iNumberofClicks].Y = e.Y;
Pen PenSpikes = new Pen(Color.Green);
SolidBrush solidBrush = new SolidBrush(Color.Blue);
if(iNumberofClicks==0)
{
a = e.X;
b = e.Y;
}
iNumberofClicks++;
if (iNumberofClicks > 1)
{
Point[] CurrentpointArray = new Point[iNumberofClicks];
for (int aa = 0; aa < iNumberofClicks; aa++)
{
CurrentpointArray[aa].X = pointArray[aa].X;
CurrentpointArray[aa].Y = pointArray[aa].Y;
}
Graphics offScreenDC = Graphics.FromImage(pictureBox1.Image);
offScreenDC.DrawLines(PenSpikes, CurrentpointArray);
offScreenDC.Dispose();
pictureBox1.Refresh();
}
}
for (int j = 1; j < CurrentpointArray.Length;j++ )
{
if ((Convert.ToInt16(CurrentpointArray[j].X) == a && Convert.ToInt16(CurrentpointArray[j].Y) == b) )
{
MessageBox.Show("alert");
break;
}
}
推荐答案
您应该从不使用PictureBox
开始解决此问题.它仅在最简单的情况下才有用,当您尝试进行更高级的操作时会变得很麻烦.
我在过去的答案中对此进行了解释:
如何从旧图纸中清除面板 [ ^ ],
在C#中绘制矩形 [在图片框内添加图片 [在mdi子表单之间画线 [在面板上捕获图形 [ Paint是一种哪种好玩的方法? (DataGridViewImageCell.Paint(...)) [
You should start solving this problem from not usingPictureBox
. It is useful only in some simplest cases and becomes a hassle when you try to do something more advanced.
I explain it in my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^].
Some more detailed explanations on what to do instead in my past answers:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^].
—SA
这篇关于鼠标单击的点显示为*并与线交会处,它将给出消息.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文