Public Class Form1 Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click '▼マウスの座標を取得して学校関数でYだけ反転 円を書く Dim sp As System.Drawing.Point = System.Windows.Forms.Cursor.Position Dim cp As System.Drawing.Point = Me.PointToClient(sp) Dim schoolP As System.Drawing.Point = Me.PointToSchool(cp) Dim x As Integer = schoolP.X Dim y As Integer = schoolP.Y Dim newX As Integer = RoundMultiple(x, 60 / 100 * TrackBar1.Value) Dim newY As Integer = RoundMultiple(y, 40 / 100 * TrackBar1.Value) 'MsgBox(newX & "," & newY & " の位置にマウスカーソルを移動します。") Dim g As Graphics = PictureBox1.CreateGraphics g.TranslateTransform(0, Me.ClientSize.Height) g.ScaleTransform(1, -1) g.DrawEllipse(Pens.Blue, newX - 15, newY - 15, 30, 30) g.Dispose() End Sub '----------------------------------------------------- '▼学校関数で反転させる Private Function PointToSchool(p As Point) As Point Dim x As Integer = p.X Dim y As Integer = Me.ClientSize.Height - p.Y Return New Point(x, y) End Function '----------------------------------------------------- '▼クリックした座標は指定した近い倍数になる Private Function RoundMultiple(value As Integer, factor As Integer) As Integer Dim rate As Double = value / factor 'MsgBox(factor) Dim value以下で最も大きい倍数 As Integer = CInt(Math.Floor(rate) * factor) Dim value以上で最も小さい倍数 As Integer = CInt(Math.Ceiling(rate) * factor) Dim 差1 As Integer = value - value以下で最も大きい倍数 Dim 差2 As Integer = value以上で最も小さい倍数 - value If 差1 < 差2 Then Return value以下で最も大きい倍数 Else Return value以上で最も小さい倍数 End If End Function End Class