Results 1 to 10 of 10

Thread: simple movement of a picturebox....

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Posts
    216

    simple movement of a picturebox....

    I want to have a sample code so that i can look at, but what i want it to be is a code that will hav ethe picturebox1 move to whereever the mouse clicked so i need:

    1.)On mousedown move pctrbox1 there
    2.)make it so i can understand.

    Thank you so much, next is going to be map

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    hmm is this what you want? or do you want to be able to mouse the picturebox as you move the mouse?
    VB Code:
    1. Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
    2.         PictureBox1.Location = New Point(e.X, e.Y)
    3.     End Sub
    this will move the picturebox to where you clicked on the form.


    If you want to be able to drag the picturebox around then use this:
    VB Code:
    1. Private isMouseDown As Boolean = False
    2.     Private initX, initY As Integer
    3.  
    4.     Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
    5.         isMouseDown = True
    6.         initX = e.X
    7.         initY = e.Y
    8.     End Sub
    9.  
    10.     Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
    11.         If isMouseDown Then
    12.             PictureBox1.Left += e.X - initX
    13.             PictureBox1.Top += e.Y - initY
    14.         End If
    15.     End Sub
    16.  
    17.     Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
    18.         isMouseDown = False
    19.     End Sub
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Posts
    216
    Ok thank you soo much if i have any questions ill ask you

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    np
    just something that might be helpful to mention: note that in the first code, in the form_mousedown event, e.x and e.y are the location of mouse in the form. But in the second part of the code, e.x and e.y are the location of the mouse in the picturebox
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Posts
    216
    OK mr.polite i have another question: How can i make it so that the box wouldnt move instantly? like it would go to the destination one square at a time? Also how cna i set boundries?

  6. #6
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by james14
    OK mr.polite i have another question: How can i make it so that the box wouldnt move instantly? like it would go to the destination one square at a time? Also how cna i set boundries?
    hmm what do you mean? so when someone clicks it would start to move to that location ? like an animation?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Posts
    216
    Well,yeah kind of like that but say X is were i am and i clicked to Y

    X
    -
    -
    -
    -
    Y

    It would move straight down to the Y. It would slide down to the Y going to all of the - spaces before it got to Y... i hope you understand.

  8. #8
    Addicted Member ProgrammerJon's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    203
    why don't you use a timer?
    (I can't tell you how to use a timer because I don't know how to use it too much)

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Posts
    216
    no no no you missed the point. hmm you know how in shooting games and stuff? well like that kind of movement. you dont just go there automaticly it moves through the pixels (or square things i think) it doesnt just appear where you clicked it moves up one square at a time

    (i dont know hoe to use timers either =))

  10. #10
    Addicted Member ProgrammerJon's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    203
    Originally posted by james14
    no no no you missed the point. hmm you know how in shooting games and stuff? well like that kind of movement. you dont just go there automaticly it moves through the pixels (or square things i think) it doesnt just appear where you clicked it moves up one square at a time

    (i dont know hoe to use timers either =))
    \


    something like this:

    for i = 1 to mouseposition
    'pause sometime
    object.location = object.location + 1
    next i

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width