none
moving an image RRS feed

  • Question

  • hi

    i need to move an image in a diagonal by using a loop for exemple = for ,while do until

    I can only click once to a button

    Can someone know  some code and i using Microsoft visual Basic 2010

    Sunday, September 10, 2017 3:55 AM

Answers

  • Hi mart122346,

    It seems that tommytwotrain's reply resolve your issue, if so, please mark it as answer, it will be beneficial to other communities who have the same issue.

    Thanks you for participating in the forum activities.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by mart122346 Tuesday, September 12, 2017 2:14 AM
    Monday, September 11, 2017 7:54 AM
    Moderator

All replies

  • i need to move an image in a diagonal by using a loop for exemple = for ,while do until

    I can only click once to a button

    Can someone know  some code and i using Microsoft visual Basic 2010

    It depends on how you are drawing the image - what is the image source, and what are you drawing it on?

    If you are writing a bitmap to a form then you will specify the location in the drawimage method. FOr instance, to draw the whole iage at a particular size:
    https://msdn.microsoft.com/en-us/library/dbsak4dc(v=vs.110).aspx

    Then you would increment the x and y values to move it diagonally.  You would not do this in a loop.  Put the drawing code in the form's paint event.  Create and start a timer.  Each time the timer ticks, increment the X and Y values, and invalidate the form.
    https://vbdotnetblog.wordpress.com/graphics/graphics-methodology/

    If you aren't drawing a bitmap to a form the process changes slightly, but the principal is the same - when the timer ticks, update the image position and draw the image.

    Sunday, September 10, 2017 5:03 AM
  •  Not sure what you're doing exactly but,  maybe the example i posted at the link below will help.  8)

    Drawing and moving a game sprite image on a form


    If you say it can`t be done then i`ll try it

    Sunday, September 10, 2017 11:54 AM
  • Here is a sample like you asked for. See how it loops in the while statement until the picturebox reaches the right side of the screen.

    This sample runs fairly fast, however, when the animation is running the application is locked up and does not respond to user events.

    If you intend to run an animation for longer than a second or so you should use a timer as the others have stated or a separate background thread for the animation. Than way you can animate continuously without freezing the application from user gui events because the application and system can still process other events between each timer tick.

    This example just moves a picturebox using a while. You can also draw the image on the form etc as others have said. But this freezes the app while the animation is running.

    Public Class Form5
        Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            PictureBox1.BackgroundImage = Image.FromFile("c:\bitmaps\rusty.jpg")
            PictureBox1.BackgroundImageLayout = ImageLayout.Zoom
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Static count As Single = 0
    
            While PictureBox1.Right < Me.ClientSize.Width
                count += CSng(0.0001)   'increment 0.001 to slow down 
                If count > 2 Then
                    count = 0
                    PictureBox1.Left += 2
                    PictureBox1.Top += 1
                End If
            End While
        End Sub
    End Class
    

    Sunday, September 10, 2017 12:53 PM
  • Off Topic...  Hi Tom.  8)

    If you say it can`t be done then i`ll try it

    Sunday, September 10, 2017 1:07 PM
  • Off Topic...  Hi Tom.  8)

    If you say it can`t be done then i`ll try it

    Hi Razerz!

    Sunday, September 10, 2017 1:08 PM
  • THANKS A LOT 

    I NEEDED this so much and its work

    Sunday, September 10, 2017 11:12 PM
  • Hi mart122346,

    It seems that tommytwotrain's reply resolve your issue, if so, please mark it as answer, it will be beneficial to other communities who have the same issue.

    Thanks you for participating in the forum activities.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by mart122346 Tuesday, September 12, 2017 2:14 AM
    Monday, September 11, 2017 7:54 AM
    Moderator