locked
help me pls...rush RRS feed

  • Question

  • can anyone or someone help me?i need to know how to put a command on an image?probably like using arrow keys to make it move?

    like in a game,when u press a direction key,the character follow that command

    pls help..need response asap

    tnx


    Wednesday, March 17, 2010 8:43 AM

All replies

  • In WPF I'd use a button, iCommand and stick the image control on a canvas.

    Wednesday, March 17, 2010 9:29 AM
  • im just new and has no background in VB at all..more on turbo c..hm can u give me the code?
    Thursday, March 18, 2010 1:59 AM
  • Hi.  This is really the wrong forum for this kind of question.  Please try posting in the Visual Basic General forum if you are using VB: 

    http://social.msdn.microsoft.com/forums/en-US/vbgeneral/threads/#page:1

     

    Monday, March 22, 2010 8:26 PM
  • can anyone or someone help me?i need to know how to put a command on an image?probably like using arrow keys to make it move?

    like in a game,when u press a direction key,the character follow that command

    pls help..need response asap

    tnx



    check out the programmers' friend - the Button class .

     


    Micky D
    Thursday, March 25, 2010 11:23 AM
  • You really should have taken my advice and reposted in the VB General forum -- that is where you need to fiund support for VB-related questions in the future.

    What you need to do is trap the key events on the form that contains the picture box.  When the arrow keys are pressed then you change the Location property of the picture box.  Very simple - my code below does the absolute minimum in this regard.  Just paste that code behind your Form1 in a new Windows Forms project and run it then press the arrow keys.

    I don't know what you are going to make with this code but if it is a simple code then you will need to maybe test for collision with other objects, test for when the object moves to the edge of the form, and possibly account for the user holding the arrow key down (hint:  look at the KeyPress event rather than KeyDown).  Please do not post any further questions on this thread (unless it has been moved by a moderator to an appropriate forum).  When (and I mean when) you come upon further questions with your project you need to post them in the proper forum -- and that can be found in the link from my first post.  You will be very surpised I thinbk to see how fast you will get responses there (often in a few minutes).  So please respect the forums and learn how to use them properly.

    Oh yeah - and it would be good for you to learn how to Google for answers before posting -- even if you do not find a perfect answer you will have done some research on the topic, which will assist the answerers here when they try to help you.  Try googling "VB.NET move a picturebox with arrow keys " and see what comes up ;)

     

    Public Class Form1
        'NOTE: DO NOT ADD ANY CONTROLS TO THE FORM - JUST PASTE THIS CODE AND RUN THE PROJECT.
        Private WithEvents Gamepiece As New PictureBox
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles MyBase.Load
            'NOTE:  If you make your own picturebox then remove this code.
            Me.Size = New Size(500, 500)
            Gamepiece.Size = New Size(10, 10)
            Gamepiece.BackColor = Color.Red
            Me.Controls.Add(Gamepiece)
            Gamepiece.Location = New Point(245, 245)
        End Sub
    
        Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) _
        Handles Me.KeyDown
            Dim newPOint As Point = Gamepiece.Location
    
            Select Case e.KeyCode
                Case Keys.Left
                    newPOint.X -= 1
                Case Keys.Right
                    newPOint.X += 1
                Case Keys.Down
                    newPOint.Y += 1
                Case Keys.Up
                    newPOint.Y -= 1
            End Select
            Gamepiece.Location = newPOint
            Gamepiece.Refresh()
    
        End Sub
    
    End Class
    
    Thursday, March 25, 2010 12:23 PM