I am working on a basic game to try and improve my visual basic skills. I have asked a previous question regarding this, however I am really stuck and don't know what I'm doing.
I originally thought the Visual Basic Powerpack shapes would be best, however I have now been informed that picture box is best so I have changed this in the form, however not in the code.
I would like a picture box to be rotated 90 degrees around its centre when it has been clicked on and the left or right arrow keys have been pressed (it doesn't really matter which button is pressed)
There will eventually be 60 line shapes, and I don't know how to adapt my existing code, I would really appreciate some help - I have tried to code this myself however I don't understand what I'm doing now.
Here is my code on the form with the shapes:
Public Class frmPlay
Private Sub frmPlay_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
'pbox11.AllowDrop = True
'pbox22.AllowDrop = True
'pbox33.AllowDrop = True
'pbox44.AllowDrop = True
'pbox55.AllowDrop = True
'pbox66.AllowDrop = True
'pbox77.AllowDrop = True
'pbox88.AllowDrop = True
End Sub
Private Sub pboxes_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pbox1.MouseDown, pbox2.MouseDown, pbox3.MouseDown, pbox4.MouseDown, pbox5.MouseDown, pbox6.MouseDown, pbox7.MouseDown, pbox8.MouseDown
Dim pb As PictureBox = DirectCast(sender, PictureBox)
pb.DoDragDrop(pb.Image, DragDropEffects.Copy)
End Sub
Private Sub pboxes_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles pbox11.DragOver, pbox22.DragOver, pbox33.DragOver, pbox44.DragOver, pbox55.DragOver, pbox66.DragOver, pbox77.DragOver, pbox88.DragOver
If e.Data.GetDataPresent(DataFormats.Bitmap) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub pboxes_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles pbox11.DragDrop, pbox22.DragDrop, pbox33.DragDrop, pbox44.DragDrop, pbox55.DragDrop, pbox66.DragDrop, pbox77.DragDrop, pbox88.DragDrop
If e.Data.GetDataPresent(DataFormats.Bitmap) Then
Dim pb As PictureBox = DirectCast(sender, PictureBox)
pb.Image = DirectCast(e.Data.GetData(DataFormats.Bitmap), Bitmap)
End If
End Sub
Private Sub btnPause_Click(sender As System.Object, e As System.EventArgs) Handles btnPause.Click
frmPause.ShowDialog()
End Sub
Private Sub RotateClockwise(ByVal line As LineShape)
'Code to rotate the passed line clockwise here
Dim x1 As Integer = line.X1
Dim y1 As Integer = line.Y1
Dim x2 As Integer = line.X2
Dim y2 As Integer = line.Y2
End Sub
Private Sub RotateCounterclockwise(ByVal line As LineShape)
'Code to rotate the passed line counter-clockwise here
End Sub
Private Sub LineShape_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
'Which line?
Dim line As LineShape = TryCast(sender, LineShape)
If line Is Nothing Then Exit Sub
'Left key?
If e.KeyCode = Keys.Left Then RotateCounterclockwise(line)
'Right key?
If e.KeyCode = Keys.Right Then RotateClockwise(line)
End Sub
Private Sub frmPlay_Load_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
If you can make any sense of this I would really appreciate it, thanks you for reading!
Aucun commentaire:
Enregistrer un commentaire