|
-
Aug 24th, 2001, 07:07 AM
#1
Thread Starter
Addicted Member
Picturebox inside a Picturebox
I am using this code to move the PictInner inside of PictOuter to a certain point inside of it:
-------------------------------------------------------------------------
Private Sub PictOuter_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
Dim pos As String
pos = Format(x / PictOuter.Width * 100, "0")
PictInner.left = PictOuter.Width * pos / 100
End Sub
-------------------------------------------------------------------------
My question is, how can I get the person to drag PictInner, instead of just being able to click somewhere in PictOuter, just like you would drag the sliderbar in a slider.
-
Aug 24th, 2001, 08:00 AM
#2
VB Code:
Private Sub picInner_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static blnBusy As Boolean
If (Button And vbLeftButton) = vbLeftButton Then
If blnBusy = False Then
blnBusy = True
picInner.Left = picInner.Left + X
blnBusy = False
End If
End If
End Sub
Best regards
-
Aug 24th, 2001, 08:01 AM
#3
Member
Can't you just say
VB Code:
If Button = vbLeftButton Then
-
Aug 24th, 2001, 08:03 AM
#4
Yes if the user only pressed down the left button but what if he pressed both the left and the right button?
-
Aug 24th, 2001, 08:04 AM
#5
Member
Good point. Even though I don't do that, I guess it would be a stupidity check.
-
Aug 24th, 2001, 08:09 AM
#6
Thread Starter
Addicted Member
Okay that worked great, but I have another question. When I drag pictinner now, I can keep dragging it forever at runtime, even though it is inside of pictouter. How can I make it so that you cant' move it past the end of pictouter?
-
Aug 24th, 2001, 08:13 AM
#7
VB Code:
Private Sub picInner_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim newX As Long
Static blnBusy As Boolean
If (Button And vbLeftButton) = vbLeftButton Then
If blnBusy = False Then
blnBusy = True
newX = picInner.Left + X
If newX < 0 Then
newX = 0
ElseIf newX > picOuter.ScaleWidth - picInner.Width Then
newX = picOuter.ScaleWidth - picInner.Width
End If
picInner.Left = newX
blnBusy = False
End If
End If
End Sub
Best regards
-
Aug 24th, 2001, 08:37 AM
#8
Thread Starter
Addicted Member
That worked perfect, except for one thing. It will only go from 0 to 70, and I need it to go from 0 to 100. Any way to do this?
-
Aug 24th, 2001, 09:12 AM
#9
Originally posted by ca1n3
That worked perfect, except for one thing. It will only go from 0 to 70, and I need it to go from 0 to 100. Any way to do this?
When you calculate the position you should use the following formula:
VB Code:
Dim nPos As Long
nPos = picInner.Left / (picOuter.ScaleWidth - picInner.Width) * 100
Best regards
-
Aug 24th, 2001, 09:58 AM
#10
Thread Starter
Addicted Member
Sorry, I stayed up all night and now I can't think. I am using this inner outer thing as a balance between the right and the left. How can I make it so that when it is in the middle, volleft and volright = 100, and when it gets to the end of the left side the volright is at 0, just the same when it gets to the end of the right side volleft will be 0. I dont care if in order for volright to be at 0, volleft needs to be at 200 or something, it doesnt matter, just as long as when it is all the way to the left volright is at 0. Sorry about the carry on sentences, but I am struggling to even keep my eyes open right now.
-----------------------------------------------------------
Private Sub PictInnerBalance_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
Dim volright As Long
Dim volleft As Long
Dim pos As String
Dim newX As Long
Static blnBusy As Boolean
If (Button And vbLeftButton) = vbLeftButton Then
If blnBusy = False Then
blnBusy = True
newX = PictInnerBalance.left + x
If newX < 0 Then
newX = 0
ElseIf newX > PictOuterBalance.ScaleWidth - PictInnerBalance.Width Then
newX = PictOuterBalance.ScaleWidth - PictInnerBalance.Width
End If
PictInnerBalance.left = newX
pos = PictInnerBalance.left / (PictOuterBalance.ScaleWidth - PictInnerBalance.Width) * 200
volright = pos
volleft = pos
label1.Caption = "Left: " & volleft & "%" & " Right: " & volright & "%"
blnBusy = False
End If
End If
End Sub
-----------------------------------------------------------
I put my code in there just for the hell of it, you will probably change it alot which is okay, since it doesnt work.
-
Aug 24th, 2001, 03:25 PM
#11
You only have to change your code on two lines (the bold ones)
VB Code:
Private Sub pictInnerBalance_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
Dim volright As Long
Dim volleft As Long
Dim pos As String
Dim newX As Long
Static blnBusy As Boolean
If (Button And vbLeftButton) = vbLeftButton Then
If blnBusy = False Then
blnBusy = True
newX = pictInnerBalance.Left + x
If newX < 0 Then
newX = 0
ElseIf newX > pictOuterBalance.ScaleWidth - pictInnerBalance.Width Then
newX = pictOuterBalance.ScaleWidth - pictInnerBalance.Width
End If
pictInnerBalance.Left = newX
pos = pictInnerBalance.Left / (pictOuterBalance.ScaleWidth - pictInnerBalance.Width) * 200
[b]volright = 200 - pos[/b]
[b]volleft = 200 - volright[/b]
Label1.Caption = "Left: " & volleft & "%" & " Right: " & volright & "%"
blnBusy = False
End If
End If
End Sub
Best regards
-
Aug 27th, 2001, 07:12 PM
#12
Thread Starter
Addicted Member
Thats almost perfect. They are both 100% when they are in the middle, which I need, and when it goes to the left it is at 0%, and when it goes to the right it is at 0%. The problem, is that when it is all the way to the left, right displays 200%, and I only want it to display 100%. That means, I think, that I am going to have to do something like this:
Label1.Caption = "Left: " & (volleft - 50) & "%" & " Right: " & (volright - 50) & "%"
except replace the "50" with whatever equation will make the two labels display 50% while in the middle, and 0% while at the opposite end of the spectrum. Feel free to do whatever you want to try and fix this problem, but try and only use label1.caption because if you change anything else then the volume will not only display 50% while in the middle, but it will actually be 50%, instead of being 100% which it needs to be. Thank you.
-
Aug 28th, 2001, 03:32 AM
#13
No simply change your code to something like this:
VB Code:
volright = 200 - pos
volleft = 200 - volright
[b]If volright > 100 Then
volright = 100
ElseIf volleft > 100 Then
volleft = 100
End If[/b]
Label1.Caption = "Left: " & volleft & "%" & " Right: " & volright & "%"
Best regards
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
|