Vous êtes sur la page 1sur 30

Chapter 1

Visual Studio.NET
Advanced Programming Using
Visual Basic.NET
2003 by The McGraw-Hill Companies, Inc. All rights reserved.
2
.NET
MS .NET Framework SDK
Visual Studio Integrated Development
Environment
3
The .NET Framework
A platform for developing and running
applications and XML Web services
Framework components
Common language runtime
Class libraries
ASP.NET
4
Common Language Runtime
(CLR)
Manages execution of code
managed code (code compiled to run in the CLR)
Metadata
Portable executable (PE)
Integrates components developed in different
languages
Handles errors across languages
Handles security
Manages storage and destruction of objects
managed data

5
Managed data
CLR manages data storage
CLR garbage collector removes objects no
longer in use
6
Managed code and Metadata
Code compiled to
run in the CLR
Data that describe data
(METADATA)
Portable executable (PE)
file

data types
members
references

7
Class Library
Stores all classes and interfaces of the
.NET language
Namespaces sections within the
library that contain classes, structures,
enumerations, delegates, interfaces
See Table 1.1
8
Common Language Specification
(CLS)
Published standards that specify how a
language that interacts with the CLR
should behave.
Programs should be CLS-compliant
. Note that all VB programs that you write using the VS IDE
will be CLS compliant automatically.
9
Class Library - Types
Refer to classes, structures,
enumerations, delegates, interfaces, data
types
Any element used in the As clause
Dim AnyName As SomeType
Value types 2 memory locations
intSecondValue = intFirstValue
Reference types same memory location
10
Steps to Compile Programs




PE = *.exe
*.dll
11
Assemblies
Basic units of code
A single PE file or multiple files
The assembly manifest
Metadata about the version
Table describing files needed
Assembly reference list of external files needed
***

Only needed assemblies are loaded into
memory at execution time
Assemblies are reference objects

Reference objects connect Visual
Basic projects to external components
12
Attributes
Tags containing information about parts of
a program
Part of the metadata in a .NET assembly
Reflection examining the metadata in an
assemblys attributes
System.Reflection class

13
References Objects
Assemblies (also called project-to-project
reference)
Reference to another project
COM Objects
Reference to components written in earlier
versions of VB
Non-CLS components
14
ASP.NET
The newest version of Active Server
Pages (ASP)
A Web development environment that
compiles applications written in .NET
compatible languages
Uses CLR and managed code features
15
Solution Explorer Files
bin folder
stores clean
compiles
compiled .exe
debugging info
Visual Studio .NET
16
Solution Explorer Files
Visual Studio .NET
System libraries
(DLLs) available
To this solution
.resx filename
must match form
filename
17
Solution Explorer Files
Visual Studio .NET
AssemblyInfo.vb
contains information
about your application
18
Displaying an applications
attributes
Right-click on
filename
Choose Properties

(XP) Pause over the
filename
19
Retrieving Attributes pg 10
Import the System.Reflection namespace
Declare an Assembly object
Dim asmInfo As [Assembly]
Dim objAttributes as Object
Dim atrProduct as
AssembyProductAttribute
Retrieve Assembly information
asmInfo = [Assembly].Load(ProjectName)
objAttributes = asmInfo.GetCustomAttributes(False)
atrProduct =
Ctype(ObjectAssemby(n),AssemblyProductAttribute)
20
Deploying Applications
Target computer must have .NET
Framework or .NET Framework
Redistributable (dotnetfx.exe)
Deployment methods
XCopy deployment copy necessary files to
the target machine
Windows Installer technology application
ships with Windows

21
Helpful Hints for .NET
Set a default font for your form
Set Font property at design time
Run time
Me.Font = New Font(Arial, 14, FontSytle.Underline)
Predetermine minimum and maximum form size
Me.MinimumSize = New Size(200,200)
Me.MaximumSize = New Size(500,500)
Avoid use of VB6 compatibility library
22
MDI
To create a parent form, set
IsMdiContainer property to True
To create a child form, set MdiParent
property to the parent form
Dim frmChildOne As New frmChildOne()
frmChildOne.MdiParent = Me
frmChildOne.Show()
23
MDI
Projects can contain
Multiple parent forms
Multiple child form
Independent forms (the splash screen)
When you close a parent form, all of its
children close
A child cannot wander out of its parents
area
24
The Window Menu
Create a Window menu for parent forms
List open child windows
mnuWindows.MdiList = True
Allow users to arrange child windows
Window Layout Options
Me.LayoutMdi(MdiLayout.TileVertical)
Me.LayoutMdi(MdiLayout.TileHorizontal)
Me.LayoutMdi(MdiLayout.Cascade)

25
Redisplaying Child Windows

Determine if form already exists
Dim frmTest As Form
Dim blnFound As Boolean = False

Does form already exist?
For Each frmTest In Me.MdiChildren
With frmTest
If .Name = frmSummary Then
.Activate() Activate previous instance
blnFound = True
End If
End With
Next
If Not blnFound Then
Dim frmSummaryInstance As New frmSummary()
With frmSummaryInstance
.MdiParent = Me
.Show()
End With
End If
26
Image Lists
Use an ImageList component to store the
images for toolbars and other controls
Use the ils prefix
To add images to the ImageList
Select Images collection Build button from the
Properties window
Use the Add button in the Image Collection Editor to
add each image to the collection
Images stored in common7 folder of VS root
27
Toolbars
Use the toolbar in the toolbox to create a
toolbar object
Add buttons with a Buttons collection in the
Properties window
Use the tlb prefix to name the object
In Toolbar Button Click Event
SELECT Case tlbMain.Buttons.IndexOf(e.Button)

28
Status Bars
Add a StatusBar control to your form
Add StatusBarPanel objects to the status
bar
Use the sbr prefix to name the object
Set the ShowPanels property to True
sbrParent.Panels(0).Text = Now.ToShortDateString
29
Context Menus
Also called shortcut or popup menus
Use the regular menu designer to create a
menu
Assign the top-level menu name to the
ContextMenu property of the form and/or
controls on the form
30
Demo Time

Vous aimerez peut-être aussi