CheckBox Control for Visual Basic 6.0 Users
This topic compares the Visual Basic 6.0 CheckBox control with its equivalent in Visual Basic 2008.
The CheckBox control in Visual Basic 6.0 is replaced by the Windows Forms CheckBox control 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
Click Event
In Visual Basic 6.0, the Click event is raised when the CheckBox state is changed programmatically. In Visual Studio 2005 you use the CheckStateChanged event, not the Click event.
Additional Differences
In addition, there are numerous conceptual differences that apply to all controls, including differences in data binding, font handling, drag-and-drop, Help support, and more. For more information, see Windows Forms Overview and Additions to Windows Forms for the .NET Framework 2.0.
Code Changes for the CheckBox Control
The following examples illustrate differences in coding techniques between Visual Basic 6.0 and Visual Basic 2008.
Code Changes for Responding to CheckBox Clicks
The following code demonstrates changing the text of a CheckBox control when a user checks or unchecks the control. The Visual Basic 6.0 Value property is replaced by the Visual Basic 2008 Checked property, and the Caption property is replaced by the Text property. Notice that the Visual Basic 2008 example uses the CheckStateChanged event to duplicate the behavior of the Visual Basic 6.0 Click event.
' Visual Basic 6.0
Private Sub Check1_Click()
If Check1.Value = 1 Then
Check1.Caption = "Checked"
Else
Check1.Caption = "Unchecked"
End If
End Sub
' Visual BasicPrivateSub CheckBox1_CheckStateChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles CheckBox1.CheckStateChanged
If CheckBox1.Checked = TrueThen
CheckBox1.Text = "Checked"Else
CheckBox1.Text = "Unchecked"EndIfEndSub
Code Changes for Determining the State of a CheckBox
The following example demonstrates checking the state of a CheckBox control at run time.
' Visual Basic 6.0
Select Case Check1.Value
Case vbUnchecked
Check1.Caption = "Unchecked"
Case vbChecked
Check1.Caption = "Checked"
Case vbGrayed
Check1.Caption = "Disabled"
End Select
' Visual BasicSelectCase CheckBox1.CheckState
Case CheckState.Unchecked
CheckBox1.Text = "Unchecked"Case CheckState.Checked
CheckBox1.Text = "Checked"Case CheckState.Indeterminate
CheckBox1.Text = "Disabled"EndSelect
CheckBox Control Property, Method, and Event Equivalents
The following tables list Visual Basic 6.0 properties, methods, and events, along with their Visual Basic 2008 equivalents. Those properties, methods, and events that have the same names and behaviors 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.
Properties
Visual Basic 6.0 Property |
Visual Basic 2008 Equivalent |
---|---|
Alignment 0 (Left Justify) 1 (Right Justify) |
MiddleLeft enumeration value MiddleRight enumeration value |
Appearance 0 (Flat) 1 (3D) |
FlatStyle enumeration Flat enumeration value Standard enumeration value |
BackColor |
Note:
For a list of color constants, see Color Handling for Visual Basic 6.0 Users.
Note:
Colors are handled differently in Visual Basic 2008. For more information, see Color Behavior for Visual Basic 6.0 Users.
|
Caption |
|
Container |
|
DataChanged DataField DataFormat DataMember DataSource |
New implementation. For more information, see Data Access for Visual Basic 6.0 Users. |
DisabledPicture DownPicture |
New implementation. For more information, see How to: Emulate a Visual Basic 6.0 Tri-State Control in an Upgraded Application. |
DragIcon DragMode |
New implementation. For more information, see Drag and Drop 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 Handling for Visual Basic 6.0 Users.
|
ForeColor |
Note:
For a list of color constants, see Color Handling for Visual Basic 6.0 Users.
Note:
Colors are handled differently in Visual Basic 2008. For more information, see Color Behavior 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 |
|
Index |
New implementation. For more information, see Control Arrays for Visual Basic 6.0 Users. |
Left |
Note:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.
|
MaskColor |
New implementation. For more information, see MaskColor for Visual Basic 6.0 Users. |
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. |
OLEDropMode |
New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users. |
Parent |
FindForm method |
Picture |
|
RightToLeft True False |
Yes enumeration value No enumeration value |
Style 0 (Standard) 1 (Graphical) |
Normal enumeration value Button enumeration value
Note:
There are differences in how the Graphical style is handled in Visual Basic 2008. For more information, see How to: Emulate a Visual Basic 6.0 Tri-State Control in an Upgraded Application.
|
Tag |
|
ToolTipText |
ToolTip component For more information, see ToolTip Support for Visual Basic 6.0 Users. |
Top |
Note:
Coordinates are handled differently in Visual Basic 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.
|
UseMaskColor |
New implementation. For more information, see MaskColor for Visual Basic 6.0 Users. |
Value 0 (vbUnchecked) 1 (vbChecked) 2 (vbGrayed) |
Unchecked enumeration value Checked enumeration value Indeterminate enumeration value |
WhatsThisHelpID |
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.
|
Methods
Visual Basic 6.0 Method |
Visual Basic 2008 Equivalent |
---|---|
Drag |
New implementation. For more information, see Drag and Drop 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. |
SetFocus |
|
ShowWhatsThis |
New implementation. For more information, see Help Support for Visual Basic 6.0 Users. |
ZOrder 0 (vbBringToFront) 1 (vbSendToBack) |
Events
Visual Basic 6.0 Event |
Visual Basic 2008 Equivalent |
---|---|
Click |
Note:
In Visual Basic 6.0, the Click event is raised when the CheckBox state is changed programmatically. In Visual Basic 2008, the Click event is not raised; therefore, you should use the CheckStateChanged event.
|
DragDrop DragOver |
New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users. |
GotFocus |
|
LostFocus |
|
OLECompleteDrag OLEDragDrop OLEDragOver OLEGiveFeedback OLESetData OLEStartDrag |
New implementation. For more information, see Drag and Drop for Visual Basic 6.0 Users. |
Validate |
Upgrade Notes
When upgrading a Visual Basic 6.0 application using the Upgrade wizard, CheckBox controls are upgraded to Windows Forms CheckBox controls, and code is updated to use equivalent properties, methods, and events. Where there are no equivalents or where there are potential behavioral differences, comments are inserted into the code with a link to a Help topic.
See Also
Concepts
Data Access for Visual Basic 6.0 Users
Style Property for Visual Basic 6.0 Users
Font Handling for Visual Basic 6.0 Users
Coordinate System for Visual Basic 6.0 Users
Control Arrays for Visual Basic 6.0 Users
Help Support for Visual Basic 6.0 Users
MousePointer for Visual Basic 6.0 Users
ToolTip Support for Visual Basic 6.0 Users
Reference
CheckBox Control Overview (Windows Forms)
Other Resources
Upgrading Applications Created in Previous Versions of Visual Basic