We Are GAP Mobilize
Free Assessment Tool

VBUC Migration Guide - Chapter 9

Upgrading Visual Basic 6.0 Forms Features

Most VB6 applications use forms. Given that big architecture changes have been made through the years, upgrading Visual Basic 6.0 forms to .NET has become an essential step in the migration process. Chapter 9 describes some of the techniques that will help you achieve functional equivalence for those forms features that are no longer supported in Visual Basic .NET. In other words, you will learn how to upgrade VB6 line controls, shape controls, popupmenu, drag and drop, property pages and control arrays to .NET.

What are the main differences in Visual Basic 6.0 and Visual Basic.NET on how graphic operations are performed?

There are several changes to how drawing operations are performed in Visual Basic .NET. For example:

1. Removal of the Line Control in Visual Basic .NET

The Line control in Visual Basic 6.0 allows you to draw a line segment on a form. It has no equivalent control in Visual Basic .NET. When the upgrade wizard is applied, vertical and horizontal Line controls are replaced with the Windows Forms Label control, with the Text property set to an empty string, the BorderStyle property set to None, and the BackColor, Width, and Height properties set to match the original control. Line controls that are not vertical or horizontal are not upgraded; the upgrade wizard replaces such lines with a Label control, with the BackColor property set to Red to highlight the issue. Line controls can be replaced with lines drawn in the Paint event using graphics functions available in Visual Basic .NET.

2. Removal of the Shape Control in Visual Basic .NET

The Shape control in Visual Basic 6.0 has no equivalent in Visual Basic .NET. Rectangular or square Shape controls in code are replaced with Windows Forms Label controls where the BorderStyle is set to FixedSingle, and the BackColor, Width, and Height properties are set to match the original control. Oval and circle Shape controls cannot be upgraded; they are replaced with a placeholder Label control with its BackColor property set to Red. You can replace Shape controls with drawing methods in the Paint event. This strategy can be used for any Shape control, but it is mandatory for oval and circle Shape controls.

Are all features of Visual Basic 6.0 PopupMenu method available in Visual Basic .NET?

No. Flags and boldcommand arguments have no equivalent. Menu items in Visual Basic .NET can not be set to bold with version 1.1 of the .NET Framework unless you use owner-drawn menus. However, this ability has been added to version 2.0. The popup menu position depends entirely on the position specified in the parameters of the Show method, and the pop-up menu reacts to a mouse click only when you use the left mouse button. Additional visual effects, such as bold items, can be achieved in Visual Basic .NET by using the enuItem.OwnerDraw property to specify that a menu item will be drawn by the owner. This technique requires a user-defined event handler for the MenuItem.DrawItem event and the usage of the Graphics object.

Does Visual Basic.NET support the ClipControls property?

No. When your application is upgraded and this property is referenced in the code, it is left as-is and is marked with upgrade warnings. To correct this issue, you must replace references to the property with a call to the Graphics.SetClip method. By providing an event handler for the Paint event, you can access the Graphics object associated with the control that is going to be drawn. Using this object, the SetClip method can be called to specify a clipping region. This is a somewhat advanced technique that requires additional work; before writing custom drawing routines you should test the drawing performance of your upgraded application.

The ClipControls property is used to improve performance in hardware that has limited capabilities. Modern high-performance computers and video cards are often sufficient to render displays without the need for clipping.

What are the differences between the Drag-and-Drop functionalities in Visual Basic 6.0 and Visual Basic .NET?

Visual Basic 6.0 supports two kinds of drag-and-drop operations: standard drag-and-drop functionality, which supports moving items between controls within a single form, and OLE drag-and-drop functionality, which supports moving items between applications.

In Visual Basic .NET, the drag-and-drop operations are consolidated into a single framework. Drag-and-drop operations between controls is handled the same as drag-and-drop operations between applications. This change simplifies the programming burden for new development, but it requires rewriting drag-and-drop code for existing applications.

The changes necessary to make the drag-and-drop code work in Visual Basic .NET are fairly significant. Because of changes in the drag-and-drop programming model, the upgrade wizard cannot automatically make the modifications. Instead, the methods are unchanged, and you have to implement the logic in the Visual Basic.NET drag-and-drop event model.

Are custom mouse pointers supported in Visual Basic.NET?

In Visual Basic 6.0, You can use the MousePointer and MouseIcon properties to display a custom icon, cursor, or any one of a variety of predefined mouse pointers. Changing the mouse pointer gives you a way to inform the user of a variety of activities or possible activities. Using custom icons or mouse pointers, you can express an endless range of visual information about the state and functionality of your application.

