我正在努力实现在mouseClick位置中央画一个矩形。为此,我觉得我需要得到x和y坐标作为int。
(这是编辑的代码,e.X或e.Y是解决这个问题的方法)
let mouseClick (e: MouseEventArgs) =
let x = e.X
let y = e.Y
let coords = [|System.Drawing.Point((x-10),(y-10));
System.Drawing.Point((x-10),(y+10));
System.Drawing.Point((x+10),(y+10));
System.Drawing.Point((x+10),(y-10));
System.Drawing.Point((x-10),(y-10))|]
window.Paint.Add(fun e -> e.Graphics.DrawLines(pen, coords ))
window.MouseClick.Add mouseClick我尝试使用无法工作的e.Location属性,这在某种程度上是有意义的,因为当我打印它时,它会打印“x=(某些数字)y=(某些数字)”。
有人能帮我得到x和y坐标作为int吗?
发布于 2016-11-26 11:08:48
如注释中所述,要从MouseEventArgs获取鼠标位置,只需访问它的X或Y属性
,它只反映了Location.X和Location.Y属性,这些属性也可在e上使用。
关于您的编辑和您的附加注释,我认为您通过每次单击添加一个新的Paint处理程序做了一些错误,您只需要绘制(不过,在某个时候可能仍然需要一个Refresh )。
let mouseClick (e: MouseEventArgs) =
let x = e.X
let y = e.Y
let coords = [| System.Drawing.Point(x - 10, y - 10)
System.Drawing.Point(x - 10, y + 10)
System.Drawing.Point(x + 10, y + 10)
System.Drawing.Point(x + 10, y - 10)
System.Drawing.Point(x - 10, y - 10) |]
// maybe use instead of let ?
let g = window.CreateGraphics()
g.Graphics.DrawLines(pen, coords)
window.MouseClick.Add mouseClickhttps://stackoverflow.com/questions/40816788
复制相似问题