0
我是一名初學者程序員,我正在學習使用VB在大學(英國)編碼。使用鼠標位置旋轉圖像 - Visual Studio 2015
我有一個位圖在一個圖片框的中心繪製,這是一個箭頭朝右的圖像。要旋轉我正在使用;
RAD = Math.Atan2(MOUSE_Y - CENTRE_Y, MOUSE_X - CENTRE_X)
ANG = RAD * (180/Math.PI)
正如你可以看到我想要使用MousePosition.Y & X上使用鼠標的位置,以便朝着老鼠,但箭頭的角度箭頭指向是關閉的,因爲它是使用旋轉圖像X和Y的整個顯示器尺寸,但我希望它只使用表格尺寸(640 x 480)
這是Picturebox1_Paint子;
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
Dim MOUSE_X As Integer
Dim MOUSE_Y As Integer
Dim CENTRE_X As Integer
Dim CENTRE_Y As Integer
Dim BMP As Bitmap
Dim ANG As Integer = 0
Dim RAD As Double
Dim GFX As Graphics = e.Graphics
BMP = New Bitmap(My.Resources.ARROWE)
MOUSE_X = (MousePosition.X)
MOUSE_Y = (MousePosition.Y)
CENTRE_X = PictureBox1.Location.X + PictureBox1.Width/2
CENTRE_Y = PictureBox1.Location.Y + PictureBox1.Height/2
RAD = Math.Atan2(MOUSE_Y - CENTRE_Y, MOUSE_X - CENTRE_X)
ANG = RAD * (180/Math.PI)
GFX.TranslateTransform(PictureBox1.Height/2, PictureBox1.Width/2)
GFX.RotateTransform(ANG)
GFX.DrawImage(BMP, -30, -30, 60, 60)
GFX.ResetTransform()
End Sub
任何幫助,將不勝感激