Custom mouse pointers are not supported at design time in Visual Basic

.NET; the MousePointer property is replaced by the Cursor property, and the

MouseIcon property no longer exists. However, you can load your custom mouse pointer in the Load event.

How has the Property Browser been improved in Visual Basic .NET?

Visual Basic 6.0 property pages allow you to work around the limitations of the

Visual Basic Property Browser. For example, you can use property pages to give users a way to add a collection of colors to a color list user control. In the property page, you would write code that manages the collection, something beyond the capabilities of the Visual Basic 6.0 Property Browser. In contrast, the Visual Basic .NET Property Browser can be used to edit any .NET variable type or class. Property pages are no longer needed.

How can I implement a functionality equivalent to Visual Basic 6.0’s property pages in Visual Basic.NET?

To implement a functionality equivalent to Visual Basic 6.0 property pages in Visual Basic .NET, it is necessary to use some .NET Framework classes and member attributes. The first class you should consider is System.Drawing.Design.UITypeEditor. This class provides basic functionality that you can use or derive from to implement a custom editor for the design-time environment.

How can I upgrade the OLE Container Control?

Visual Basic .NET does not support this control. As a result, the upgrade wizard is unable to convert it, replacing it with a red label to highlight the need to rewrite the code. A strategy for replacing the OLE Container is to use a WebBrowser ActiveX control in place of the OLE Container to display the Word document in the form. Through this control, you can display, edit, and save documents displayed in the control.

What steps should I follow to replace the OLE Container with a WebBrowser ActiveX Control?

1. Remove the red label inserted by the upgrade wizard as a placeholder for the OLE Container.

2. Add a WebBrowser control to the form. You can do this by right-clicking in the ToolBox, clicking Add/Remove Items, clicking the COM Components tab, and then clicking Microsoft WebBrowser Control in the Customize Toolbox component picker.

3. After you add the control, add the following code to the Form_Load subroutine (or wherever you want to bind to the document):

Me.AxWebBrowser1.Navigate("C:\Temp\LinkedDoc.doc")

Be sure to substitute the file name in this example for the location of the object to which you are linking. After completing these steps, you should be able to rebuild the solution.

Why did developers use Control Arrays in Visual Basic 6.0 and earlier versions?

There were three reasons:

1. To allow one event routine to be hooked to several controls

2. To access controls as a collection in a For Each loop

3. To dynamically add and remove controls in forms

Each of these tasks can be achieved in Visual Basic .NET using the available mechanisms for event handling, collections, and dynamic control creation.

How does the Event Handling Mechanism work in Visual Basic.NET?

Control arrays in Visual Basic 6.0 allow you to define one set of event procedures for all controls in the control array. In Visual Basic .NET, this functionality can be achieved for controls defined at design time and created at run time. The event handling mechanism allows controls to share event handler procedures without the need for control arrays.

How does the Collections Mechanism work in Visual Basic.NET?

Visual Basic .NET provides extensive support for collections and other types of structures that can be used to hold groups of controls. It is convenient to loop through the controls in a set like that to update common properties or modify the behavior of the controls. Because there are no control arrays in Visual Basic .NET, the user must explicitly build a collection of objects and add all the required objects. In this way, the user can create different groupings of objects according to the current needs.

How does the Dynamic Control Creation Mechanism work in Visual Basic.NET?

Another important goal of control arrays in Visual Basic 6.0 is that they provide an easy way to add controls at run time. You can create the control array at design time and then add controls of the same type to the array at run time. In Visual Basic .NET, you do not need a control array to add controls at run time. You can use the Controls collection to add controls of any type at run time; this will be shown in the next code example.

In the case where controls are dynamically added to a form according to the original Visual Basic 6.0 application logic, it will be necessary to dynamically connect the new controls with the preexisting event handlers. This can be done with the AddHandlerstatement, which ties events raised by controls with specific procedures that can handle the event.

What advantages do I get from using COM in Visual Basic .NET instead of DDE?

At one time, Dynamic Data Exchange (DDE) was one of the few ways you could

pass data between applications without using a shared file. However, DDE has since been replaced by COM. With COM, you can share data and invoke methods between applications in a more efficient and scalable manner. Because most Windows-based applications that expose public data and methods do so by way of COM, DDE is not the primary way that you retrieve public data and invoke public methods in a Windows-based application. As a consequence, COM can be used as a means of communicating with most Windows-based applications.

Talk To An Engineer