Results 1 to 13 of 13

Thread: Picturebox inside a Picturebox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    154

    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.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    VB Code:
    1. Private Sub picInner_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     Static blnBusy As Boolean
    3.     If (Button And vbLeftButton) = vbLeftButton Then
    4.         If blnBusy = False Then
    5.             blnBusy = True
    6.             picInner.Left = picInner.Left + X
    7.             blnBusy = False
    8.         End If
    9.     End If
    10. End Sub
    Best regards

  3. #3
    Can't you just say

    VB Code:
    1. If Button = vbLeftButton Then

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Yes if the user only pressed down the left button but what if he pressed both the left and the right button?

  5. #5
    Good point. Even though I don't do that, I guess it would be a stupidity check.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    154
    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?

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    VB Code:
    1. Private Sub picInner_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     Dim newX As Long
    3.     Static blnBusy As Boolean
    4.     If (Button And vbLeftButton) = vbLeftButton Then
    5.         If blnBusy = False Then
    6.             blnBusy = True
    7.             newX = picInner.Left + X
    8.             If newX < 0 Then
    9.                 newX = 0
    10.             ElseIf newX > picOuter.ScaleWidth - picInner.Width Then
    11.                 newX = picOuter.ScaleWidth - picInner.Width
    12.             End If
    13.             picInner.Left = newX
    14.             blnBusy = False
    15.         End If
    16.     End If
    17. End Sub
    Best regards

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    154
    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?

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    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:
    1. Dim nPos As Long
    2. nPos = picInner.Left / (picOuter.ScaleWidth - picInner.Width) * 100
    Best regards

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    154
    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.

  11. #11
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    You only have to change your code on two lines (the bold ones)
    VB Code:
    1. Private Sub pictInnerBalance_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
    2.     Dim volright As Long
    3.     Dim volleft As Long
    4.     Dim pos As String
    5.     Dim newX As Long
    6.     Static blnBusy As Boolean
    7.    
    8.    
    9.     If (Button And vbLeftButton) = vbLeftButton Then
    10.         If blnBusy = False Then
    11.             blnBusy = True
    12.             newX = pictInnerBalance.Left + x
    13.             If newX < 0 Then
    14.                 newX = 0
    15.             ElseIf newX > pictOuterBalance.ScaleWidth - pictInnerBalance.Width Then
    16.                 newX = pictOuterBalance.ScaleWidth - pictInnerBalance.Width
    17.             End If
    18.             pictInnerBalance.Left = newX
    19.             pos = pictInnerBalance.Left / (pictOuterBalance.ScaleWidth - pictInnerBalance.Width) * 200
    20.            
    21.             [b]volright = 200 - pos[/b]
    22.             [b]volleft = 200 - volright[/b]
    23.             Label1.Caption = "Left: " & volleft & "%" & " Right: " & volright & "%"
    24.             blnBusy = False
    25.         End If
    26.     End If
    27. End Sub
    Best regards

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    154
    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.

  13. #13
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    No simply change your code to something like this:
    VB Code:
    1. volright = 200 - pos
    2. volleft = 200 - volright
    3. [b]If volright > 100 Then
    4.     volright = 100
    5. ElseIf volleft > 100 Then
    6.     volleft = 100
    7. End If[/b]
    8. 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
  •  



Click Here to Expand Forum to Full Width