Introducing More Controls Text boxCheck box Option button Command button frame image.

27
Introducing More Controls Text box Check box Option button Command button frame image
  • date post

    20-Dec-2015
  • Category

    Documents

  • view

    230
  • download

    0

Transcript of Introducing More Controls Text boxCheck box Option button Command button frame image.

Page 1: Introducing More Controls Text boxCheck box Option button Command button frame image.

Introducing More ControlsText box Check boxOption button

Command buttonframe image

Page 2: Introducing More Controls Text boxCheck box Option button Command button frame image.

Text Boxes

Used primarily for user input• It holds the value input by the user as characters

Three letter prefix is txt Use the Text property of text boxes in program code to

assign an input value• Example: txtMessage.Text=“Enter your name here”

Alignment property changes the alignment of text but you must also set the Multiline property to True for it to be effective

• Set at design time only• 0-Left Justify;1-Right Justify;2-Center

Page 3: Introducing More Controls Text boxCheck box Option button Command button frame image.

Frames

used as containers for other controls and to group like items on a form.

Three letter prefix is fra Set the Frame Caption property to the words that you wish

to appear at the top edge of the frame

Page 4: Introducing More Controls Text boxCheck box Option button Command button frame image.

Check Boxes

allows the user to make choices any number of the boxes may be selected or deselected Three letter prefix is chk Value property is set to 0 if unchecked, 1 if checked and 2

if grey or disabled• Use the Value property in your event procedure code to

determine the user’s selections Caption property is used to specify text next to the box

Page 5: Introducing More Controls Text boxCheck box Option button Command button frame image.

Option buttons

only one can be selected Generally place several options in a frame to form a group

Create frame first, select object and use the crosshair to draw the option

Doubleclicking the control on the toolbox automatically places it on form

Once on the form, it becomes part of the form group even if you later drag it into a frame

Value Property is True if option is selected and False if not Caption property is used to specify text next to the box Three letter prefix is opt

Page 6: Introducing More Controls Text boxCheck box Option button Command button frame image.

Images

A control which will contain a graphic The control is first placed on the form and then the Picture

property provides a Load option to include the desired graphics file

• File extension of .bmp, .gif, .jpg among others Stretch property = True causes the picture to fill the

control Visible property = False causes the picture to be invisible

Page 7: Introducing More Controls Text boxCheck box Option button Command button frame image.

Setting a Border and style

The Appearance property of many controls can be set to 0 - Flat or 1 - 3D

To make a label or image 3 dimensional first provide it with a border

Page 8: Introducing More Controls Text boxCheck box Option button Command button frame image.

The Shape and Line Control the shape tool in the VB toolbox (not drawing toolbox)

provides the ability to put rectangles, squares, ovals and circles on a form Type of shape is assigned through the Shape property 0-Rectangle, 1-Square, 2-Oval, 3-Circle, 4-Rounded Rectangle, 5 -

Rounded Square 3 letter prefix is shp

Use the line tool on the VB toolbox to provide for lines on a form Change the properties for thickness and color using Borderwidth and

Color 3 letter prefix is lin

Page 9: Introducing More Controls Text boxCheck box Option button Command button frame image.

Working with Multiple Controls

You can select multiple controls and treat them as a group, including setting common properties at once, moving them, or aligning them.

The properties windows display properties common to the group after the group has been created

Page 10: Introducing More Controls Text boxCheck box Option button Command button frame image.

Combining controls into a group

To select Drag a selection box around the controls to group or/ Ctrl or Shift select each one

To deselect Click anywhere on the form not on the control

Page 11: Introducing More Controls Text boxCheck box Option button Command button frame image.

To align and resize a group of controls

Use the format option on the menu and select the Align or Make Same Size submenus

Measured in Twips – 1/1,440 of an inch • a control that that has a width of 1,440 twips is an inch wide

Page 12: Introducing More Controls Text boxCheck box Option button Command button frame image.

Standards for Designing the User Interface

Make your programs easier to use by following Windows standard guidelines for colors, control size and placement, access keys, default and cancel buttons, and tab order

Windows are primarily grey White text boxes Grey background for labels

If a message will be displayed or a calculation results – border the label

If only a caption on the screen – no border

Page 13: Introducing More Controls Text boxCheck box Option button Command button frame image.

Defining Keyboard Access Keys

Define keyboard access keys by including an ampersand in the caption of command buttons, option buttons, and check boxes etc.

• Examples: &OK for OK or E&xit for Exit Activated by depressing Alt+O or Alt+x Try to follow the Windows defaults to avoid confusion

Page 14: Introducing More Controls Text boxCheck box Option button Command button frame image.

Setting the Default and Cancel Properties of Command Buttons

Set the Default property of one command button to True user can press Enter to select this button

