|
-
Jan 29th, 2003, 04:54 PM
#1
Thread Starter
Addicted Member
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
-
Jan 29th, 2003, 06:21 PM
#2
hmm is this what you want? or do you want to be able to mouse the picturebox as you move the mouse?
VB Code:
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
PictureBox1.Location = New Point(e.X, e.Y)
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:
Private isMouseDown As Boolean = False
Private initX, initY As Integer
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
isMouseDown = True
initX = e.X
initY = e.Y
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If isMouseDown Then
PictureBox1.Left += e.X - initX
PictureBox1.Top += e.Y - initY
End If
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
isMouseDown = False
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!!
-
Jan 29th, 2003, 06:27 PM
#3
Thread Starter
Addicted Member
Ok thank you soo much if i have any questions ill ask you
-
Jan 29th, 2003, 06:33 PM
#4
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!!
-
Jan 31st, 2003, 10:45 PM
#5
Thread Starter
Addicted Member
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?
-
Jan 31st, 2003, 10:56 PM
#6
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!!
-
Feb 1st, 2003, 10:13 AM
#7
Thread Starter
Addicted Member
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.
-
Feb 1st, 2003, 11:34 AM
#8
Addicted Member
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)
-
Feb 1st, 2003, 11:41 AM
#9
Thread Starter
Addicted Member
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 =))
-
Feb 1st, 2003, 03:50 PM
#10
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|