我在用中间点击把我的表格挂起来。现在,我在中间单击以钩住我的表单,然后再次单击以触发我的方法在我的picturebox上绘制(它在我的表单上)。
我想中点击一次,并立即在我的图片框,而不是两次中点击。我用以下代码尝试了MouseHover和MouseEnter:
private void PbxDrawing_MouseEnter(object sender, EventArgs e)
{
bMoving = true;
Point pos = PbxDrawing.PointToClient(Cursor.Position);
x = pos.X;
y = pos.Y;
}鼠标移动:
private void PbxDrawing_MouseMove(object sender, MouseEventArgs e)
{
if(bMoving && x!=-2 && y != -2)
{
g.DrawLine(pen,new Point(x,y), e.Location);
x = e.X;
y = e.Y;
}
}它允许我知道光标的位置和绘制,但绘制我必须释放中间点击。
如果我的中间单击是在我的表单之外进行的,我如何从一个中间单击来绘制?
编辑:澄清问题
发布于 2022-05-16 12:49:15
只需检查一下中间按钮是否在MouseMove事件中:
private void PbxDrawing_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Middle)
{
x = e.X;
y = e.Y;
}
}
private void PbxDrawing_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Middle)
{
g.DrawLine(pen, new Point(x, y), e.Location);
x = e.X;
y = e.Y;
}
}不过,您对g的使用是一个危险信号。g是用PbxDrawing.CreateGraphics()创建的吗?如果是,则这是错误的,应该重构为使用来自PictureBox的PictureBox()事件的。
https://stackoverflow.com/questions/72258489
复制相似问题