كود :
Imports System.Math
Public Class Form1
Const av As Byte = 10
Event GetPoint(ByVal x As Double, ByVal y As Double)
Dim Orgx As Integer = Me.Width / 2
Dim Orgy As Integer = Me.Height / 2
Private Sub Form1_GetPoint(ByVal x As Double, ByVal y As Double) Handles Me.GetPoint
Me.Text = "X:" & x & " Y:" & y
End Sub
Dim Xv As Double = 0
Property Xvalue() As Double
Get
Return Xv
End Get
Set(ByVal value As Double)
Xv = value
Invalidate()
End Set
End Property
Dim yv As Double = 0
Property Yvalue() As Double
Get
Return yv
End Get
Set(ByVal value As Double)
yv = value
Invalidate()
End Set
End Property
Dim bb As Boolean = False
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
bb = True
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
Dim xx As Double = e.X - CDbl(Orgx)
Dim yy As Double = CDbl(Orgy) - e.Y
RaiseEvent GetPoint(xx / 10, yy / 10)
If bb Then
Dim g As Graphics = CreateGraphics()
g.DrawEllipse(New Pen(Color.Black, 2), e.X, e.Y, 1, 1)
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
bb = False
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawLine(Pens.Black, 0, Orgy, Me.Width, Orgy)
e.Graphics.DrawLine(Pens.Black, Orgx, 0, Orgx, Me.Height)
For rx As Integer = Orgx To Me.Width Step 10
e.Graphics.DrawLine(Pens.Black, rx, Orgy - 2, rx, Orgy + 2)
Next
For lx As Integer = Orgx To 0 Step -10
e.Graphics.DrawLine(Pens.Black, lx, Orgy - 2, lx, Orgy + 2)
Next
For uy As Integer = Orgy To Me.Height Step 10
e.Graphics.DrawLine(Pens.Black, Orgx - 2, uy, Orgx + 2, uy)
Next
For uy As Integer = Orgy To 0 Step -10
e.Graphics.DrawLine(Pens.Black, Orgx - 2, uy, Orgx + 2, uy)
Next
If Xvalue <> 0 Then
If Yvalue <> 0 Then
Dim xx As Single = Xvalue + Orgx
Dim yy As Single = Yvalue - Orgy
e.Graphics.FillEllipse(Brushes.Black, xx, yy, 2, 2)
End If
End If
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
Orgx = Me.Width / 2
Orgy = Me.Height / 2
Invalidate()
End Sub
Dim b As Boolean = False
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Xvalue = 1
Yvalue = 1
Invalidate()
End Sub
End Class