Namespaces - PowerPoint PPT Presentation

1 / 29
About This Presentation
Title:

Namespaces

Description:

Namespaces. Namespaces are file cabinets for classes, similar to the concept of folders. Namespaces can contain classes, other namespaces, etc. ... – PowerPoint PPT presentation

Number of Views:84
Avg rating:3.0/5.0
Slides: 30
Provided by: pcC5
Category:

less

Transcript and Presenter's Notes

Title: Namespaces


1
Namespaces
  • Namespaces are file cabinets for classes, similar
    to the concept of folders.
  • Namespaces can contain classes, other namespaces,
    etc.
  • Namespaces help organize the vast number of
    classes into a neat structure.
  • To make use of a class, we need to reference or
    import the namespace that contains the class.

2
Namespaces
  • System.Diagnostics.Process.Start("www.money.com")

Namespace
Class
If System.Diagnostics has already been referenced
in our project, we can omit it in our code, such
that Process.Start("www.money.com")

3
Learning Objectives
  • Form basic concept
  • Structure of form
  • Instantiation of forms
  • Form events load and activated
  • Show vs. ShowDialog method
  • Messagebox an example of dialog boxes

4
Structure of Form
Maximize button
Minimize button
Text property
Control box
Close button
Title bar
MinimizeButton, MaximizeButton, ControlBox can be
set to false for removal from the form.
Removal of controlbox removes 3 other boxes as
well.
5
  • BorderStyle Property

WindowState Property Normal, Maximized,
Minimized Opacity Property specify form
transparency
6
Form Basic Concept
System.Windows.Forms.Form
IS-A-Kind of relationship
Form1
Instance-of relationship
Form1copy1
Form1copy2
7
Form Instantiation
The system automatically creates an instance of
it at runtime.
Form1
An instance of Form1 is created by the system
8
Form Show Hide
From form1
Private Sub Button1_Click() Handles
Button1.Click form2.Show()
Me.Hide() me refers to form1 End Sub
From form2
Private Sub Button1_Click() Handles
Button1.Click Me.Close()
form1.Show() End Sub
9
The Show Method
  • makes a form visible
  • triggers two events
  • - the form load event (load the form into
    primary
  • storage), only if form is not yet in
    memory
  • - the activated event (makes the form
    active)
  • e.g.,
  • form2.show modeless style

10
The Hide method
  • makes a form invisible without unloading it
  • e.g.,
  • summaryForm.hide

11
Form Events
  • the form load event
  • the form activated event
  • these events can be used to
  • initialize variable values or control
  • properties

12
start-up
form1 loaded form1 activated
form1
form1.hide deactivated even without hiding
it form2.show
form1 deactivated form2 loaded form2 activated
form 2
form2.close form1.show
form1 loaded once, activated twice
form2 closed form1 activated
form 1
13
Form Events
  • Load
  • Activated
  • Paint form redrawn, resized, moved
  • Deactivate form no longer the active form
  • FormClosing form about to close
  • FormClosed after form is closed

14
Choose the Start-up Form
15
The ShowDialog Method
  • e.g.,
  • form1.ShowDialog
  • makes form1 a dialog box (modal form), which has
    to be responded to by the user. Other forms
    become un-accessible before form1closes.

16
Dialog Box Example
Form1
Form2
A dialog box
17
DialogResult enumeration
  • DialogResult is a property of form, public in
    scope.
  • Values of DialogResult
  • DiaglogResult.Abort
  • DiaglogResult.Cancel
  • DiaglogResult.No
  • DiaglogResult.Yes
  • DiaglogResult.OK
  • DiaglogResult.Retry

18
On Form1 Private Sub Button1_Click() Handles
Button1.Click form2.ShowDialog()
program suspended waiting for user
response to form2 If form2.DialogResult
DialogResult.OK Then Label1.Text
"OK" Else Label1.Text
"Cancel" End If End Sub
19
Form2
Private Sub OK_Click() Handles Button1.Click
DialogResult DialogResult.OK End
Sub Private Sub Cancel_Click() Handles
Button2.Click DialogResult
DialogResult.Cancel End Sub
Assigning value to DialogResult closes the dialog
box.
20
Program flow show vs. showdialog
form2.show Line 3 Line 4
form2.showdialog Line 3 Line 4
Line 3, Line 4 continue to execute after
form.Show
Line 3, Line 4 suspended until form2 is closed.
21
Getting results from MessageBoxes
  • MessageBox.Show() show is function that
    returns a
  • value of DialogResult type, i. e., one of the
    following
  • DialogResult.Abort
  • DialogResult.Cancel
  • DialogResult.No
  • DialogResult.Yes
  • DialogResult.OK
  • DialogResult.Retry
  • MessageBox.Show behaves like ShowDialog method

22
Getting results from MessageBoxes
23
Private Sub Button1_Click() Handles
Button1.Click Dim dResult As
DialogResult dResult
MessageBox.Show("Would you marry me?", "Please
let me know", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) If dResult
DialogResult.Yes Then Label1.Text
"She said Yes!" Else
Label1.Text "I am heart-broken. She said No!"
End If End Sub
24
(No Transcript)
25
Private Sub Button2_Click() Handles
Button2.Click Select Case
MessageBox.Show("Yes or NO", "Make a selection",
MessageBoxButtons.YesNo, MessageBoxIcon.Question)
Case DialogResult.Yes
Label1.Text "User selects yes!"
Case DialogResult.No Label1.Text
"User selects no!" End Select End
Sub
26
Coordinate systems of VB
  • units of measurement pixels (monitor
    resolution)
  • left (the distance between left edge of a
    control from its
  • container)
  • top (the distance between top edge of a control
    from its
  • container)
  • Forms and groupboxes are containers.

27
top
left
top
left
This is a groupbox.
28
Form's Screen Location
  • StartPosition Property
  • CenterScreen
  • WindowsDefaultLocation
  • Write code to set position
  • e.g.,
  • me.left 150 unit in pixels
  • me.top 200

29
Screen
top
left
Form
Write a Comment
User Comments (0)
About PowerShow.com