Home > Code Library > SmartViewport Control

Last Update 29 Oct 2001

 


Search:



  

Options:

   

   

   

   



SmartViewport Control

About this page

You need a scrolling area?
A Pager perhaps?

In this page you will find a viewport control that you can freely use in your applications.

Downloads

SmartViewport.ocx

Requires SmartSubclass


How does SmartViewport work?

How many times have you needed to use scrollbars in your VB projects? Probably not too many but, when you need them, there's no other solution than having to hard-code all necessary procedures and functions to handle the required scrolling behaviour. That is, resizing the scrollbar, setting correct values for its 'Min' and 'Max' properties, deciding what values should 'LargeChange' and 'SmallChange' have and, finally, adding code to the 'Change' event in order to reposition whatever objects you want to scroll - not so difficult but time-consuming.

It makes sense to have a control that does all this for us. Viewports do not come as components with VB6, although there's a very good component called 'Panel' which comes with .NET and has scrolling capabilities. Anyway, the fact is that we do not have a scrolling Viewport in VB6 unless we buy one from a third-party company or we build one ourselves.

SmartViewport is a free control-container that allows you to build scrolling viewports in a matter of seconds. It has a large set of properties that will give you total control of the viewport behaviour. You just have to place a SmartViewport in your form, drop on it as many controls as you want and run your application. SmartViewport will automatically pop-up scrollbars as soon as any contained control gets out of its client area.

To better understand how SmartViewport works lets take a look at the following diagram:


          

The blue rectangle represents the viewport visible area. You can get its size by accessing properties 'Width' and 'Height'. The outer rectangle is the virtual page which is scrolled within the viewport. The size of this virtual page is automatically calculated based on the layout of the contained controls. You can read its dimensions through properties PageLeft, PageTop, PageWidth and PageHeight. If you add new controls to the viewport at run-time you should use method Refresh to let the viewport re-calculate the virtual-page bounds. OffsetX and OffsetY are the amount of twips the viewport has scrolled to either right or bottom of the page. You can read these properties at run-time but you can't modify them. Instead, you should use method Scroll to manually scroll the viewport. Finally, properties OffsetRight and OffsetBottom represent the distance between the last visible object and the viewport border. These properties are equal to 0 by default. You may want to have an offset to avoid your objects sticking to the right and bottom borders.

You can find below a list of properties, methods and events for the SmartViewport:

Properties
Methods
Events
BackColor
(1)
Drag
AfterScroll
BorderStyle
(1)
Move
(1)
Click
ButtonChange
Refresh
(1)
DblClick
ButtonHeight
Scroll
(1)
DragDrop
ButtonWidth
(1)
SetFocus
(1)
DragOver
(1)
CausesValidation
(1)
ShowWhatsThis
(1)
GotFocus
(1)
Container
(1)
ZOrder
(1)
Hide
CornerColor
 
(1)
LostFocus
(1)
DragIcon
 
(1)
KeyDown
(1)
DragMode
 
(1)
KeyPress
(1)
HeightHelpContextID
 
(1)
KeyUp
(1)
Index
 
(1)
MouseDown
(1)
Left
 
(1)
MouseMove
(1)
MouseIcon
 
(1)
MouseUp
(1)
MousePointer
 
(1)
Paint
(1)
Name
 
(1)
Resize
(1)
Object
 
ScrollBarHide
OffsetBottom
 
ScrollBarShow
OffsetRight
 
(1)
Show
OffsetX
 
(1)
Validate
OffsetY
 
 
PageLeft
 
 
PageHeight
 
 
PageTop
 
 
PageWidth
 
 
(1)
Parent
 
 
ScaleHeight
 
 
ScaleWidth
 
 
ScrollBarType
 
 
ScrollLargeChange
 
 
ScrollLeftRight
 
 
ScrollSmallChange
 
 
ScrollUpDown
 
 
(1)
TabIndex
 
 
(1)
TabStop
 
 
(1)
Top
 
 
(1)
Visible
 
 
(1)
WhatsThisHelpID
 
 
(1)
Width
 
 


(1) Please read Visual Basic documentation for a complete description of this property/method/event.

 

   Last Changes  

   27.May.2001

  • The control wasn't showing the scrollbars unless it was resized.
    This bug is now fixed.

    I would like to thank Colin Jamieson for reporting this bug.

   28.May.2001

  • An error was generated when SmartViewport was acting as a component of a usercontrol.
    This bug is now fixed.

  • An error was generated when the size of the virtual page was greater than 32,767 twips.
    This bug is now fixed and now the size of the virtual page can go up to 491,505 twips.

    Thanks to Károly Ladvánszky for finding these two problems.

   28.September.2001

  • SmartViewport was sometimes generating the following error when its Terminate event was fired:

    Run-time error '-2147418105 (80010007)':
    Automation error

    This bug is now fixed.

    Thanks to Janusz Ras for finding this bug.

 

 
Copyright © 2001, Andrés Pons (andres@vbsmart.com). All rights reserved.