我試圖重新創建一個很久以前我嘗試過的小東西。這實際上只是一個簡單的繪畫程序。該代碼基本上是:DrawLine精度?
Public Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
X = Control.MousePosition.X
Y = Control.MousePosition.Y
Mdown = True
End Sub
Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
Dim g As Graphics = Me.CreateGraphics
Dim NX As Integer = Control.MousePosition.X
Dim NY As Integer = Control.MousePosition.Y
If Mdown = True Then
g.DrawLine(System.Drawing.Pens.Red, X, Y, NX, NY)
X = NX
Y = NY
End If
End Sub
Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
Mdown = False
End Sub
它工作正常,當鼠標移動時,該線從主點繪製到下一個點。但是,劃線的準確性值得懷疑。在我的第二臺顯示器(1280x720下運行)上繪製常規窗口大小(586,634)時,該線非常緊密地跟隨着鼠標尖(但不是確切的)。但是當窗口在我的主屏幕(1920x1080)上時,該線路是關閉的。這是否有一個特定的原因,因爲我認爲調用Control.MousePosition.X/Y獲得鼠標相對於窗口大小而不是屏幕大小的位置? (或別的東西)
我通常能夠自己弄清楚這些事情,但這只是一般的錯誤。有任何想法嗎?
哇,我真沒想到一個快速的答覆,並添加了很多細節,您的解決方案也確實解決了問題。謝謝! – EpicMinecartz