Itc2301 P2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

ITC2301

VISUAL BASIC WORKSHOP

PART TWO
 VB.NET IDE
 VB.NET objects
 Writing VB.NET code
◦ Toolbox window
 contains set of controls which make up a VB
application.
◦ Windows Form designer window
 central part of VB. It provides the display area for
the application acts as a container for all the
controls
◦ Properties window
 Each object in VB has a set of characteristics called
properties. This window contains the properties
that control the object’s appearance and behaviour.
 Object box, Properties list, Description pane,
settings box
◦ Main window
 At top of screen. Contains
 title bar:
 menu bar: displays commands used to build VB application
 standard tool bar: quick access to commonly used menu commands
 form, label, picturebox, button
 demonstration
◦ Adding a control to a form
◦ sizing, moving and deleting a control
◦ setting properties of a control at design time
◦ changing properties for more than one control
Name – uniquely identifies the object in the program
Text– the caption of a button, contents of a text
box or label, the title of a form
Size.Height and Size.Width – the width and height of
the object (dimension in pixels)
Visible – Whether the object should be shown
Font – the face, style, and size of an objects font
BackColor, ForeColor – color of background or
foreground
EachVB.NET Graphical Object has an extensive list
of properties which can be individually set.
Qualities or attributes of an object/graphic-control
Can be changed by programmer
◦ design time – in the ‘properties’ box.

Can be changed by user


◦ run time – e.g. typing into a text box

Dynamically (in code):


ObjectName.PropertyName = Value
◦ TextBox1.Text = “Hello World”
◦ TextBox1.ForeColor = Color.Blue
Properties Window
◦Click object with mouse – updates RHS
panel
◦If not visible, press ‘F4’
Code associated with an event
◦Typed in the code-window
◦e.g. Text1.Visible = True
◦e.g. Button1.Enabled = False
 used as a backdrop for other controls
◦ useful properties include:
 Name naming convention = frmSomething
 Text the text inside the title bar of the form
 BackColor no need to type code, just click on three dots
then choose a coloured box
 BackgroundImage used to display a graphic as a background
 Font sets font style, bold, italics, underline etc
 Startpostition determines where the windows form object is
positioned when it first appears on the
screen
 Size used to set the ht and width of the form on the
screen (measured in twips (1400 twips ~ 1
inch)
 Purpose of label control is to display text
 naming convention = lblSomething
◦ useful properties include:
 FlatStyle 3d or flat
 BackColor colour of background of label
 ForeColour colour of text within label
 Borderstyle none or fixed single (box around text)
 Text the text on the label
 Font appearance as applied to the text
 Size set label’s height and width
 Position set labels x and y co ords on the form
 AutoSize True or False (True enables label to
expand with text)
Used to hold an image
naming convention = picBoxSomething
◦ useful properties include:
 image used to select an image to place inside
the picBox control (click on three
dots to open an existing image)
 SizeMode set whether the chosen picture fills
the entire space of the image control
 Size used to set the size of the image
 Location used to set the positioning of the image
 Used to get input such as text from the user
 naming convention: txtSomething
◦ useful properties include:
 BorderStyle - Can have a box around text
 Enabled - True or False (False means user cannot enter text into
text box)
 Font - same as before
 Size, Location. - same as before
 MultiLine - True or False (True lets user hit return and keep
typing)
 ScrollBars - none, vertical, horizontal or both (requires MultiLine to
be True)
 Text - displays initial (default) text in text box; used to lighten
burden on user
◦ Always add a label next to a text box to guide the
user in their input.
 used to allow user to initiate some coded
behaviour
 naming convention= cmdSomething
◦ useful properties include:
 Text - the text on the button
 Font - font appearance as applied to the
Caption
 Size - used to set the size of the button on the
screen
 Location - used to set the positioning of the
button on the screen
 Enabled - True or False
 Reduce the use of the mouse, so
enable speed for user input
 Add an ampersand (&) in front of
access key letter in the caption
◦ ie.
E&xit as the caption on a command button
lets the user select the button by hitting
Alt plus x simultaneously
 Important for user friendliness
 Example of objects
◦ Form, pictureBox, label, command buttons
 Example of events (user actions)
◦ click, double click, scroll, keypress
 Event procedure (method)
◦ VB.NET instruction, or code that tells an object
how to respond to an event
 To run an application
◦ Click Debug then click start or press F5
◦ Visual Studio .NET creates an executeable
file(.exe) that can be run outside the IDE

◦ Demo:
 Lets run our application. What happens?
 Programming involves understanding the Syntax and
Semantics of a particular programming language, to
form Statements that tell the computer what to do.
 Statement
◦ An instruction to the computer (specifically, for the
compiler)
 Syntax
◦ The rules for constructing valid statements
 Semantics
◦ The meaning or interpretation of a statement
 Statements are organised into a source-code file
 The source code file is divided into sections:
◦ Class definition
◦ Form Layout information
◦ Global Variables and Constants
◦ New data type
◦ Procedures and Functions
 Actions—such as clicking, double-clicking, and
scrolling—are called events
 The set of Visual Basic .NET instructions, or
code, that tells an object how to respond to an
event is called an event procedure
 You write statements inside an event procedure
to specify the individual steps required for the
input, processing and output.
 To help you follow the syntax rules of the
Visual Basic .NET programming language, the
Code Editor provides you with a code template
for every event procedure
 The first line in the Code template is called the
procedure header
 And the last line is called the procedure footer
 A keyword is a word that has a special meaning in a
programming language
 The Sub keyword is an abbreviation of the term sub
procedure, which, in programming terminology,
refers to a block of code that performs a specific task
 The Private keyword indicates that the procedure can
be used only within the class in which it is defined
 VB.NET provides Code Template for each Event Procedure
 Example:
Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub btnExit_Click(ByVal sender As


System.Object, ByVal e As
System.EventArgs) Handles btnExit.Click
Me.Close( )
End Sub
End Class

 Keywords = Private Sub, End Sub


 Object Name = btnExit
 Event = Click ()
 Me.Close( ) Method
◦ Terminates the current application
◦ The Me in the instruction refers to the current
form
◦ The Close is the method

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy