KnowDotNet Visual Organizer

Scrolling Forms and Windows are a Snap in .NET

Good Reasons to Migrate to .NET

by Les Smith
Print this Article Discuss in Forums

Need to create a scrolling form or a form with one or more scrolling windows in your application?  Visual Studio NET makes it a snap to do.

In VB6, I did a contract application that required scrolling forms and scrolling windows on forms.  One of the reasons for this is that several forms had over 100 controls, including approximately 50 TextBoxes and associated Labels.  Regardless of the screen resolution, I could not make a form that was readable without making the form scrollable. To do this in VB6, I had two options.  The first was a 3rd party tool that allowed a form to scroll.  The second option was to create pure VB code that would scroll a PictureBox with vertical and horizontal scroll bars.

I chose to use the latter option, and it required a lot of code and I had to write an add-in designer to be able to scroll the form and windows at design time.  I got the job done, but it was not a piece of cake.

With Visual Studio .NET you have the ability to make a form scroll, simply by setting the AutoScroll property to True.  Figure 1 shows an example scrolling form at design time.  Once the AutoScroll property is set, any time you move the bottom of any control past the bottom of the form, or you move the right border of a control past the right side of the form, the scroll bar(s) will appear.

Figure 1 - Scrolling Form.

Scrolling Form


Now suppose that you need to create a scrolling window, so that you can have a number of controls, that are rarely used, but you want them visible and you do not want them to take up a lot of space.  Again, in VB6, I did this with an Add-in (VBCommander/Pro), which could not only generate the pure VB code to create the window, but had a designer that would scroll the window at design time.

Visual Studio .NET once again comes to the rescue.  Figure 2 shows a form with a scrolling window.  To create this window, I added a Panel control, set the BorderStyle to Fixed3D, and AutoScroll to True.  Next, I placed some controls on the Panel.  If you move one of the controls outside of the border of the Panel, the Panels Scroll Bar(s) will appear.

Figure 2 - Scrolling Window.

Scrolling Window


Obviously, you can have scrolling windows on a scrolling form.  This is illustrated in Figure 3.  And with Visual Studio .NET you can do this with VB.NET and C# applications, and without 3rd Party controls!  

Figure 3 - Scrolling Form and Scrolling Window.

Scrolling Window and Form


If you are considering moving to .NET, this gives you some more ammunition.

Writing Add-Ins for Visual Studio .NET
Writing Add-ins for Visual Studio .NET
by Les Smith
Apress Publishing