Professional Documents
Culture Documents
The CheckBox control is similar to the option button, except that a list of choices can be made using check boxes where you cannot choose more than one selection using an OptionButton. By ticking the CheckBox the value is set to True. This control can also be grayed when the state of the CheckBox is unavailable, but you must manage that state through code. When you place a CheckBox control on a form, all you have to do, usually, is set its Caption property to a descriptive string. You might sometimes want to move the little check box to the right of its caption, which you do by setting the Alignment property to 1-Right Justify, but in most cases the default setting is OK. If you want to display the control in a checked state, you set its Value property to 1-Checked right in the Properties window, and you set a grayed state with 2-Grayed. The only important event for CheckBox controls is the Click event, which fires when either the user or the code changes the state of the control. In many cases, you don't need to write code to handle this event. Instead, you just query the control's Value property when your code needs to process user choices. You usually write code in a CheckBox control's Click event when it affects the state of other controls. For example, if the user clears a check box, you might need to disable one or more controls on the form and reenable them when the user clicks on the check box again. This is how you usually do it (here I grouped all the relevant controls in one frame named Frame1): Private Sub Check1_Click() Frame1.Enabled = (Check1.Value = vbChecked) End Sub Note that Value is the default property for CheckBox controls, so you can omit it in code. I suggest that you not do that, however, because it would reduce the readability of your code. The following example illustrates the use of CheckBox control * Open a new Project and save the Form as CheckBox.frm and save the Project as CheckBox.vbp * Design the Form as shown below Object Form Property Caption Name Caption CheckBox Name Caption CheckBox Name Caption CheckBox Name Setting CheckBox frmCheckBox Bold chkBold Italic chkItalic Underline chkUnderline
Caption OptionButton Name Caption OptionButton Name Caption OptionButton Name Name TextBox Text Caption CommandButton Name
Red optRed Blue optBlue Green optGreen txtDisplay (empty) Exit cmdExit
Following code is typed in the Click() events of the CheckBoxes Private Sub chkBold_Click() If chkBold.Value = 1 Then txtDisplay.FontBold = True Else txtDisplay.FontBold = False End If End Sub Private Sub chkItalic_Click() If chkItalic.Value = 1 Then txtDisplay.FontItalic = True Else txtDisplay.FontItalic = False End If End Sub Private Sub chkUnderline_Click() If chkUnderline.Value = 1 Then
txtDisplay.FontUnderline = True Else txtDisplay.FontUnderline = False End If End Sub Following code is typed in the Click() events of the OptionButtons Private Sub optBlue_Click() txtDisplay.ForeColor = vbBlue End Sub Private Sub optRed_Click() txtDisplay.ForeColor = vbRed End Sub Private Sub optGreen_Click() txtDisplay.ForeColor = vbGreen End Sub To terminate the program following code is typed in the Click() event of the Exit button Private Sub cmdExit_Click() End End Sub http://visualbasic.freetutes.com/learn-vb6/lesson13.html
Diferencias conceptuales
En Visual Basic 6.0, el evento Click del control OptionButton slo se produca cuando su propiedad Value se cambiaba a True. En Visual Basic 2005, el evento CheckedChanged del control RadioButton se produce cada vez que el valor de la propiedad Checked cambia a True o False. Asimismo, hay numerosas diferencias conceptuales que se aplican a todos los controles, incluidas las diferencias en los enlaces de datos, control de fuentes, funcionalidad de arrastrar y colocar, compatibilidad con Ayuda y otras. Para obtener ms informacin, vea Conceptos de formularios Windows Forms para usuarios de Visual Basic 6.0.
VB
' Visual Basic 2005 If RadioButton1.Checked = True Then RadioButton2.Checked = True Else RadioButton1.Checked = True End If
VB
' Visual Basic 2005 ' 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
Propiedades
Visual Basic 6.0 Alignment Appearance Equivalente de Visual Basic 2005 TextAlign FlatStyle BackColor Nota Para obtener una lista de constantes, vea Control del color para usuarios de Visual Basic 6.0. Nota Los colores se controlan de forma diferente en Visual Basic 2005. Para obtener ms informacin, vea Control del color para usuarios de Visual Basic 6.0. Caption Container DisabledPicture DownPicture DragIcon Text Parent Nueva implementacin. Para obtener ms informacin, vea Propiedad Style para usuarios de Visual Basic 6.0. Nueva implementacin. Para obtener ms informacin, vea Arrastrar y colocar
BackColor
Font Nota Las fuentes se controlan de forma diferente en Visual Basic 2005. Para obtener ms informacin, vea Objeto Font para usuarios de Visual Basic 6.0.
ForeColor Nota Para obtener una lista de constantes, vea Control del color para usuarios de Visual Basic 6.0. Nota Los colores se controlan de forma diferente en Visual Basic 2005. Para obtener ms informacin, vea Control del color para usuarios de Visual Basic 6.0. Height, Size Height Nota Las coordenadas se controlan de forma diferente en Visual Basic 2005. Para obtener ms informacin, vea Sistema de coordenadas para usuarios de Visual Basic 6.0. Nueva implementacin. Para obtener ms informacin, vea Compatibilidad con la Ayuda para usuarios de Visual Basic 6.0. Handle Nueva implementacin. Para obtener ms informacin, vea Matrices de controles para usuarios de Visual Basic 6.0. Left Left Nota Las coordenadas se controlan de forma diferente en Visual Basic 2005. Para
ForeColor
obtener ms informacin, vea Sistema de coordenadas para usuarios de Visual Basic 6.0. MaskColor Nueva implementacin. Para obtener ms informacin, vea MaskColor para usuarios de Visual Basic 6.0 Nueva implementacin. Para obtener ms informacin, vea No se puede personalizar la propiedad MousePointer. Cursor MousePointer Para obtener una lista de constantes, vea MousePointer para usuarios de Visual Basic 6.0. Nueva implementacin. Para obtener ms informacin, vea Arrastrar y colocar para usuarios de Visual Basic 6.0. Mtodo FindForm Image RightToLeft Valor de la enumeracin Yes Valor de la enumeracin No Appearance Style Nota Existen diferencias en cmo se controla el estilo Graphical en Visual Basic 2005. Para obtener ms informacin, vea Propiedad Style para usuarios de Visual Basic 6.0. Componente ToolTip ToolTipText Para obtener ms informacin, vea Compatibilidad de la informacin sobre herramientas para usuarios de Visual Basic 6.0. Top Nota Las coordenadas se controlan de forma diferente en Visual Basic 2005. Para obtener ms informacin, vea Sistema de coordenadas para usuarios de Visual
MouseIcon
Top
Basic 6.0. UseMaskColor Value WhatsThisHelpID Nueva implementacin. Para obtener ms informacin, vea MaskColor para usuarios de Visual Basic 6.0. Checked Nueva implementacin. Para obtener ms informacin, vea Compatibilidad con la Ayuda para usuarios de Visual Basic 6.0. Width, Size Width Nota Las coordenadas se controlan de forma diferente en Visual Basic 2005. Para obtener ms informacin, vea Sistema de coordenadas para usuarios de Visual Basic 6.0.
Mtodos
Visual Basic 6.0 Drag Equivalente de Visual Basic 2005 Nueva implementacin. Para obtener ms informacin, vea Arrastrar y colocar para usuarios de Visual Basic 6.0. SetBounds Move Nota Las coordenadas se controlan de forma diferente en Visual Basic 2005. Para obtener ms informacin, vea Sistema de coordenadas para usuarios de Visual Basic 6.0. Nueva implementacin. Para obtener ms informacin, vea Arrastrar y colocar para usuarios de Visual Basic 6.0. Focus Nueva implementacin. Para obtener ms informacin, vea Compatibilidad con la Ayuda para usuarios de Visual Basic 6.0. Mtodo BringToFront o SendToBack
Eventos
Visual Basic 6.0 Click Equivalente de Visual Basic 2005 CheckedChanged
Nota En Visual Basic 6.0, el evento Click se produca slo cuando se cambiaba el estado a True; en Visual Basic 2005, se produce tanto para True como para False. DblClick DragDrop DragOver GotFocus LostFocus OLECompleteDrag OLEDragDrop OLEDragOver OLEGiveFeedback OLESetData OLEStartDrag Validate Validating Nueva implementacin. Para obtener ms informacin, vea Arrastrar y colocar para usuarios de Visual Basic 6.0. DoubleClick Nueva implementacin. Para obtener ms informacin, vea Arrastrar y colocar para usuarios de Visual Basic 6.0. Enter Leave
Notas de actualizacin
Cuando se actualiza una aplicacin de Visual Basic 6.0 a Visual Basic 2005, los controles OptionButton se actualizan a los controles RadioButton de formularios Windows Forms, y las propiedades, mtodos y eventos se actualizan a sus equivalentes. Donde puede haber diferencias en el comportamiento, se insertan comentarios de actualizacin en el cdigo.
Vea tambin
Referencia Informacin general sobre el control RadioButton (formularios Windows Forms)
http://msdn.microsoft.com/es-es/library/kd7e4yte%28v=vs.80%29.aspx