矩阵变换对于整数鼠标事件来说太小的 2D 图形?

2D Graphics with matrix transformation too small for integer mouseevents?

我正在设计一个简单的应用程序,使用 DrawLine() 和 DrawEllipse() 函数将一些笛卡尔类型的图形显示到 PictureBox 控件中。为了使坐标系更 "real-world" 而不是图片框,我使用矩阵来翻转 Y 轴,缩小所有内容并重新定位它,以便 (0,0) 位于屏幕的中心并且 (+ 2,+2) 在右上角。一切都适用于图形绘制。但是,在尝试读取鼠标事件时,似乎 MouseEventArgs 变量(由大多数鼠标事件返回)returns 鼠标位置 X 和 Y 为整数。我正确地使用倒置矩阵来检索缩放值的坐标,但在我使用的比例下,这不能作为整数工作,因为我需要分数值(1.5、1.6 等)的屏幕位置。

有没有办法将鼠标值检索为浮点数或 double/decimal 值来提供我需要的 "resolution"?

一些代码碎片:

--全球

Private MyTransform As Matrix

--图片框内

Paint() event  
Dim G As Graphics = e.Graphics  
Dim mx As New Matrix(1, 0, 0, -1, 0, 0) 'Y-axis orientation flipped to match Cartesian plane  
mx.Translate(PictureBox.Width / 2, -PictureBox.Height / 2) 'Move 0,0 to lower left corner  
mx.Scale(100, 100)  
G.Transform = mx  
MyTransform = G.Transform  

'此时已执行所有绘图并且工作正常。

--MouseDown事件内

MyTransform.Invert()  
'Here is the issue--the Mouse points returned, being integers, cannot properly  
'show the mouse point if the transformation matrix has scaled up the drawing space at all.  
e.Location.x 'is an integer, so it cannot show .01 as the proper mouse location within the transformed viewspace.  
e.Location.y 'same issue.  
MyTransform.Invert()  

我一直在寻找基于笛卡尔坐标的图片框替代方案,但无济于事,而且图表组件无法工作,因为它们要求绘制的点包含在它们自己的专有 containers/sets 中。我正在用 GDI 类型的方法自己完成所有绘图。唯一的选择似乎是避免使用 vb 进行转换并自己完成所有 translation/untranslation,除非有人有替代方案或示例建议....?

Scale 存储为 属性。然后,当您更改比例时,您将一个函数应用于鼠标坐标差异。示例将使用 10/1 平面,因此 Scale 将是 10

Private Property Scale As Single 

函数:

Private Function CorrectForScale(coord As Integer) As Single
   Return (coord / Scale)
End Function

现在,如果鼠标位置之间的距离差 = 3,那么函数后的结果将是 0.3