Download presentation
Presentation is loading. Please wait.
1
Visual Basic Objects Controls
Chapter 3.1 12/2/2018 Prepared by: Deborah Becker
2
Prepared by: Deborah Becker
Managing Controls Common Control Properties The most common tools in the tool box Accelerator Keys and Focus Event procedures 12/2/2018 Prepared by: Deborah Becker
3
Prepared by: Deborah Becker
Studying Controls Types of controls Intrinsic Controls ActiveX Controls Insertable Controls Intrinsic controls are those controls that appear in the tool box when you first fire Visual Basic 6 from the program menu. ActiveX Controls contain a file extension of (.OCX) and are external controls that you can add to the tool box window. *Remember that there are no scroll bars on the tool box window. The tools available will extend the tool box beyond the open screen window, and only those tools that you can see are available. Hidden tools are not accessible. Insertable Controls are controls made from external applications like Microsoft Excel and Word. We access ActiveX controls and insertable controls by clicking ProjectsComponentsInsertable from the main menu During lectures and discussions I will from time to time give you the access thread to controls and VB features by indicating the Menu and submenu layers in the same manner, Menu optionsubmenu optionTab or component. These access threads make good test questions. 12/2/2018 Prepared by: Deborah Becker
4
Prepared by: Deborah Becker
Intrinsic Controls Intrinsic controls are the most common controls and the ones that we will use during this class. We will only discuss the first 10 controls during class lecture but you are welcome to experiment with the other controls during the coding of your program assignments. Shapes, Line and Image controls make the appearance of User interfaces more professional looking. 12/2/2018 Prepared by: Deborah Becker
5
Prepared by: Deborah Becker
Common Properties Caption & (name) Alignment BackColor & ForeColor BorderStyle Enable Font Left, Top, Height & Width ToolTipText & MousePointer Alignment determines position of text in labels and on control boxes options are Left and right justified, and centered. These effect the appearance of the caption and text content of labels. BackColor and ForeColor change the appears of controls. The Down-Arrow that appears when you click on this property tell you that there are several options. Clicking the arrow brings up two tab folders containing the palette of colors and the system defaults that are available. Both of these properties work primarily the same. 12/2/2018 Prepared by: Deborah Becker
6
Prepared by: Deborah Becker
Caption, Name, Enable Captions—are used to display text on controls Name—specifies the name of the control and are used when altering properties during run time. Enable—determines the action of the control Caption and name Caption list the text displayed on the control. Name specifies the name of the control and will be used when your write basic code procedures that affect the appearance of your forms. In the alphabetical listing name appear in parenthesis so that it will appear first in the property box. Enable can be set to either true of false using the drop down menu. Setting enable to false means that when the user click on the control it will not respond. True means that it will respond to user clicks. This feature may mean more to you when we actually begin generating user applications. 12/2/2018 Prepared by: Deborah Becker
7
Left, Top, Twips (1440 per inch)
Left—indicates the starting Twip from the left edge of the form or window. Top—indicates the starting twip from the top of the form or window Font is the same as other Microsoft products. It allows you to set the size and appearance of text either on the control or in text boxes on the form. Left, Top, Height & Width A twip is the measurement used to indicate the position of a form on the screen or a control on a form. --Two measurement areas on the right side of the tool bar, the first is activated when you click on a control during design phase, and the second indicates the location of the form within the window. Left—for a control indicated the starting twip from the left edge of the form for the form it indicated the number of twips from the edge of the screen 12/2/2018 Prepared by: Deborah Becker
8
Height, Width, TooltipText & MousePointer
Height & Width determine the actual size of the object or tool (twips) ToolTipText—is used for additional instructions MousePointer—change the appearance of the mouse as it passes over the control Top—for a control indicates the starting twip from the top of the form for the form itself it indicated its twip position from the top of the screen. --The left number indicated the position from the left edge and the right number tell you your position from the top edge. Both position indicators work the same for the control and the form. Height and Width are measurement for controls. The indicate the side of the control. Tool Tip Text and Mouse pointer both activate when the mouse passes over the control. By typing in instruction in the tool tip box you are able to give users help and instructions with out cluttering up the form or control with text. 12/2/2018 Prepared by: Deborah Becker
9
Prepared by: Deborah Becker
Default Properties Default values are assigned, as controls are inserted into the form Most objects have key properties Some properties can only be set with Basic code Mouse pointer determines the shape of the mouse pointer when it passes over the control at run time Remember that properties have defaults values assigned when you place a control on your form. You will not want to change all properties and may never used some of the properties, but some Properties will be used extensively when coding your applications. Properties can also be modified with visual basic commands during coding. We use let statement or assign statements to change the properties of control during run time. We saw some of these during our example form in our lecture from Chapter 1. We can set the size and placement of the form in the coding window by placing the following statement in the Form_Load event in the coding window. frmMyfrist.Left = (Screen.Width - frmMyfrist.Width) / 2 frmMyfrist.Top = (Screen.Width - frmMyfrist.Height) / 2 Some properties must be set with visual basic code The name property may not be set with a let statement and must be set during design time through the property window. 12/2/2018 Prepared by: Deborah Becker
10
Prepared by: Deborah Becker
Form Key Properties BorderStyle decides whether you will allow the user to resize the form ContolBox Can have a value of true or False and controls whether you Will allow the user to have Access to the Control Menu. Control box– is the menu that appears when you click a window’s icon in the upper-left corner of the window. If you set this property to false then you the programmer control the entering and exit of the program. Other property features that might be useful are MaxButton and MinButton – determines whether the form will appear with the _ and Maximum buttons in the righthand upper corner of the form. Moveable – determines whether the user can move the form around on the window or if the form is stationary ShowInTaskbar – determines if the program will appear in the taskbar StartUpPosition – determines where the form appears on the screen when the application is fired. The most common use of this is 2-CetersScreen which places the form in the center of the screen. WindowState – indicated whether the form is maximized or minimized when the program is launched. 12/2/2018 Prepared by: Deborah Becker
11
Setting the Forms Location
Drag the image of the form in the Form Layout Window Change the Form’s StartupPosition property Or we can use the example on the board to change the forms startupPosition Another way to change the location of the from is to change the StartupPosition property in the property window. There are always at least three ways to accomplish every task. During lectures I will try to point out alternate ways of accomplishing tasks during lecture. 12/2/2018 Prepared by: Deborah Becker
12
Prepared by: Deborah Becker
Label Control Mrs. Becker Used to Display text on the screen User Prompts Key Properties AutoSize – if set to true the label expands across the form to display all the word typed into the caption property WordWrap – If set to true VB keeps the width the same but expands the label vertically to accommodate all the text typed in the caption. Object Focus - the placement of the cursor For wordwrap to work properly you must also set AutoSize to true. Focus is indicated in several ways and shows the user where the mouse cursor is active in the screen at any given time. Labels do not normally have the cursor focus. They may be used as input objects and then they will be able to have the focus. The cursor appears as a Line in the Textbox object. The cursor appears as an outline on a command button. Other object may appear darker or sunken when they have the cursor focus. 12/2/2018 Prepared by: Deborah Becker
13
Prepared by: Deborah Becker
Text Box Used when you want users to type information into your form. Programmers often set a default value Properties most often used Alignment, Locked, MaxLength, Multiline, PasswordChar, and ScrollBars Alignment – used to control how data is display in the text box. Alphabetic data is usually left justified, while numeric data is normally right justified. Locked – determines whether the control can be edited during runtime. MaxLength – returns/set the maximum number of characters the the user can enter into the control. returns means that I can use an assign statement to display the value of this property at run time. Multiline – returns/set the value that determines if the control can accept multiple lines of text from the user. PasswordChar – will cause the program to display the password character as the user enters text instead of the text entered. This is most commonly an asterisk. Scrollbars – usually set to true when multiline us set to true to allow the user to scroll up or down, or from side to side in the text entered into the textbox control You can always find out what effect a control property will have by placing the mouse at that property in the property window. An explanation of the property will appear below the property box window. 12/2/2018 Prepared by: Deborah Becker
14
Command Buttons Key Properties
Cancel—can be set to enable the KEY to activate the control Caption—is used to type words on the control The underlined X is entered by placing a & before the X in the caption It means that the control can be activate by pressing “Alt-X”. Default, Picture, Style ESC Acceleration keys can be set by placing an ampersand character before the letter you wish to use as an acceleration key. These allow the user quicker access to the control without using the mouse. Default – if set to true the user can trigger the command button by pressing ENTER 1—ONLY ONE COMMAND BUTTON DEFAULT CAN BE SET TO TRUE. IF YOU SET MORE THEN ONE COMMAND BUTTON’S DEFAULT PROPERTY TO TRUE, vb RESETS ALL BUT THE LAST ONE TO FALSE. Picture—you can place a picture on the command button using this property. Style—determines if the command button display the text caption or the picture If set to Zero it displays text If its set to 1 it displays the picture. Remember to set both properties if you intend to use a picture on a command button. Command buttons are used to call other forms, and execute specific procedures within the VB program. Exit Program 12/2/2018 Prepared by: Deborah Becker
15
Prepared by: Deborah Becker
Remember ... Default only one control per form You can set cancel to true for only one control per form Accelerator keys are indicated by the underlined letter on a control and are always activated by Alt+? Focus—only one control can have the focus at a time Accelerator keys make the program more user friendly 12/2/2018 Prepared by: Deborah Becker
16
Prepared by: Deborah Becker
Frames A container for other controls Used for option buttons or check boxes Default name: Frame1, Frame2 Naming Convention Prefix: fra, e.g., fraMeaningfulName Examples: fraColor, fraStyle Key Property: Caption property default is default name (appears on top left border of frame) Frames appear as a box on a form. They divide the plane (surface area) of the form into separate areas. You place other objects into a frame you may not drag objects already placed on a form into a frame you must create the object inside the frame. Setting the caption property for a frame allows you to display a meaningful purpose for the frame to the user. 12/2/2018 Prepared by: Deborah Becker
17
Prepared by: Deborah Becker
Images and Pictures Holds a picture (bmp, wmf, ico, gif, jpg, etc.) Default name: Image1, Image2 Naming Convention: imgMeaningfulName Examples: imgBigIcon, imgSmallIcon Key Properties: Picture property – use Load Picture dialog box to load the graphic image Stretch property – default: False - Change to True to make the picture enlarge to fill the control Visible property default: True - False hides the image A Picture control is often used to display output to the screen. We will use picture boxes to display the results of our programs to the screen. This save the forest for future generations and allows for more efficient debugging sessions. The image object is used most often to display an Icon, Logo or picture to the screen It contains a stretch property that allows the image to fill the entire control. The picture control does not have a stretch property, you must determine the size of the picture box control on the screen by setting the Height and Width properties or manually stretching the control to the desired size during design time. 12/2/2018 Prepared by: Deborah Becker
18
Prepared by: Deborah Becker
Other Controls Boarder and Style The appearance of the control may be flat or three-dimensional Shape Places a shape on the form Line Allow lines to be added on the form 12/2/2018 Prepared by: Deborah Becker
19
Prepared by: Deborah Becker
Tab Order and Focus Events are caused in several ways Clicking on the control to shift the focus Pressing the tab key to shift the focus to the next control Setting a default control Setting a control cancel property to true Tab order is set by Setting the TabStop property to true Assigning the TabIndex property a(0,1,2,) When you set the tab stop property to true the cursor will stop there when the form is running. Setting this property to false means that the cursor will skip the control when the user presses the tab key. The tabIndex determines the order of the cursor when the tab key is pressed at run time. 12/2/2018 Prepared by: Deborah Becker
20
Coding for the Controls
Clearing TextBoxes and Labels txtName.Text = “” lblName.Caption = “” Resetting the Focus txtName.SetFocus textName.setfocus is a VB statement the components of this statement are ObjectName separated by a Period and then the Method Name. Remember a method is like a verb it tell the object to perform some action. Here we are telling the Textbox to capture the cursor focus. 12/2/2018 Prepared by: Deborah Becker
21
Prepared by: Deborah Becker
Coding for Controls Changing Fonts txtName.Font.Bold = true lblMessage.Font.Size = 12 Changing Color of Text ForeColor is the color of the text BackColor is the color around the text Color Constants vbBlack, vbGreen, vbRed, txtName.ForeColor = vbRed The font property has sub properties that can be set. This is indicated by the to the left of the property. You may separate sub properties with a period or simply indicate the name of the sub property. Like textName.FontSize = 12 Good programming form is to separate the components of the property but you will see this both ways in industry code. 12/2/2018 Prepared by: Deborah Becker
22
Changing Multiple Properties
With…End With statements With txtName .ForeColor = vbBlack .Font.Bold = True .Setfocus End With Concatenating Text lblName.Caption = “Your Name: “&txtName The with block is a powerful VB multistatement block. It begins with the Width key word and is followed by the object name. Inside the block properties and methods are indicated by placing a period and then the property name and the assignment or the method. Methods do not have assignments they are verbs or commands. You may want to enter text and control names together in a label for the user this is done through concatenation the components with the &, The & has two function in VB, indication of accelerator keys and Concatenation 12/2/2018 Prepared by: Deborah Becker
23
Prepared by: Deborah Becker
The Property Assumed TextBox: Text Label: Caption Command button: Caption Frame: Caption Default properties are assumed during coding and may be left out of assign statements. Text1 = “Todays Date” Label1 = “My Name” 12/2/2018 Prepared by: Deborah Becker
24
Prepared by: Deborah Becker
Good Bye That’s all Folks!!!! 12/2/2018 Prepared by: Deborah Becker
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.