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 2008. 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 2008, 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 2008, 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 2008, 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 2008 do not have an equivalent property.
Although it is generally considered bad user interface design, you can achieve similar behavior in Visual Basic 2008 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 2008, 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 2008, 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 2008.
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 2008 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 BasicPrivateSub Form1_FormClosing(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles _
MyBase.FormClosing
If e.CloseReason.UserClosing Then
e.Cancel = TrueEndIfEndSub
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 BasicPrivateSub TextBox1_Validating(ByVal sender AsObject, ByVal e As _
System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If TextBox1.Text = ""Then
MsgBox("Please enter a name")
e.Cancel = TrueEndIfEndSub
PrivateSub Form1_FormClosing(ByVal sender As System.Object, ByVal e _
As System.Windows.Forms.FormClosingEventArgs) Handles _
MyBase.FormClosing
' If validation failed cancel the Closing event.IfMe.Validate = FalseThen
e.Cancel = TrueEndIfEndSub
Form Object Property, Method, and Event Equivalencies
The following tables list Visual Basic 6.0 properties, methods, and events, along with their Visual Basic 2008 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 2008 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 2008, links are provided to topics that present alternatives.
Form Properties
Visual Basic 6.0 |
Visual Basic 2008 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 |
Note:
Colors are handled differently in Visual Basic 2008. For more information, see Color Behavior for Visual Basic 6.0 Users.
|
BorderStyle |
|
Caption |
|
ClipControls |
New implementation. For more information, see Graphics for Visual Basic 6.0 Users. |
Controls |
Note:
There are differences in the Controls collection in Visual Basic 2008. For more information, see Controls Collection for Visual Basic 6.0 Users.
|
Count |
Note:
There are differences in the Controls collection in Visual Basic 2008. 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 |
Note:
Fonts are handled differently in Visual Basic 2008. For more information, see Font Object for Visual Basic 6.0 Users.
|
ForeColor |
Note:
Colors are handled differently in Visual Basic 2008. 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 |
Note:
Coordinates are handled differently in Visual Basic 2008. 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 |
|
Image |
New implementation. The Image property in Visual Basic 6.0 returned a handle to a bitmap; images in Visual Basic 2008 do not have handles. |
Left |
Note:
Coordinates are handled differently in Visual Basic 2008. 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 |
|
MDIChild |
Note:
MDI behavior is different in Visual Basic 2008. For more information, see MDI for Visual Basic 6.0 Users.
|
MinButton |
|
MouseIcon |
New implementation. For more information, see Cannot set a custom MousePointer. |
MousePointer |
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 |
|
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 |
Note:
In Visual Basic 6.0, the Picture was displayed in the top left corner of the form; in Visual Basic 2008, the BackgroundImage is tiled.
|
RightToLeft: True False |
Yes enumeration value No 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 |
Manual enumeration value CenterParent enumeration value CenterScreen enumeration value WindowsDefaultLocation enumeration value |
Top |
Note:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.
|
WhatsThisButton |
Note:
There are differences in Help behavior in Visual Basic 2008. 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 |
Note:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.
|
Form Methods
Visual Basic 6.0 |
Visual Basic 2008 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 |
Note:
Coordinates are handled differently in Visual Basic 2008. 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 |
|
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 |
Note:
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 |
Form Events
Visual Basic 6.0 |
Visual Basic 2008 Equivalent |
---|---|
Activate |
Note:
In Visual Basic 6.0, the Activate event is raised only when switching between forms in the application; in Visual Basic 2008, the Activated event also is raised when switching from other applications.
|
Click |
Note:
The Click event is not supported for MDI Forms.
|
DblClick |
|
Deactivate |
Note:
In Visual Basic 6.0, the Deactivate event is raised only when switching between forms in the application; in Visual Basic 2008, 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 |
|
Initialize |
New method
Note:
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 |
Note:
The MouseDown event is not supported for MDI Forms.
|
MouseMove |
Note:
The MouseMove event is not supported for MDI Forms.
|
MouseUp |
Note:
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 |
Note:
In Visual Basic 6.0, QueryUnload takes two arguments, Cancel and UnloadMode. In Visual Basic 2008, Cancel is replaced by Cancel; UnloadMode is replaced by CloseReason.
|
Terminate |
Dispose method
Note:
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 |
Note:
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
Concepts
Forms Tasks for Visual Basic 6.0 Users