Export (0) Print
Expand All
Expand Minimize
8 out of 18 rated this helpful - Rate this topic

OptionButton Control for Visual Basic 6.0 Users

The OptionButton control in Visual Basic 6.0 is replaced by the Windows Forms RadioButton 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.

In Visual Basic 6.0, the Click event of the OptionButton control was raised only when its Value property was changed to True.

In Visual Basic 2008, the CheckedChanged event of the RadioButton control is raised each time the Checked property value changes to either True or False.

In addition, there are numerous conceptual differences that apply to all controls, including differences in data binding, font handling, drag-and-drop functionality, Help support and more. For more information, see Windows Forms Concepts for Visual Basic 6.0 Users.

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

Code Changes for Programmatically Selecting an OptionButton

The following code demonstrates how to select an OptionButton or RadioButton control from a group of two at run time.

' Visual Basic 6.0
If Option1.Value = True Then
    Option2.Value = True
Else
    Option1.Value = True
End If
' Visual Basic
If RadioButton1.Checked = True Then
    RadioButton2.Checked = True
Else
    RadioButton1.Checked = True
End If


Code Changes for Determining When an OptionButton is Selected

The following code demonstrates how to handle the Click event for the OptionButton control versus the CheckedChanged event for the RadioButton control.

' Visual Basic 6.0
' The Click event is only fired when the Value is True
Private Sub Option1_Click()
    MsgBox "Option1 was clicked"
End Sub

Private Sub Option2_Click()
    MsgBox "Option2 was clicked"
End Sub
' Visual Basic
' The CheckChanged event fires each time the RadioButton's Checked 
' value changes to either True or False.
Private Sub RadioButton1_CheckedChanged(ByVal sender As Object, ByVal _
e As System.EventArgs) Handles RadioButton1.CheckedChanged, _
RadioButton2.CheckedChanged
    ' Only execute if the Checked value is True.
    If sender.Checked = True Then
        MsgBox(sender.Name & " was clicked")
    End If
End Sub


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 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.

This table provides links to topics explaining behavior differences. Where there is no direct equivalent in Visual Basic 2008, links are provided to topics that present alternatives.

Properties

Visual Basic 6.0

Visual Basic 2008 Equivalent

Alignment

TextAlign

Appearance

FlatStyle

BackColor

BackColor

NoteNote:
For a list of constants, see Color Handling for Visual Basic 6.0 Users.
NoteNote:
Colors are handled differently in Visual Basic 2008. For more information, see Color Handling for Visual Basic 6.0 Users.

Caption

Text

Container

Parent

DisabledPicture

DownPicture

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

DragIcon

DragMode

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

Font

FontBold

FontItalic

FontName

FontSize

FontStrikethrough

FontUnderline

Font

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

ForeColor

ForeColor

NoteNote:
For a list of constants, see Color Handling for Visual Basic 6.0 Users.
NoteNote:
Colors are handled differently in Visual Basic 2008. For more information, see Color Handling for Visual Basic 6.0 Users.

Height

Height, Size

NoteNote:
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

Handle

Index

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

Left

Left

NoteNote:
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

Cursor

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

Image

RightToLeft:

 True

 False

RightToLeft

 Yes enumeration value

 No enumeration value

Style

Appearance

NoteNote:
There are differences in how the Graphical style is handled in Visual Basic 2008. For more information, see Style Property for Visual Basic 6.0 Users.

ToolTipText

ToolTip component

For more information, see ToolTip Support for Visual Basic 6.0 Users.

Top

Top

NoteNote:
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

Checked

WhatsThisHelpID

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 2008. For more information, see Coordinate System for Visual Basic 6.0 Users.

Methods

Visual Basic 6.0

Visual Basic 2008 Equivalent

Drag

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

Move

SetBounds

NoteNote:
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

Focus

ShowWhatsThis

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

ZOrder

BringToFront or SendToBack method

Events

Visual Basic 6.0

Visual Basic 2008 Equivalent

Click

CheckedChanged

NoteNote:
In Visual Basic 6.0, the Click event was raised only when the state was changed to True; in Visual Basic 2008, it is raised for both True and False.

DblClick

DoubleClick

DragDrop

DragOver

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

GotFocus

Enter

LostFocus

Leave

OLECompleteDrag

OLEDragDrop

OLEDragOver

OLEGiveFeedback

OLESetData

OLEStartDrag

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

Validate

Validating

When a Visual Basic 6.0 application is upgraded to Visual Basic 2008, any OptionButton controls are upgraded to Windows Forms RadioButton controls, and properties, methods and events are upgraded to their equivalent. Where there may be differences in behavior, upgrade comments are inserted into the code.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.