Results 1 to 8 of 8

Thread: Showing scrolling bars in UC

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Showing scrolling bars in UC

    now i'm trying build a 2D Level Editor ActiveX control.
    my 1st problem is for put the scroll bars in UC.
    heres the code:
    Code:
    If vNewValue = ScrlBars Then Exit Property
        'for showing the scroll bars, the UC is resized
        If vNewValue = None Then
            ScrollingHorizontal.Visible = False
            ScrollingVertical.Visible = False
            'put the scroll bars outside of UC
            UserControl.Width = UserControl.Width - ScrollingHorizontal.Height
            UserControl.Height = UserControl.Height - ScrollingVertical.Width
            ScrollingHorizontal.Top = UserControl.Height + 100
            ScrollingVertical.Left = UserControl.Width + 100
        ElseIf vNewValue = Horizontal Then
            ScrollingHorizontal.Visible = True
            ScrollingVertical.Visible = False
            'put the horizontal scroll bar in right position
            'and the other outside of it
            UserControl.Width = UserControl.Width + ScrollingHorizontal.Height
            UserControl.Height = UserControl.Height - ScrollingVertical.Width
            ScrollingHorizontal.Top = (UserControl.Height - ScrollingHorizontal.Width) * Screen.TwipsPerPixelY
            ScrollingVertical.Left = UserControl.Width + 100
        ElseIf vNewValue = Vertical Then
            ScrollingHorizontal.Visible = False
            ScrollingVertical.Visible = True
            'put the vertical scroll bar in right position
            'and the other outside of it
            UserControl.Width = UserControl.Width - ScrollingHorizontal.Height
            UserControl.Height = UserControl.Height + ScrollingVertical.Width
            ScrollingHorizontal.Top = UserControl.Height + 100
            ScrollingVertical.Left = (UserControl.Width - ScrollingHorizontal.Height) * Screen.TwipsPerPixelX
        ElseIf vNewValue = Both Then
            If ScrlBars = Both Then Exit Property
            ScrollingHorizontal.Visible = True
            ScrollingVertical.Visible = True
            'put both scroll bars in right position
            UserControl.Width = UserControl.Width + ScrollingHorizontal.Height
            UserControl.Height = UserControl.Height + ScrollingVertical.Width
            ScrollingHorizontal.Top = (UserControl.Height - ScrollingHorizontal.Width) * Screen.TwipsPerPixelY
            ScrollingVertical.Left = (UserControl.Width - ScrollingHorizontal.Height) * Screen.TwipsPerPixelX
        End If
        ScrlBars = vNewValue
    the scrolling bars aren't in right position, can anyone tell me what isn't right?
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: Showing scrolling bars in UC

    i change somethings in code:
    Code:
    If vNewValue = None Then
            ScrollingHorizontal.Visible = False
            ScrollingVertical.Visible = False
        ElseIf vNewValue = Horizontal Then
            ScrollingHorizontal.Visible = True
            ScrollingVertical.Visible = False
        ElseIf vNewValue = Vertical Then
            ScrollingHorizontal.Visible = False
            ScrollingVertical.Visible = True
        ElseIf vNewValue = Both Then
            ScrollingHorizontal.Visible = True
            ScrollingVertical.Visible = True
        End If
    and
    Code:
    Private Sub UserControl_Resize()
        ScrollingHorizontal.Top = UserControl.Height - ScrollingHorizontal.Height
        ScrollingHorizontal.Width = UserControl.Width - 240
        ScrollingVertical.Left = UserControl.Width - ScrollingVertical.Width
        ScrollingVertical.Height = UserControl.Height - 240
    End Sub
    my proble here is the UserControl Resize event. what isn't right in code for change the scrollbars position?
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: Showing scrolling bars in UC

    i resolve my problem:
    Code:
     ScrollingHorizontal.Top = UserControl.Height / Screen.TwipsPerPixelY - ScrollingHorizontal.Height
        ScrollingHorizontal.Width = UserControl.Width / Screen.TwipsPerPixelX - 16
        ScrollingVertical.Left = UserControl.Width / Screen.TwipsPerPixelX - ScrollingHorizontal.Height
        ScrollingVertical.Height = UserControl.Height / Screen.TwipsPerPixelY - 16
    now i have 2 questions:
    -why i must multply or divide by Screen.TwipsPerPixelY or Screen.TwipsPerPixelx?
    -when i know that i need use them?
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: Showing scrolling bars in UC

    how can i calculate the scrollbars max property value?
    i just can't do these:

    VerticalScrollBar.Max = PictureBox.Heigth
    HorizontalScrollBar.Max = PictureBox.Width

    because the max values depends, too, the UC size.
    can anyone explain to me something?
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: Showing scrolling bars in UC

    ok. i resolve the problem.
    Code:
    Private Sub ScrollingValues()
        ScrollingVertical.Max = picView.Height - UserControl.ScaleHeight
        If ScrlBars = Vertical Or ScrlBars = both Then ScrollingVertical.Max = ScrollingVertical.Max + 17
        ScrollingHorizontal.Max = picView.Width - UserControl.ScaleWidth
        If ScrlBars = Horizontal Or ScrlBars = both Then ScrollingHorizontal.Max = ScrollingHorizontal.Max + 17
        If picView.ScaleHeight <= UserControl.ScaleHeight Then ScrollingVertical.Max = 0
        If picView.ScaleWidth <= UserControl.ScaleWidth Then ScrollingHorizontal.Max = 0
    End Sub
    and works fine.
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: Showing scrolling bars in UC

    how can i see the controls name in these UC?
    i try these:
    UserControl.ContainedControls.Item(1).Name
    but i recive an error:
    "invalid property array".
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Unhappy Re: Showing scrolling bars in UC

    heres 1 thing 100% strange
    Code:
    Private Sub ScrollingHorizontal_Change()
        Dim i As Long
        Dim value As Long
        For i = 0 To UserControl.Controls.Count - 1
            If UserControl.Controls(i).Name = "Timer1" Or UserControl.Controls(i).Name = "Picture1" Or UserControl.Controls(i).Name = "ScrollingHorizontal" Or UserControl.Controls(i).Name = "ScrollingVertical" Then
            Else
                If value > ScrollingHorizontal.value Then
                    UserControl.Controls(i).Left = UserControl.Controls(i).Left + 1
                ElseIf value < ScrollingHorizontal.value Then
                    UserControl.Controls(i).Left = UserControl.Controls(i).Left - 1
                ElseIf value = 0 Then
                End If
            End If
        Next i
        value = ScrollingHorizontal.value
    End Sub
    when i click in left scrolling horizontal button, the controls move to the right. but if click in right button the controls move to the left. but why the controls move to the same way(instead move to the left it move to the right)?
    Last edited by joaquim; Dec 8th, 2008 at 12:12 PM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: Showing scrolling bars in UC

    ok... problem 100% resolved.
    the value variable was changed for HorizontalValue. i create these variable in declation section and when i change the horizontalscrollbar max property i give these variable 0 value.
    and i change morethings in code(if anyone want to know these code setp by step, just tell me):
    Code:
    Private Sub ScrollingHorizontal_Change()
        Dim i As Long
        For i = 0 To UserControl.Controls.Count - 1
            If UserControl.Controls(i).Name = "Timer1" Or UserControl.Controls(i).Name = "Picture1" Or UserControl.Controls(i).Name = "ScrollingHorizontal" Or UserControl.Controls(i).Name = "ScrollingVertical" Then
            Else
                If HorizontalValue > ScrollingHorizontal.value Then
                    UserControl.Controls(i).Left = UserControl.Controls(i).Left + (Abs(ScrollingHorizontal.value - HorizontalValue))
                ElseIf HorizontalValue < ScrollingHorizontal.value Then
                    UserControl.Controls(i).Left = UserControl.Controls(i).Left - (Abs(ScrollingHorizontal.value - HorizontalValue))
                End If
            End If
        Next i
        HorizontalValue = ScrollingHorizontal.value
    End Sub
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

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