Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > VB6 > Скролинг области на форме


Автор: Rain 11.5.2006, 21:28
Привет всем! Опять я со своими проблемами))) Суть вот в чем:

Есть форма. Я добавляю на нее элемент управления( вертикальный скролинг) и мне нужно сделать так, чтобы область на форме на против моего скролинга с помощью него могла прокручиваться! Т.е я как понимаю нужно связать эту область и мой элемент управления.

КАК ЭТО СДЕЛАТЬ?????

Вроде ясно выразился)

Заранее спасибо! 

Автор: Cheburek 12.5.2006, 00:12
Не знаю как по другому делать, я всегда top объектов на форме менял, вот к примеру
Код

Private Sub Form_Load()
    Label1.Top = 0
    Label1.Caption = ""
    Label1.AutoSize = True
    Dim i As Integer
    For i = 1 To 100
        Label1.Caption = Label1.Caption & i & Chr(13) & Chr(10)
    Next
    If Form1.Height < Label1.Height Then
        VScroll1.Enabled = True
        VScroll1.Max = Label1.Height - Form1.Height + 200
    Else
        VScroll1.Enabled = False
    End If
End Sub
Private Sub VScroll1_Change()
    Label1.Top = -VScroll1.Value
End Sub
 

Автор: cardinal 12.5.2006, 00:56
Я бы только не так
Код

Private Sub VScroll1_Change()
    Label1.Top = -VScroll1.Value
End Sub

сделал, а так
Код

Private Sub VScroll1_Scroll()
    Label1.Top = -VScroll1.Value
End Sub

Так красивее... smile

Добавлено @ 01:05 
А вот другой прикольный вариант.

Код в форме:
Код

Option Explicit

' You have a royalty-free right to use, modify, reproduce and distribute
' the Sample Application Files (and/or any modified version) in any way
' you find useful, provided that you agree that Martin Liss has no warranty,
' obligations or liability for any Sample Application Files.


' All objects that should scroll must be drawn in picI_Scroll

' If you need to edit any of the objects that are below the bottom of the form,
' temporarily change picI_Scroll.Top to -1000, -10000, or whatever it takes

Public Disclaimer

Private Sub cmdExit_Click()

    Unload Me
    Set frmScroll = Nothing
    
End Sub

Private Sub Form_Activate()

    ' So that scrooling will happen if the user immediately presses
    ' PageUp or PageDown
    picI_Scroll.SetFocus
    
End Sub

Private Sub Form_Load()

    
    picWindow.Left = 0
    picWindow.Width = Me.Width - VScroll1.Width
    
    VScroll1.Height = picWindow.Height
    VScroll1.Max = picI_Scroll.Height - picWindow.Height
    VScroll1.SmallChange = 100
    VScroll1.LargeChange = picWindow.Height
    VScroll1.Left = Me.Width - VScroll1.Width - 60
    VScroll1.Top = 0
    
    picI_Scroll.Left = 0
    picI_Scroll.Width = picWindow.Width
    
End Sub


Public Sub CheckKeyCode(KeyCode As Integer)
'***************************************************************************
'Purpose: Intercept and act on special keys on me so
'         that up and down arrows and scroll bar works as expected. Also
'         automatically scroll screen when Tab key would otherwise disappear
'         off the screen.
'Inputs:  KeyCode - The ASCII(?) value of the key pressed
'Outputs: None
'***************************************************************************

    Dim nScrollValue As Double
    Dim nOnePage As Integer
    
    nOnePage = Me.VScroll1.Height
    
    If KeyCode = vbKeyPageUp Or KeyCode = vbKeyPageDown Then
        If KeyCode = vbKeyPageDown Then
            nScrollValue = -Me.picI_Scroll.Top + nOnePage
        Else
            nScrollValue = -Me.picI_Scroll.Top - nOnePage
        End If
        'Make sure that the scroll bar 'handle' is not attempted to be positioned
        'below the bottom of the scroll bar.
        If nScrollValue > Me.VScroll1.Max Then
            nScrollValue = Me.VScroll1.Max
            Me.picI_Scroll.Top = -Me.VScroll1.Max
        End If
        If nScrollValue > 0 Then
            Me.VScroll1.Value = nScrollValue
        Else
            Me.VScroll1.Value = 0
        End If
    End If
    
End Sub


Private Sub picI_Scroll_KeyDown(KeyCode As Integer, Shift As Integer)

    CheckKeyCode KeyCode
    
End Sub

Private Sub VScroll1_Change()

    picI_Scroll.Top = -(VScroll1.Value)
    
    ' So that the scrollbar doesn't blink
    cmdExit.SetFocus

End Sub

Пример взят на: www.vbforums.com 

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)