Export (0) Print
Expand All
Expand Minimize

Form Object for Visual Basic 6.0 Users 

The Form object in Visual Basic 6.0 is replaced by the Form class in Visual Basic 2005. The names of some properties, methods, events, and constants are different, and in some cases there are differences in behavior.

Conceptual Differences

Activate and Deactivate Events

In Visual Basic 6.0, the Activate and Deactivate events are raised only when switching between forms.

In Visual Basic 2005, the Activated and Deactivate events are also raised when switching to or from other applications.

QueryUnload Event

In Visual Basic 6.0, the QueryUnload event takes two arguments, Cancel and UnloadMode. By querying the UnloadMode argument you can determine why the form is being unloaded and then cancel if necessary.

In Visual Basic 2005, the QueryUnload event is replaced by the FormClosing event; UnloadMode is replaced by CloseReason.

Picture Property

In Visual Basic 6.0, an image assigned to the Picture property is displayed in the top left corner of the form if the bitmap is smaller than the form.

In Visual Basic 2005, the Picture property is replaced by the BackgroundImage property; if the image assigned to the BackgroundImage property is smaller than the form, it will be tiled by default.

Moveable Property

In Visual Basic 6.0, the Moveable property of a form can be set to False to prevent a user from moving the form at run time. Windows Forms in Visual Basic 2005 do not have an equivalent property.

Although it is generally considered bad user interface design, you can achieve similar behavior in Visual Basic 2005 by setting the FormBorderStyle property to None and the ControlBox property to False.

ValidateControls Method

In Visual Basic 6.0, the ValidateControls method is used to force the Validate event for the control that has focus when a form is closed; if the Validate event fails, an error is raised.

In Visual Basic 2005, the ValidateControls method is replaced by the Validate method, which returns True or False.

Mouse Events for MDI Forms

In Visual Basic 6.0, MDI Forms supports mouse events. In Visual Basic 2005, the Click, MouseDown, MouseMove, and MouseUp events are no longer supported for MDI Forms, because the MDI Form has no client area to receive mouse events.

Code Changes for the Form Object

The following examples illustrate the differences in coding techniques between Visual Basic 6.0 and Visual Basic 2005.

Code Changes for Determining Why a Form Closes

The following code can help you determine why a form closes and then how to act depending on the reason. In the Visual Basic 6.0 example, the UnloadMode argument of the QueryUnload event is used. In the Visual Basic 2005 example, the argument is replaced by the CloseReason parameter in the FormClosing event handler.

' Visual Basic 6.0
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If UnloadMode = vbFormControlMenu Then
        Cancel = True
    End If
End Sub
' Visual Basic 2005
Private Sub Form1_FormClosing(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles _
MyBase.FormClosing
    If e.CloseReason.UserClosing Then
        e.Cancel = True
    End If
End Sub

Code Changes for Validating a Control on Form Close

The following code demonstrates how to force the validation of the control that has focus when the form closes. This example assumes that the CausesValidation property of the TextBox control is set to the default value of True.

' Visual Basic 6.0
Private Sub Text1_Validate(Cancel As Boolean)
    If Text1.Text = "" Then
        MsgBox ("Please enter a name")
        Cancel = True
End If

Private Sub Form_Unload(Cancel As Integer)
    OnError GoTo ERR_HANDLER
    Me.ValidateControls

ERR_HANDLER:
    ' If validation failed cancel the Unload event.
    If Err.Number = 380 Then
        Cancel = True
    End If
End Sub
' Visual Basic 2005
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As _
System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
    If TextBox1.Text = "" Then
        MsgBox("Please enter a name")
        e.Cancel = True
    End If
End Sub

Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e _
As System.Windows.Forms.FormClosingEventArgs) Handles _
MyBase.FormClosing
    ' If validation failed cancel the Closing event.
    If Me.Validate = False Then
        e.Cancel = True
    End If
End Sub

Form Object Property, Method, and Event Equivalencies

The following tables list Visual Basic 6.0 properties, methods, and events, along with their Visual Basic 2005 properties. Those properties, methods, and events that have the same name and behavior are not listed. Where applicable, constants are indented beneath the property or method. All Visual Basic 2005 enumerations map to the System.Windows.Forms namespace unless otherwise noted.

Links are provided as necessary to topics explaining differences in behavior. Where there is no direct equivalent in Visual Basic 2005, links are provided to topics that present alternatives.

Form Properties

Visual Basic 6.0 Visual Basic 2005 Equivalent

Appearance

New implementation. For more information, see Appearance and BorderStyle Properties for Visual Basic 6.0 Users.

AutoRedraw

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

BackColor

BackColor

NoteNote

Colors are handled differently in Visual Basic 2005. For more information, see Color Behavior for Visual Basic 6.0 Users.

BorderStyle

FormBorderStyle

Caption

Text

ClipControls

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

Controls

Controls

NoteNote

There are differences in the Controls collection in Visual Basic 2005. For more information, see Controls Collection for Visual Basic 6.0 Users.

Count

Count

NoteNote

There are differences in the Controls collection in Visual Basic 2005. For more information, see Windows Forms Controls for Visual Basic 6.0 Users.

CurrentX

CurrentY

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

DrawMode

DrawStyle

DrawWidth

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

FillColor

FillStyle

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

Font

FontBold

FontItalic

FontName

FontSize

FontStrikethrough

FontUnderline

Font

NoteNote

Fonts are handled differently in Visual Basic 2005. For more information, see Font Object for Visual Basic 6.0 Users.

ForeColor

ForeColor

NoteNote

Colors are handled differently in Visual Basic 2005. For more information, see Color Behavior for Visual Basic 6.0 Users.

HasDC

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

HDC

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

Height

Height, Size

NoteNote

