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

Lecture 4 - Notes

Uploaded by

allwyn2ebenezer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Lecture 4 - Notes

Uploaded by

allwyn2ebenezer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Explain the Form Methods. (OR) List the Form Methods.

Form Methods:
Form methods that are used in code to control their behavior. Visual Basic supports many methods to change the
appearance and behavior of the form at run time. The following are the important methods of a form control.
1. Circle 2. Line 3. Cls 4. PSet 5. Point 6. PaintPicture
7. Move 8. PrintForm 9. Show 10. Hide 11. SetFocus
1. Circle Method
Draws a circle, ellipse, or arc on an object.
Syntax
object.Circle [Step] (x, y), radius, [color, start, end, aspect]
Example:
Private Sub Command1_Click()
Form1.Circle (2000, 1400), 1000, vbRed
Form1.Circle (2000, 3000), 1000, vbGreen, 0.9, 2.2
End Sub
2. Line Method
Draws lines and rectangles on an object.
Syntax
object.Line [Step] (x1, y1) [Step] - (x2, y2), [color], [B][F]
Example:
Private Sub Command1_Click()
Form1.Line (1000, 1000)-(2000, 2000)
Form1.Line (1000, 1000)-(2000, 2000), vbBlue, B
Form1.Line (3000, 1000)-(4000, 3000), vbRed, BF
End Sub
3. Cls Method
Clears graphics and text generated at run time from a Form or PictureBox.
Syntax
object.Cls
Example:
Private Sub Command1_Click()
Form1.Line (1000, 1000)-(2000, 1500), vbRed, BF
End Sub
Private Sub Command2_Click()
Form1.Cls
End Sub
4. PSet Method
Sets a point on an object to a specified color.
Syntax
object.PSet [Step] (x, y), [color]
Example:
Private Sub Command1_Click()
Form1.PSet (1900, 1800), vbRed
Dim i As Integer
For i = 1 To 1000
Form1.PSet (2000 + i, 2000), vbGreen
Next
End Sub
5. Point Method
Returns, as a long integer, the red-green-blue (RGB) color of the specified point on a Form or Picture
Box. Doesn't support named arguments.
Syntax
object.Point(x, y)
Example:
Private Sub Command1_Click()
Form1.Line (1000, 1000)-(2000, 1500), vbRed, BF
MsgBox Form1.Point(1200, 1200)
End Sub
6. PaintPicture Method
Draws the contents of a graphics file (.bmp, .wmf, .emf, .cur, .ico, or .dib) on a Form, PictureBox, or Printer.
Doesn't support named arguments.
Syntax object.PaintPicture picture, x1, y1, width1, height1, x2, y2, width2, height2, opcode
Example:
Private Sub Command1_Click()
Form1.PaintPicture Form1.Picture, 1000, 2000, 1500, 2000, 5000, 4000, 2000, 3000
End Sub
Private Sub Form_Load()
Form1.Picture = LoadPicture("C:\WINDOWS\SYSTEM\OOBE\IMAGES\BGMC.JPG")
End Sub
7. Move Method
Moves an MDIForm, Form, or control. Doesn't support named arguments.
Syntax object.Move left, top, width, height
Example:
Private Sub Command1_Click()
Command1.Move 1000, 2000, 3500, 2500
End Sub
8. PrintForm Method
Sends a bit-by-bit image of a Form object to the printer.
Syntax object.PrintForm
The object placeholder represents an object expression that evaluates to an object in the Applies To list. If
object is omitted, the Form with the focus is assumed to be object.
PrintForm prints all visible objects and bitmaps of the Form object. PrintForm also prints graphics added to a
Form object or PictureBox control at run time if the AutoRedraw property is True when the graphics are drawn. The
printer used by PrintForm is determined by the operating system's Control Panel settings.
Example:
Private Sub Command1_Click()
Form1.PrintForm
End Sub
9. Show Method
Displays an MDIForm or Form object. Doesn't support named arguments.
Syntax object.Show style, ownerform
Example:
Private Sub Command1_Click()
Form1.Hide
Form2.Show
End Sub
10. Hide Method
Hides an MDIForm or Form object but doesn't unload it.
Syntax object.Hide
Example:
Private Sub Command1_Click()
Form1.Hide
End Sub
11. SetFocus Method
Moves the focus to the specified control or form.
Syntax object.SetFocus
Example:
Private Sub Command1_Click()
Form1.PrintForm
End Sub
Explain in detail Form Events. (OR) List the Form Events.
Form Events:
1. Initialize 2. Activate 3. Load
4. Deactivate 5. Unload 6. Terminate
1. Initialize Event:
As the name suggests, all the variables associated with this form are initialized.
2. Activate Event:
This event occurs when the form gets user input. This event also occurs when the show method or set focus
method of the form is called.
3. Load Event:
During the load event, the form with all its properties and variables is loaded in memory. The load event occurs
whenever the "Show" method is executed or a form property is referenced.
4. Deactivate Event:
This event occurs when an another form gets the focus.
5. Unload Event:
When the user closes the form, the form is closed from the memory. Another event called the Query Unloaded
event occurs before the unload event fired. The query unload event allows the option to abort the unload event.
6. Terminate Event:
All the memory that was held for the form variable is released
Example Program for Form Events:
1. Open the new project window.
2. Add Form2 to the new project through Project→ Add Form
3. Add command button control to form1.
4. Type the following code to the Form1
How will you place a control to the form? (OR) What are the two ways of placing a control into the form?
Working with a Control:
We can place a control to the form in two ways
1. Double click the control on the toolbox.
2. Select the control, come to the form window drag and drop the control.
After placing the control into the form, the properties of the control are changed by using the properties window

How will you change the size of the control?


Changing the Size of the Control:
1. Through Properties Window (Use Top, Left, Height and Width properties)
2. Manually change the sizes of a control.
3. The two sizing handles on the horizontal edges are used to increase or decrease the width of the
control.
4. The two sizing handles on the vertical edges are used to increase or decrease the height of the
control.
How will you move the control over the form?
Moving a control:
To move a control to another location, click on the control hold down the left mouse button and drag
the control to a location of your choice.

Write about Code window. (OR) Explain about working with code window. (OR) What are the ways are
used to open the code window.
Opening the Code Window:
There are several options are used to open the code window.
i) Select the control, press the right mouse button, pop-up menu will appear, choose the view code
option.
(Or)
Press F7, after selecting the control.
(Or)
Click on View in the Menu bar, and then click the View Code option.
(Or)
Use the View Code icon on the Project Explorer window.
(Or)
Directly double click the control.
Explain Code Window.
Anatomy of the Code Window:
The title bar of the code window contains the name of the Project and Form name. Next there are two combo boxes.
One holds the text “Form” and the other holds the text “Load”.

This means that form is the name of the object and load is the event that you want to write the code for. Click the down arrow
button and the Drop Down list box will display all the controls that have been placed in the form.
If you intend to write the Command1, then select it from the list by clicking on it. Now click on the Down arrow button on
the other Drop down control. This will list all the events related to the selected object. The lines given below provide a
framework within which you can enter the code.
Private Sub Command1_Click()

End Sub
The Private means that the variables declared and the code used here can be used only by this function. Then we have the
word Sub. This is short for Sub-routine or Function. Command1_Click() is the name of the function which is self explanatory.
End Sub means end of this subroutine

You might also like