Set the Cancel property to True for one command button this button will be selected when the user presses the Esc key.

Page 15: Introducing More Controls Text boxCheck box Option button Command button frame image.

Setting the Focus and Tab Order for Controls

One control on a a form always has the focus Focus is a light dotted line for command buttons and option

buttons Focus is the insertion point for text boxes image controls and labels do not have a focus The focus moves from control to control as the user presses the

Tab key. The sequence for tabbing is determined by the TabIndex properties

of the controls. Assigned by VB as you begin to enter controls Starts at 0 When program begins running, focus is on control with TabIndex 0 Although labels do not have a focus…they do have a tabindex

• If you use a & in the caption of a label, the focus will move to the first TabIndex following the label when the access key is activated,

Page 16: Introducing More Controls Text boxCheck box Option button Command button frame image.

Setting the Form’s Location on the Screen

The form will appear in the upper left hand corner of the screen by default To change – drag form in Form/Layout window or/ StartupPosition Property of Form set to 0-Left, 1-Right,2-Center

Page 17: Introducing More Controls Text boxCheck box Option button Command button frame image.

Creating ToolTips

Set the ToolTipText property of a control to make a ToolTip appear when the user pauses the mouse pointer over the control.

Page 18: Introducing More Controls Text boxCheck box Option button Command button frame image.

Coding for the Controls

controls can be changed at run time by using VB code in the event procedures

Text boxes and labels can be cleared The focus can be set Option buttons and check boxes can be preset Font and colors can be changed Multiple properties of a group of controls can be set

Page 19: Introducing More Controls Text boxCheck box Option button Command button frame image.

Clearing Text Boxes and Labels

Set the property to empty string or null string defined by “”• txtName.txt =“”

• lblAddress.Caption=“”

Page 20: Introducing More Controls Text boxCheck box Option button Command button frame image.

Resetting the Focus

To reset the focus, use Object.Method Example: txtName.SetFocus

Page 21: Introducing More Controls Text boxCheck box Option button Command button frame image.

Setting the Value Property of Option Buttons and Check Boxes

To set a default value to an option button or check box, use the Value Property

• Example: chkBold.Value = 1 means box is checked

• Example: chkBold.Value = 0 box is unchecked (Remember 2 is greyed or dimmed)

• Example: optRed.Value=True means button is selected

Page 22: Introducing More Controls Text boxCheck box Option button Command button frame image.

Changing the Font Properties of Controls

To change font attributes of a text box or a label, use the Font property of the control. The Font property refers to a Font object, with properties for bold, italic, underline, size, etc. Example: txtName.Font.Bold = True Example: txtName.Font.Size = 14 Example: txtName.Font.Underline= True

Page 23: Introducing More Controls Text boxCheck box Option button Command button frame image.

Changing the Color of Text

Change the color of text in a control by changing the ForeColor property txtMessage.ForeColor = vbGreen changes the text to Green

Change the color around the text by changing the BackColor property txtMessage.BackColor = vbWhite changes the area around the

text to White Several default Visual Basic color constants

vbBlack, vbWhite, vbRed, vbGreen, vbYellow, vbBlue, vbMagenta, vbCyan

Page 24: Introducing More Controls Text boxCheck box Option button Command button frame image.

Changing Multiple Properties of a single Control during Run Time

Instead of : txtTitle.Visible=True txtTitle.Font.Bold = True txtTitle.ForeColor = vbRed txtTitle.SetFocus

Use a With block which is actually more efficient in terms of execution timeWith txtTitle

.Visible=True

.Font.Bold = True

.ForeColor = vbRed

.SetFocusEnd With

Page 25: Introducing More Controls Text boxCheck box Option button Command button frame image.

Concatenating Text

Joining two strings of text is called concatenation and is accomplished by placing & between the two elements. A space must precede and follow the & Example: lblMessage.Caption = “Your name is: “ & txtName.Text

Page 26: Introducing More Controls Text boxCheck box Option button Command button frame image.

Continuing Long Program Lines

Use a space and an underscore to continue a long statement on another line.

You may indent the next line You may not use this line continuation character in the middle

of a literal or split the name of an object or property Examples:

lblGreetings.Caption = “Greetings “ & txtName.Text & “:” & _

“You have been selected to win a free prize. “ & _

“Just send us $100 for postage and handling”

Page 27: Introducing More Controls Text boxCheck box Option button Command button frame image.

Using the Default Property of a Control

Using the default property of a control allows you to refer to an object without naming the property Example: A text box the default property is Text hence you can write

either

• txtCompany.Text = “ABC” or/

• txtCompany = “ABC”

• chkHours.Value = 1 or/

• chkHours =1 Table 2.1 in text provides a complete list