15-08-16, 06:38 PM
السلام عليكم
عندي سوال في اداة OvalShape هو لما اضغط علي حرف ال w يتحرك حركة لفوق ولما اضغط D يتحرك حركة لليسار وعند الضغط علي S يتحرك حركة لتحت وعند الضغط علي A يتحرك حركة لليمين وشكرا اتمنا الرد السريع
(16-08-16, 02:55 AM)silverlight كتب : [ -> ]ممكن توضح لي هدفك من تحريك الشكل البيضاوي لأنك ممكن تشتغني عن الأداة OvalShape تماما
Public Class Form1
Private isMoving As Boolean = False
Private ovalShape As Rectangle = New Rectangle(10, 10, 80, 60)
Private Const speed As Integer = 2
Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp
isMoving = False
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
isMoving = True
Dim currentLocation As Point = ovalShape.Location
Dim x As Integer = currentLocation.X
Dim y As Integer = currentLocation.Y
If e.KeyCode = Keys.Right Then
x += speed
ElseIf e.KeyCode = Keys.Left Then
x -= speed
ElseIf e.KeyCode = Keys.Up Then
y -= speed
ElseIf e.KeyCode = Keys.Down Then
y += speed
End If
Dim newLocation As Point = New Point(x, y)
ovalShape.Location = newLocation
Invalidate()
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
Dim mode = e.Graphics.SmoothingMode
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
e.Graphics.FillEllipse(SystemBrushes.MenuHighlight, ovalShape)
e.Graphics.DrawEllipse(SystemPens.ControlDarkDark, ovalShape)
e.Graphics.SmoothingMode = mode
End Sub
End ClassPublic Class Form1
Private isMoving As Boolean = False
Private Const speed As Integer = 2
Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp
isMoving = False
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
isMoving = True
Dim currentLocation As Point = Label1.Location
Dim x As Integer = currentLocation.X
Dim y As Integer = currentLocation.Y
If e.KeyCode = Keys.Right Then
x += speed
ElseIf e.KeyCode = Keys.Left Then
x -= speed
ElseIf e.KeyCode = Keys.Up Then
y -= speed
ElseIf e.KeyCode = Keys.Down Then
y += speed
End If
Dim newLocation As Point = New Point(x, y)
Label1.Location = newLocation
End Sub
End Class
(17-08-16, 02:58 PM)silverlight كتب : [ -> ]ماذا تعني بكلمة زر المستر؟
انا فعلا مش فاهم كلامك و لو فيه شخص فاهم كلامك أتمني إنه يفهني ماذا تقصد بكلامك هذا