0% found this document useful (0 votes)
164 views

Command, Checkbox&amp Optionbuttons Visual Basic 6.0

The document discusses various properties and methods for customizing buttons, checkboxes, and option buttons in Visual Basic. It covers how to set captions, colors, fonts, images, tooltips, locations, states (enabled, visible), and events. It also provides examples of using control arrays, initializing multiple buttons with procedures, checking/setting checkbox and option button values, grouping option buttons in frames, and adding images to checkboxes and option buttons.

Uploaded by

Bibin Singh
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
164 views

Command, Checkbox&amp Optionbuttons Visual Basic 6.0

The document discusses various properties and methods for customizing buttons, checkboxes, and option buttons in Visual Basic. It covers how to set captions, colors, fonts, images, tooltips, locations, states (enabled, visible), and events. It also provides examples of using control arrays, initializing multiple buttons with procedures, checking/setting checkbox and option button values, grouping option buttons in frames, and adding images to checkboxes and option buttons.

Uploaded by

Bibin Singh
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 35

COMMAND BUTTON, CHECKBOX TOOL, OPTION BUTTON TOOL

COMMAND BUTTON TOOL CHECK BOX TOOL OPTION BUTTON TOOL

We use, a buttons Caption property to set its caption. This property is available at both design time and runtime. We can also change the buttons caption at runtime, of course. As an example, well use our tic-tac-toe program from Chapter 1:
Private Sub Form_Load() xNow = True End Sub Private Sub Command_Click(Index As Integer) If xNow Then
Command(Index).Caption = "x"

Else
Command(Index).Caption = "o"

End If xNow = Not xNow End Sub

have a property called ForeColor to set the text in a specified color. We can also set the text color through code also, for example,
We
Private Sub Command1_click() Check1.ForeColor=RGB(255,0,0) End Sub

Same

way we can also set the back color through coding with the help of the RGB() function, for example,
Command1.BackColor=RGB(255,0,0)

Notice that there are number of options in the Font dialog box, which means that you cant set a single property at runtime to set a buttons font. Instead, we can use the following properties:

y y y y y y

FontBold FontItalic FontName FontSize FontStrikethru FontUnderline

We also have direct access to the buttons Font object, so we can set those properties by referring to them as, for example, Option1.Font.Bold, Option1.Font.Italic, and so on.

We respond to button clicks with the buttons Click event. To add a Click event handler, just double-click the button at design time, which adds a subroutine like this one:
Private Sub Command1_Click() End Sub

Place the code we want to execute when the button is clicked in this subroutine:
Private Sub Command1_Click()
MsgBox "You clicked the command button!"

End Sub

All three buttons have a Click eventthey wouldnt be much use otherwiseand option buttons also have a double-click event, DblClick. If you double-click a checkbox, we select and then deselect it If you double-click an option button, however, we select it, no matter what its original state, and cause a DblClick event.

To create a control array, just give two controls of the same type the same name (in the Name property); when you do, Visual Basic will ask if you want to create a control array. We use a control array and one event handler function (the control array index of the button that was clicked is passed to the event handler, so you can tell which button you need to respond to). When you create an event handler subroutine for a button in the control array, Visual Basic will automatically pass the index of the control in the control array to that subroutine:

Private Sub GamePiece_Click(Index As Integer) End Sub

do that with the controls SetFocus() method, which is something you frequently do in real programs after button clicks. Heres how it might look in code:
We

Private Sub Command1_Click()


RichTextBox1.UpTo (gstrStringToFind) RichTextBox1.SetFocus

End Sub
Now,

when the user clicks the button and starts typing again, the focus will be back on the rich text box, as it should be. Note that you can set the control that has the focus when a form first appears by setting the controls Default property to True

can give menu items access characters those underlined characters in a menu item that the user can reach with the Alt key. Just place an ampersand (&) in front of the character in the buttons caption that you want to make into the access character for that button
We

To

make your buttons more accessible from the keyboardespecially if weve got a lot of them you can use the TabStop, TabIndex, and Default properties. Heres what those properties do:
TabStop indicates if this button can accept the focus when the user tabs to it. TabIndex is the index of the current button in the tab order (starts at 0). Default is True for one control on a form only; that control will have the focus when the form first appears

can disable the button by setting its Enabled property to False when its inappropriate to use that button. We can also disable buttons at runtime, of course, like this:
We

Private Sub Command1_Click() Command1.Enabled = False End Sub

To

make a button disappear, just set its Visible property to False. To make it reappear, set the Visible property to True. In runtime also we can disable is, for example
Private Sub Command1_Click() Command1.Visible = False End Sub

can do it using ToolTipText property for buttons We just place the text we want to appear in the tool tip into the ToolTipText property to create a tool tip for the button. We can also set tool tip text at runtime, using the ToolTipText property this way in code:
We

Private Sub Command1_Click()


Command1.ToolTipText = "You already clicked me!"

End Sub

We

can do it using the Top, Left, Height, and Width properties, or the Move method. Heres what those properties hold:
Left holds the horizontal coordinate of the upper left of the button. Top holds the vertical coordinate of the upper left of the button. Height holds the buttons height. Width holds the buttons width.

Using

the Picture property, we can load an image into a buttonjust click the button with the ellipsis () in the Picture propertys entry in the Properties window and indicate an image file in the Load Picture dialog box that opens. Thats not all, howeverwe also have to set the buttons Style property to Graphical. Weve loaded an image into a command button

can use the Load statement to load new buttons if theyre part of a control array. To see how this works, add a new button to a form, giving it the name, say, Command. To make it the first member of a control array, set its Index property to 0. Now when the user clicks this button, we can add a new button of the same type to the form with Load. Here, we load Command(1), because Command(0) is already on the form:
We

Private Sub Command_Click(Index As Integer)


Load Command(1)

End Sub

got 200 buttons in your new program, and each one has to be initialized with a long series of code statements. We can organize it easily. We can pass the buttons to a procedure and place the initialization code in that procedure. Heres an example.
Weve

Private Sub Command1_Click()


SetCaption Command1

End Sub
In

the SetCaption() procedure, you just declare the button as a parameter; well name that parameter Button and make it of type Control:
Private Sub SetCaption(Button As Control) End Sub

can see if a checkbox is checked by examining its Value property. Here are the possible Value settings for checkboxes:
We
0 Unchecked 1 Checked 2 Grayed

Heres

an example:

Private Sub Command1_Click()


If Check1.Value = 1 Then Command1.Caption = "The check mark is checked"

End If

We

can set a checkboxs state by setting its Value property to one of the following:
0Unchecked 1Checked 2Grayed

Heres

an example; In this case, we check a checkbox, Check1, from code:


Private Sub Command1_Click() Check1.Value = 1 End Sub

can use frame control to group option buttons together. Just draw a frame for each group of option buttons we want on a form and add the option buttons to the frames. Each frame of option buttons will act as its own group, and the user can select one option button in either group.
We

can check if an option button is selected or not with the Value property. Unlike checkboxes, which have three settings for the Value property (corresponding to checked, not checked, and grayed), option buttons Value property only has two settings: True if the button is selected, and False if not.
You

add an image to a button by connecting an image (as from an image file) to its Picture property. When were working with checkboxes and option buttons, we should also set the buttons DownPicture property to specify what image it should display when selected. Graphical checkboxes and option buttons look like image-bearing command buttons, not standard checkboxes and option buttons. The only way we tell them apart from command buttons when the program runs is that checkboxes and option buttons, when clicked, stay clicked
We

After

this we must also set the STYLE property of the option button to True

Using

frames we can also use both check boxes and option boxes together For example

You might also like