Coordinates are handled differently in Visual Basic 2005. For more information, see Coordinate System for Visual Basic 6.0 Users.

HelpContextID

New implementation. For more information, see Help Support for Visual Basic 6.0 Users.

HWnd

Handle

Image

New implementation. The Image property in Visual Basic 6.0 returned a handle to a bitmap; images in Visual Basic 2005 do not have handles.

Left

Left

NoteNote

Coordinates are handled differently in Visual Basic 2005. For more information, see Coordinate System for Visual Basic 6.0 Users.

LinkMode

LinkTopic

No equivalent. For more information, see Dynamic Data Exchange for Visual Basic 6.0 Users.

MaxButton

MaximizeBox

MDIChild

MdiParent

NoteNote

MDI behavior is different in Visual Basic 2005. For more information, see MDI for Visual Basic 6.0 Users.

MinButton

MinimizeBox

MouseIcon

New implementation. For more information, see Cannot set a custom MousePointer.

MousePointer

Cursor

For a list of constants, see MousePointer for Visual Basic 6.0 Users.

Moveable

New implementation. For more information, see Moveable Property for Visual Basic 6.0 Users.

Name

Name

NegotiateMenus

New implementation. For more information, see Menu Object for Visual Basic 6.0 Users.

OLEDropMode

New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users.

Palette

PaletteMode

New implementation. For more information, see Palettes for Visual Basic 6.0 Users.

Picture

BackgroundImage

NoteNote

In Visual Basic 6.0, the Picture was displayed in the top left corner of the form; in Visual Basic 2005, the BackgroundImage is tiled.

RightToLeft:

True

False

RightToLeft

Yes enumeration value

ScaleHeight

ScaleLeft

ScaleMode

ScaleTop

ScaleWidth

New implementation. For more information, see Coordinate System for Visual Basic 6.0 Users.

StartUpPosition:

0 – Manual

1 – CenterOwner

2 – CenterScreen

3 – Windows Default

StartPosition

 Manual enumeration value

 CenterParent enumeration value

 CenterScreen enumeration value

 WindowsDefaultLocation enumeration value

Top

Top

NoteNote

Coordinates are handled differently in Visual Basic 2005. For more information, see Coordinate System for Visual Basic 6.0 Users.

WhatsThisButton

HelpButton

NoteNote

There are differences in Help behavior in Visual Basic 2005. For more information, see Help Support for Visual Basic 6.0 Users.

WhatsThisHelp

New implementation. For more information, see Help Support for Visual Basic 6.0 Users.

Width

Width, Size

NoteNote

Coordinates are handled differently in Visual Basic 2005. For more information, see Coordinate System for Visual Basic 6.0 Users.

Form Methods

Visual Basic 6.0 Visual Basic 2005 Equivalent

Circle

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

Cls

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

Line

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

Move

SetBounds

NoteNote

Coordinates are handled differently in Visual Basic 2005. For more information, see Coordinate System for Visual Basic 6.0 Users.

OLEDrag

New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users.

PaintPicture

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

Point

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

PopupMenu

New implementation. For more information, see Menu Object for Visual Basic 6.0 Users.

PrintForm

New implementation. For more information, see Printing Changes for Visual Basic 6.0 Users.

Pset

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

Scale

ScaleX

ScaleY

New implementation. For more information, see Coordinate System for Visual Basic 6.0 Users.

SetFocus

Activate

Show

Show or ShowDialog

TextHeight

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

TextWidth

New implementation. For more information, see Graphics for Visual Basic 6.0 Users.

ValidateControls

Validate

NoteNote

The Validate method returns True or False; ValidateControls raised an error if validation failed.

WhatsThisMode

New implementation. For more information, see Help Support for Visual Basic 6.0 Users.

ZOrder:

 0 – vbBringToFront

 1 - vbSendToBack

BringToFront or SendToBack function

 BringToFront

 SendToBack

Form Events

Visual Basic 6.0 Visual Basic 2005 Equivalent

Activate

Activated

NoteNote

In Visual Basic 6.0, the Activate event is raised only when switching between forms in the application; in Visual Basic 2005, the Activated event also is raised when switching from other applications.

Click

Click

NoteNote

The Click event is not supported for MDI Forms.

DblClick

DoubleClick

Deactivate

Deactivate

NoteNote

In Visual Basic 6.0, the Deactivate event is raised only when switching between forms in the application; in Visual Basic 2005, it also is raised when switching to other applications.

DragDrop

DragOver

New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users.

GotFocus

Enter

Initialize

New method

NoteNote

The behavior of the New method is different than the Initialize event. For more information, see Forms Tasks for Visual Basic 6.0 Users.

LinkClose

LinkError

LinkExecute

LinkOpen

No equivalent. For more information, see Dynamic Data Exchange for Visual Basic 6.0 Users.

MouseDown

MouseDown

NoteNote

The MouseDown event is not supported for MDI Forms.

MouseMove

MouseMove

NoteNote

The MouseMove event is not supported for MDI Forms.

MouseUp

MouseUp

NoteNote

The MouseUp event is not supported for MDI Forms.

OLECompleteDrag

OLEDragDrop

OLEDragOver

OLEGiveFeedback

OLESetData

OLEStartDrag

New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users.

QueryUnload

FormClosing

NoteNote

In Visual Basic 6.0, QueryUnload takes two arguments, Cancel and UnloadMode. In Visual Basic 2005, Cancel is replaced by Cancel; UnloadMode is replaced by CloseReason.

Terminate

Dispose method

NoteNote

The behavior of the Dispose method is different than the Terminate event. For more information, see Form Events for Visual Basic 6.0 Users.

Unload

FormClosing

NoteNote

The behavior of the FormClosing event is different than the Unload event. For more information, see Form Events for Visual Basic 6.0 Users.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft