Professional Documents
Culture Documents
Vbnet
Vbnet
.NET
--
w w.pdf actory.com
w w.pdf actory.com
))
((
w w.pdf actory.com
...
...
...
w w.pdf actory.com
.NET
Visual Basic .NET
2003
- .NET Visual Basic .NET
. .
.... Microsoft(
- - 3876 :
w w.pdf actory.com
..................................................................
..................................................................
.............................................................
.................................................................
...............................................
Visual Basic 16 .....................
................................
.......................................
................................... CD-ROM
...................................
) ( .............................................
....................................................
: 1 .............................................................
: 3 .............................. Visual Basic .NET
3 ....................................................... .NET
4 .......................................... DOS
4 ....................................... Windows
7 ................................. COM
8 ...............................................
10 ..............................
10 ..................................................... .NET
11 ................................
w w.pdf actory.com
16 ...................................... JIT
17 ..................................... Assemblies
18 ............................................
24 ................................................
26 ..............................................
26 ..................................................
26 ............................................
28 ...............................................
30 ..........................................
31 .................................. ArabicConsole
32 .............................................
: 35 .....................................................
35 ......................................... Modules
)(38 ....................................... Sub Main
)(39 ........................................ Sub New
41 ....................................................
41 ......................................
43 ................................
48 .................................................
52 ....................................................
58 .......................................................
59 ................................................
59 ................................... Enum
62 ............................... Structure
67 ...................................................
69 ....................................................
70 ....................................
w w.pdf actory.com
72 ................................
81 ......................................................
82 ..........................................
84 ..........................
85 ..................... Imports
87 ................ Imports
: 89 ................................................
89 .................................................
94 ....................................................
94 .............................................. Fields
96 ........................................... Methods
116 .....................................................
116 ........................................
119 ....................................
123 ...................................................
126 ........................................
137 .............................
138 ...................................................
w w.pdf actory.com
: 147 ........................................................
147 ....................................................
147 .................................................
152 ..................................
152 .............................................
157 .........................................
174 ..............................................
174 ........................ NotInheritable
174 ............................ MustInherit
176 ......................... MustOverride
177 ....................................................
177 .........................................
181 ................................
184 ......................
: 187 .........................
187 ............................................................
190 .................................................
192 .............................................
196 .......................................
197 ............................................
w w.pdf actory.com
207 .............................................................
208 ........................................
211 .............................................
212 .............................................
214 .............................................
217 ..........................................................
225 .......................................
: 229 .............................. .NET Framework
: 231 .............................................
231 .............................................. System.Object
232 ........................................ Object
234 ..........
236 ........................................
236 .......................................................
239 .........................................
242 .............................................
w w.pdf actory.com
250 ........................................................
251 ........................................
252 ..............................................
254 ................................................ Math
256 ..........................................................
256 .......................................
: 275 ..............................................
275 ...........................................................
275 .......................................
276 ..........................................
278 ....................................................
288 ..........................................
290 ...........................................
w w.pdf actory.com
292 ...............................................
294 .................................................
296 .............................. Configurations
: 299 ............................................
299 .................................................... Directory
301 ........................................
302 ...............................
306 ...............................
309 ..................................
312 ..................................
) ( 325 ................
231 ...............................................
341 ...........................................
w w.pdf actory.com
345 ..............................
351 .......................
353 ............................................
354 ........................................
364 ..................................
368 .....................................................
369 ...............................
374 ...........................
377 .............................. Thread Synchronization
377 ............... SyncLock End SyncLock
381 .................................................
393 .......................
394 .....................................
395 ..............................
w w.pdf actory.com
400 ............................................
400 ......................................
405 ....................................
419 ............................................
419 ....................................... System.Type
421 ...........................................
422 .................................................
422 .............................. MemberInfo
425 ..........................................
426 ......................................
428 ..........................................
429 .........................................
431 ..................................................
431 ............................... ReflectionExample
/ 432 ......................................
/ 433 ..................................
w w.pdf actory.com
433 .............................................
435 ......................................................
435 ...................................
436 ................................
445 ..................................
448 .................................
450 ......................................
450 ..........................................
453 ..............................................
456 .............................................
462 ...................................
465 ..............................
469 ......................................................
474 .............................................
w w.pdf actory.com
479 .................................................
480 ...........................................
482 ....................................
487 ........................................
488 ...........................................
489 ...........................................
489 ...........................................
490 ............................................
490 .....................................................
491 ...................................................
492 ................................................
493 ........................................
494 ..............................................
494 ...............................................
495 ...............................................
497 ............................................... Label
497 ......................................... LinkLabel
w w.pdf actory.com
514 ............................................
515 ...............................................
518 ..........................................................
521 .....................................
527 ..............................................
527 ..............................
528 ............................................
537 ......................................................
542 ...............................................
545 ...................................................
545 .......................................
546 ..............................................
549 ................................
552 ...............................................
552 ............................................. Icons
554 ...................................................
w w.pdf actory.com
554 .............................................
556 .............................................
557 ................................................
558 ..................................... StringFormat
: 571 .......................................
571 .................................................
572 ...................................................
578 ................................
581 ............................................
582 .........................................
590 .............................................
592 ................ System.IO.FileSystemWatcher
593 ..............................................
595 ..............................................
598 ..........................................................
: 605 ...........................................
: 607 ................................. ADO.NET
w w.pdf actory.com
608 ..........................
612 ..........................................
613 ...............................................
614 .....................................
618 ...........................................
618 ...........................................
621 .............................................
623 ..........................................
624 .............................................
640 ...........................................
641 ...............................................
w w.pdf actory.com
644 .............................................
653 .........................................................
654 .................................................
655 .............................................
656 .........................................
675 .................................
678 .............................................
681 ....................................
682 ..............................................
w w.pdf actory.com
685 ...............................................
688 .......................................
690 ...................................................
690 ...................................
693 .......................................
693 ......................................
694 ...............................................
695 ............................................................
w w.pdf actory.com
715 ......................................................
715 ......................................... Caching
718 ............................................
718 ...............................................
720 ....................................
725 ......................................................
725 .............................................
727 ................................................
728 .................................
731 .............................................
735 ..............................................
: .......................................... XML 1
: ............................................... SQL 7
w w.pdf actory.com
.NET
) (dev4arabs.com
! 2=1+1 ) (
Microsoft .NET
.
.NET
!
) (Microsoft
.NET
w w.pdf actory.com
.NET
Documentation
.NET Documentation .
" MSDN
" .NET
Documentation .
.(iawmd.com) IAWMD
w w.pdf actory.com
)(dev4arabs.com
) (
:
) (Visual Basic
w w.pdf actory.com
. )
( .
.
.
.
--
w w.pdf actory.com
Visual Basic .NET Microsoft
..NET
.NET Framework
.NET -
.NET .Visual Basic .NET .NET
( .NET
.NET Framework
Microsoft .NET .
:
Windows ADO.NET
.
.NET
w w.pdf actory.com
.
.
Tutorial
.
Step by Step .
Reference
.
.
Workshop
Comprehensive
.NET Framework
.NET Framework
Visual Basic 16
.Visual Basic
w w.pdf actory.com
- .
: C#
BASIC - if Then
";" .
) Microsoft
(.
-
.Visual Basic
- Visual Basic
Microsoft Visual Basic
..NET
Help
- "" ""
w w.pdf actory.com
.Windows Overloading
" "
" " .
.NET Documentation
.NET Framework
MSDN
.Microsoft
.
700 :
. OOP Classes
Objects Inheritance
.Polymorphism
.NET Framework
.NET Framework
w w.pdf actory.com
.Reflection Classes
Forms Controls
Mirroring .
GDI+ .
.Services
ADO.NET Connected
ASP.NET ASP.NET
CD-ROM
) (JPG
.
ArabicConsole.DLL Console -
.Visual Basic .NET
w w.pdf actory.com
.
:
http://www.dev4arabs.com/lib/vbnetbook
) (
. ) (
.
. -
w w.pdf actory.com
Source Codes .
-
.NET Documentation.
.NET Framework
... !
--
2003
turki@dev4arabs.com
w w.pdf actory.com
w w.pdf actory.com
w w.pdf actory.com
w w.pdf actory.com
11 Visual Basic
..NET Framework
) Visual Basic for .NET Framework Visual Basic
.(.NET Framework
.
.NET
- .NET
.Framework
..NET
.NET
DOS
Microsoft .
w w.pdf actory.com
4
:
DOS
- - Input
Print
.
- - Devices )
...(
.Drivers
Assembly .
.
- -
DOS 200
.
) ( .
Windows
Windows
-
-
w w.pdf actory.com
Windows DOS
Messages
- -
.
Windows
.
Hello World Windows
)(! C
:
>#include <windows.h
;) LRESULT CALLBACK MainWndProc( HWND, UINT, WPARAM, LPARAM
;HINSTANCE ghInstance
int PASCAL WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszCmdLine,
) int nCmdShow
}
;WNDCLASS wc
;MSG msg
;HWND hWnd
) if( !hPrevInstance
{
;"wc.lpszClassName = "ShowWindow
;wc.lpfnWndProc = MainWndProc
;wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW
;wc.hInstance = hInstance
;) wc.hIcon = LoadIcon( NULL, IDI_APPLICATION
;) wc.hCursor = LoadCursor( NULL, IDC_ARROW
;) wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1
;wc.cbClsExtra = 0
;wc.cbWndExtra = 0
w w.pdf actory.com
6
:
RegisterClass( &wc );
}
ghInstance = hInstance;
hWnd = CreateWindow ( "ShowWindow",
"ShowWindow",
WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,
0,
0,
600,
300,
NULL,
NULL,
hInstance,
NULL);
ShowWindow( hWnd, nCmdShow );
while( GetMessage( &msg, NULL, 0, 0 )) {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return (int) msg.wParam;
}
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam,
LPARAM lParam )
{
PAINTSTRUCT ps;
HDC hDC;
switch( msg ) {
case WM_DESTROY:
PostQuitMessage( 0 );
Break;
default:
return( DefWindowProc( hWnd, msg, wParam, lParam ));
}
return 0;
}
Windows
)( Visual
w w.pdf actory.com
) !(.
Windows
Windows
Windows
.(DDE) - Dynamic Data Exchange
DDE
Microsoft
DDE
- Microsoft Excel Microsoft
.Word
DDE OLE2
In-place Activation Excel
Word .Word
COM
Windows
- Object
.Oriented
(DCOM) - Distributed COM
w w.pdf actory.com
8
:
COM Windows
.COM
COM
Interfaces
System Resources
COM Windows
Registry
Reinstall .
) (DCOM
Format .
Versioning .
w w.pdf actory.com
ASP
ASP
OOP VBScript .
ASP COM
ASP
)(
HTML ) Tags
(HTML
.
) XML
(HTML .TCP/IP
SOAP - -
w w.pdf actory.com
10
:
Bugs SOAP
.
) VBScript
( ) ASP (
T-SQL
Optimization COM
Visual C++ Microsoft
Office VBA
Windows .Visual Basic
Microsoft .
.Microsoft .NET
.NET
.NET .
w w.pdf actory.com
:
Notebooks Servers Mobiles
Hardware
) (
) ( .
.NET
Framework
.NET COM
.NET -
.NET COM
.NET COM
w w.pdf actory.com
12
:
System Registry
.NET
COM
....(.
DCOM Windows
.NET
.
Versioning
.NET COM
Inheritance COM
.NET
COM
) Visual
(Basic COM
) (Visual C++
w w.pdf actory.com
.NET Visual Basic .NET
Visual C# .NET
Java Delphi .NET :
CRL .
.NET
. .NET MSIL
Compiling .
Browser
Web Services
.
Web Service
XML
.
XML
XML TCP/IP .NET
Framework .
w w.pdf actory.com
14
:
.NET Framework
UNICODE
...
- -
.NET Documentation.
Mirroring
HijriCalendarClass
.
HijriCalendarClass
.
Microsoft
-
.
w w.pdf actory.com
.NET Framework
.NET Framework
10 -
) :(1- 1
) (Integer String
I/O File Processing Threading Windows
.NET
) Exception Handling
(.
.NET Framework
Windows ) (
.
w w.pdf actory.com
16
:
JIT
- -
)
(Optimization ) :(2- 1
:2- 1 .
Executable File
JIT
Compiler
Server 9504378250470592
w w.pdf actory.com
JIT
) (NGEN) Native Image Generator (Pre-JIT Compiler
) . .NET
Documentation .(NGEN
Assemblies
Assembly ) EXE (DLL
Compiling
Assemblies
- -
- .Assemblies
.NET
.Framework
.
.
w w.pdf actory.com
18
:
Visual Studio .NET ) Start Page - 1
(3
.NET Framework
w w.pdf actory.com
:Options
Options Tools ) (4- 1
Compilers Database Debugging
HTML Windows Forms.
:4- 1 .Options
:Class View
Project Classes
) (5- 1
.
w w.pdf actory.com
20
:
View .
:Solution Explorer
) .(6- 1 Solution
Explorer View .
w w.pdf actory.com
References
Add Reference
) .(7- 1
:7- 1 .Reference
.
:Project Property Pages
) 6- 1 ( Properties
) 8- 1 ( . Assembly
.Name
w w.pdf actory.com
22
:
:8- 1 .
:Object Browser
Reference
View->Other
Windows->Object Browser ) 9- 1
(.
w w.pdf actory.com
:9- 1 .
:Code Editor
) 10- 1 ( IntelliSense
" ".
.
" "+ .
w w.pdf actory.com
24
:
:10- 1 .
) ....(
.
:File
. Printing
.
:Edit
w w.pdf actory.com
:View
.
:Project
Reference . Set As
Startup Project
Project .Solution
:Build
Compiling
Configuration
Manager .
:Debug
13 ) (
Debugging.
.
:Tools
.Externals Tools Add-
w w.pdf actory.com
26
:
:Window
!
:Help
.
.
Toolbars
Customize
.Microsoft Office
Solution Projects
Project Files .Project Items
Solution Blank
Project . OK
w w.pdf actory.com
Templates .
:11- 1 Templates .
w w.pdf actory.com
28
:
Visual Basic .NET User
:Windows Application
.DLL
:Windows Control Library
User Controls
.Windows Application
ASP .NET .
:ASP .NET Web Service
w w.pdf actory.com
:Console Application
DOS .
.Visual Basic .NET
:Windows Services
Windows Background
.
.
:Empty Project
.
:Empty Web Project
.
Templates
Windows Service
w w.pdf actory.com
30
:
Console Application
Module Module1
)(Sub Main
End Sub
End Module
Module FirstProg
)(Sub Main
Console.WriteLine("In the name of Allah the most gracious
)"and the most merciful
End Sub
End Module
Compiling (
] [ENTER :
w w.pdf actory.com
Module FirstProg
)(Sub Main
)(Console.Read
End Sub
End Module
) .(12- 1
:12- 1 .
ArabicConsole
Console
ArabicConsole Console
. ArabicConsole
)( WriteLine .
) (7- 1
Brows ArabicConsole.DLL
.
w w.pdf actory.com
32
:
ArabicConsole
'
' ArabicConsole
Imports ArabicConsoleProject
)" "(
Module FirstProg
)(Sub Main
ArabicConsole.WriteLine
End Sub
End Module
Imports ArabicConsoleProject
.
)( Read
ArabicConsole .
Compiling
- - Compiler
.Configurations
Debug
:13- 1 .
w w.pdf actory.com
Release
.
Configuration Properties
.Project Property Pages
.NET
Framework microsoft.com
100 .
w w.pdf actory.com
w w.pdf actory.com
.Windows
ArabicConsole
Visual Basic
.NET . -
...(
.Visual Basic .NET
Modules
Module
FirstProg :Module
w w.pdf actory.com
36
:
Module FirstProg
)(Sub Main
)" "(ArabicConsole.WriteLine
End Sub
End Module
) Module X
.(End Module
:Statement is not valid in a namespace
'
' Module
Dim X As Integer
)( Sub Test
End Sub
Module FirstProg
End Module
Module DrawingFunctions
End Module
Module InternetFunctions
End Module
Module SystemFunctions
End Module
w w.pdf actory.com
:
37
Identifiers ) ...( :
16383 -
"_"
"_" ) (.
Keyword .
] [ ) Dim [Dim] :
.( As Integer ] [
Module
'
MyModule '
w w.pdf actory.com
38
:
' First.vb
Module MyModule
End Module
' Second.vb
Module MyModule
End Module
Namespaces .
.
)(Sub Main
Module
)( Main
Module Module1
)(Sub Main
)" "(ArabicConsole.WriteLine
End Sub
End Module
)( Main :
Module Module1
)(Sub Main
)" "(ArabicConsole.WriteLine
End Sub
End Module
Module Module2
)(Sub Main
w w.pdf actory.com
:
39
)" "(ArabicConsole.WriteLine
End Sub
End Module
)( Main
Startup Object Project
) ( )( Main
.
:1- 2 .
)(Sub New
New
Constructor .
)(New
)(:Main
Module Module1
)(Sub New
w w.pdf actory.com
40
:
)" New"(ArabicConsole.WriteLine
End Sub
)(Sub Main
)" ArabicConsole.WriteLine("Main
End Sub
End Module
Constructors
.
Module2
:
Module Module1
)(Sub New
)" New"(ArabicConsole.WriteLine
End Sub
)(Sub Main
)" ArabicConsole.WriteLine("Main
End Sub
End Module
Module Module2
)(Sub New
)" "(ArabicConsole.WriteLine
End Sub
End Module
w w.pdf actory.com
:
41
Dim As
' Integer
Dim Age As Integer
' String
Dim FirstName As String
Dim LastName As String
String
Visual Basic .NET :
:
'
'
Dim FirstName, LastName As String, Age As Integer
Object :
Dim X
' Integer
' String
w w.pdf actory.com
X = 10
"X = "10
42
:
.
:Option Explicit
'
'
) ArabicConsole.Writeline ( programerName
w w.pdf actory.com
:
43
Visibility Scope
X )( MySub1
)( Sub MySub1
Dim X As Integer
X = 20
End Sub
)( Sub MySub2
X '
)ArabicConsole.WriteLine (X
End Sub
Lifetime
X 20
)( .MySub1 Visual Basic .NET
:
w w.pdf actory.com
44
:
:
Dynamic Local Variables
. .
Dim .
small
.Capital:
. y :For Next
Next
- :
Dim x As Integer
If x = 0 Then
Dim y As Integer
End If
'
w w.pdf actory.com
x = y
:
45
Dim a As Integer
Do
'
Dim a as integer
Loop
'
Dim x As Integer
'
If x = 0 Then
Dim x As String
End If
Do
'
Dim x As Long
Loop
For counter2 :
w w.pdf actory.com
46
:
:
1
2
3
4
5
6
7
8
9
:
Static Local Variables
) (
Static Dim :
)( Sub Counter
Static counter As Integer
counter = counter + 1
End Sub
)( Sub PrintData
Static isPrinting As Boolean
If isPrinting Then
Exit Sub
Else
isPrinting = True
End If
End Sub
w w.pdf actory.com
:
47
Static
.
:
Visual Basic .NET Module
Level Variables .
Private Dim
:
Module Module1
'
Dim x As Integer
Private y As Integer
)(Sub Main
x = 50
End Sub
)( Sub Test
y = 10
End Sub
End Module
Global Variables
. Public
:
'
Module Module1
Public x As Integer
)(Sub Main
x = 5
End Sub
End Module
w w.pdf actory.com
48
:
'
'
Module Module2
)(Sub Test
x = 1
End Sub
End Module
Friend
Public
. Friend
.
.NET PascalCase
smallCase :
'
'
w w.pdf actory.com
:
49
.
Byte .
Boolean
Byte
Char
) True( ) False(.
0 .255
Date
Decimal
16
Double
Integer
.UNICODE
0:00:00 11:59:59
1 0001 31
.9999
79,228,162,514,264,337,593,543,950,335
0
7.9228162514264337593543950335
1.79769313486231570E+308
4.94065645841246544E-324
.
4.94065645841246544E-324
1.79769313486231570E+308
.
2,147,483,648
.2,147,483,647
w w.pdf actory.com
50
:
Long
Object
Short
32,768 .32,767
Single
String
* 2) + 10
9,223,372,036,854,775,808 -
.9,223,372,036,854,775,807
3.4028235E+38 E-
1.40129845 . E-
1.40129845 3.4028235E+38
0 2 .UNICODE
Char
" "c Char
:String
Dim A As Char
'
"c" = A
"c" = A
Char
String
. Char
w w.pdf actory.com
:
51
:
-
-
Visual Basic .NET Object
. - Visual
Basic .NET :
) System.ValueType
( .
) Stack
( .
Reference Type
) Pointer
(
Managed Heap
Garbage Collection .NET :
'
'
w w.pdf actory.com
52
:
:3- 2 .
.
String Arrays
"="
w w.pdf actory.com
:
53
'
Dim X As Integer = 10
Dim Y As Integer
Dim Z As Long
Y = 20
Z = 30
'
Dim X As Integer, Y As Integer = 20, Z As Long = 30
'
Dim X, Y As Integer = 20, Z As Long = 30
:
'
Dim X As Byte = 256
Dim X As Integer = 5 + 5
1
2
3
6
2
+
*
\
^
x
x
x
x
x
=
=
=
=
=
x
x
x
x
x
'
'
'
'
'
1
2
3
6
2
=+
=-
=*
=\
=^
X
X
X
X
X
:
Visual Basic .NET '
'
Dim X As Integer += 10
Dim Y As Long ^= 20
w w.pdf actory.com
54
:
) Managed
.(Heap ) :(4- 2
'
" " = Dim Name As String
Dim Name2 As String = Name
'
Dim Age As Integer = 99
Dim Age2 As Integer = Age
:4- 2 .
) (4- 2 ) Name (Name2
Managed Heap
) Age (Age2 .
w w.pdf actory.com
:
55
) (Stack 4
.
:Option Strict
)ArabicConsole.WriteLine(A
)ArabicConsole.WriteLine(B
Double
Single
Double :Single
)ArabicConsole.WriteLine(A
)ArabicConsole.WriteLine(B
.Double Narrowing
Conversion ) (Double )
w w.pdf actory.com
56
:
) (Bugs
'
Option Strict On
Module Module1
)(Sub Main
Dim A As Double = 1
Dim B As Single
'
A = B
'
B = A
End Sub
End Module
Option Strict
- -
- Project Property Pages
) Option Explicit 2-2 .(43
Option Strict
'
Option Strict Off '
Dim A As String
Dim B As Boolean
"A = "True
B = A
w w.pdf actory.com
:
57
/
^ :Double
'
' Option Strict On
Dim X As Integer
X = 10 / 2
X = 2 ^ 3
Option Strict On
'
' Option Strict On
Dim X As Double = 3.2
)Dim Y As Integer = CInt(X
CBool
CByte
CChar
CDate
CDbl
CDec
CInt
CLng
CObj
CShort
CSng
CStr
Boolean
Byte
Char
Date
Double
Decimal
Integer
Long
Object
Short
Single
String
w w.pdf actory.com
58
:
Option Strict On
Value Type
-Reference Type
Integer
:Double
' Integer
' Double
)ArabicConole.WriteLine (10
)ArabicConole.WriteLine (5.5
" "L
Long " "S Short " "D Decimal " "F Single
) :(MSDN
Dim X As Long
Dim Y As Long
'
X = 100
Y = 100L
Date / # :#
Dim X As Date
Dim Y As Date
x = #1/29/2003#
Y = #2/15/2003 9:30:00 PM#
) EXE( . Const :
w w.pdf actory.com
:
59
Option
:Strict On
Hexadecimal
'
)ArabicConsole.WriteLine(&HFF
' 8
'
)ArabicConsole.WriteLine(&O10
- Integer
" "L :
' -1
' 4294967295
)ArabicConsole.WriteLine(&HFFFFFFFF
)ArabicConsole.WriteLine(&HFFFFFFFFL
Hexadecimal Octal
'
)ArabicConsole.WriteLine(&HFF.25
Enums Structures .
Enums
.Enumeration Enum
w w.pdf actory.com
60
:
Module
.Structure :
Enum Day
Saturday
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
End Enum
:
Dim x As Day
Dim y As Day
x = Day.Friday
y = x
Enums
- -
.
Enums :
)Sub ShowDay(ByVal CurrentDay As Day
If CurrentDay = Day.Friday Then
)""(ArabicConsole.WriteLine
End If
End Sub
w w.pdf actory.com
:
61
Dim X As Day
X = Day.Friday
)ShowDay(X
)ShowDay(Day.Friday
0 :
Enum Day
Saturday = 10
Sunday = 20
Monday
Tuesday
Wednesday
Thursday
Friday
End Enum
. Monday 21
Integer
End Enum
Private
Public
w w.pdf actory.com
62
:
Module Module1
'
Enum GlobalEnum
Enum1
Enum2
End Enum
'
Public Enum GlobalEnum2
Enum1
Enum2
End Enum
'
Private Enum PrivateEnum
Enum1
Enum2
End Enum
End Module
Enum
Private .
Enum Structure
.Modules
Friend
Public .
Structures
w w.pdf actory.com
:
63
Structure Person
Dim Name As String
Dim Age As Integer
End Structure
:
Dim Turki As Person
Turki.Name = ""
Turki.Age = 99
ArabicConsole.WriteLine(Turki.Name) '
ArabicConsole.WriteLine(Turki.Age) ' 99
- Nested Structure
Structure Person
Structure AddressStruct
Dim City As String
Dim Countrey As String
End Structure
Dim Name As String
Dim Age As Integer
Dim Address As AddressStruct
End Structure
w w.pdf actory.com
64
:
Structure Visual
Methods
:Properties
Structure Person
Dim Name As String
Dim Age As Integer
'
)(Sub ShowData
)ArabicConsole.WriteLine(Name
)ArabicConsole.WriteLine(Age
End Sub
End Structure
:
Dim Turki As Person
" " = Turki.Name
Turki.Age = 99
)(Turki.ShowData
( Constructers
.Structures ! !
w w.pdf actory.com
:
65
)( Sub New .
Structure MyStruct
Dim x As Integer = 0
Dim y As Integer = 10
End Structure
)
( )( Sub New
) 0 Nothing( .
)( Sub New
) Overloading ( . Parameters
)(:Sub New
Structure Person
Dim Name As String
Dim Age As Integer
' Overload
)Sub New(ByVal PersonName As String
Name = PersonName
)" "(ArabicConsole.WriteLine
End Sub
End Structure
)( Sub New
'
Dim Turki As Person
w w.pdf actory.com
66
:
)( Sub New ) ( .
New
'
)" "(Dim Turki As New Person
Dim
.
Private
:
'
'
Structure Person
Public Name As String
Dim Age As Integer
Private MotherName As String
)(Sub Test
" !" = MotherName
End Sub
End Structure
w w.pdf actory.com
:
67
! Structure
.Enums
:
Private
) Public (
.
Friend.
10 '
4 = 2 * 2 '
-
:0
=
=
=
=
)0
)1
)0
)1
(0,
(0,
(1,
(1,
TwoDims
TwoDims
TwoDims
TwoDims
Dynamics Arrays
w w.pdf actory.com
68
:
ReDim
ReDim :
Preserve -
:
'
)ReDim Preserve OneDim (500
)ReDim Preserve TwoDims (10, 500
'
)ReDim Preserve TwoDims (500, 500
Preserve :
'
)ReDim Preserve OneDim (500, 500
)ReDim TwoDims (100
:Erase
Erase OneDim
Erase TwoDims
Reference Type
"=" .
)(:Clone
w w.pdf actory.com
:
69
)( UBound
)( LBound :
Next
:
'
'
'
)UBound(OneDim
)UBound(OneDim, 1
)UBound(OneDim, 2
w w.pdf actory.com
70
:
Parameters
:
'
)( MySub
ArabicConsole.WriteLine (Abs (-5)) ' 5
Exit Sub
End Function
Exit Function
0 Nothing
.
:ByRef
'
)Sub swapByVal(ByVal a As Integer, ByVal b As Integer
Dim temp As Integer
temp = a
a = b
b = temp
End Sub
w w.pdf actory.com
:
71
'
)Sub swapByRef(ByRef a As Integer, ByRef b As Integer
Dim temp As Integer
temp = a
a = b
b = temp
End Sub
:
Dim A As Integer
Dim B As Integer
A = 10
B = 20
'
)swapByVal (A, B
ArabicConsole.WriteLine (A) ' 10
ArabicConsole.WriteLine (B) ' 20
'
)swapByRef (A, B
ArabicConsole.WriteLine (A) ' 20
ArabicConsole.WriteLine (B) ' 10
.
. -
w w.pdf actory.com
72
:
Visual Basic .NET
Optional .ParamArray
:
Optional
End Sub
Optional )
( :
'
)Sub MySub(ByVal Y As Byte, Optional ByVal X As Integer = -1
End Sub
'
)Sub MySub(Optional ByVal X As Integer = -1, ByVal Y As Byte
End Sub
:ParamArray
w w.pdf actory.com
:
73
:
ArabicConsole.WriteLine ( Sum (1) )
ArabicConsole.WriteLine ( Sum (2, 2) )
ArabicConsole.WriteLine ( Sum (1, 2, 3, 4, 5) )
' 1
' 4
' 15
'
ArabicConsole.WriteLine ( Sum (1, , 3) )
Windows API
! Windows API
Windows .
Windows API
:Ansi
Module Module1
Declare Auto Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
ByRef nSize As Integer) As Integer
Sub Main ()
GetUserName (x, y)
End Sub
End Module
w w.pdf actory.com
74
:
If Then
If Then
End If ) (:
'
If X = 0 Then Y = 1
If X = 1 Then X = 2 : Y = 4
If Y = 1 Then X = 0 Else X = 2
'
If X = 0 Then
Y = 1
End If
If X = 1 Then
X = 0
Y = 4
End If
If Y = 1 Then
X = 0
Else
X = 2
End If
End If
:
w w.pdf actory.com
:
75
If X = 0 Then
If Y = 0 Then
X = 100
End If
Else
Y = 1
End If
( :
If X = 0 Then
If Y = 0 Then
X = 100
Else
Y = 1
End If
End If
:
If Then End If
End If
If Not Y > 1 Then
w w.pdf actory.com
76
:
:
If X <> 0 And 10 \ X = 2 Then
X
.
X ) False( . And
AndAlso
:
If X <> 0 AndAlso 10 \ X = 2 Then
AndAlso OrElse
:True
'
' X
'
If X > 0 OrElse Y < 0 Then
AndAlso OrElse
True And Or
bit-wise operators :
x = 3
y = 12
If x <> 0 And y <> 0 Then ' True
w w.pdf actory.com
:
77
AndAlso :
'
' True And True = True
If x AndAlso y Then
And :
'
)' 0011 And 1100 = 0000 (False
If x And y Then
:ElseIf
If X = 1 Then
ElseIf X = 2 Then
ElseIf X = 3 Then
Else
End If
Select Case
Select Case :
)""(
)""(
)" "(
)" "(
w w.pdf actory.com
Dim X As Integer
Select Case X
Case 1
ArabicConsole.WriteLine
Case 2
ArabicConsole.WriteLine
Case 12
ArabicConsole.WriteLine
Case Else
ArabicConsole.WriteLine
End Select
78
:
Select Case
(")"
(")"
(")"
(")"
(")"
:
Dim Letter As Char
: Or
Select Case True
Case x > 0, Y < 0
'
' If (X > 0) Or (Y < 0)
End Select
w w.pdf actory.com
:
79
End Select
:For Next
Dim counter As Integer
For counter = 2 To 4
' )ArabicConsole.WriteLine(counter
Next
:Step
For counter = 5 To 1 Step -1
Next
:
For counter = 5 To 1 Step -1
Next
0 ' 1
ArabicConsole.WriteLine(counter) ' 0
Next
:Exit For
w w.pdf actory.com
80
:
For counter = 1 To 50
If y = 10 Then
Exit For
End If
Next
:Collections
For Each y In x
)ArabicConsole.WriteLine(y
Next
For Each
.
Do Loop
)
( . Until
True While
:True
Loop
", MsgBoxStyle.YesNo) = MsgBoxResult.No "(Do While MsgBox
Loop
w w.pdf actory.com
:
81
.Exit Do
For Next :Do Loop
A = 5
' For Next
For counter = 1 To A
Next
' Do Loop
counter = 1
Do
counter = counter + 1
Loop Until counter > A
A For Next
A
.Do Loop
Namespaces
Namespaces
. :Mouse
Structure Mouse
End Structure
w w.pdf actory.com
82
:
- - .Mouse
.
Project
- - .
Project Property Pages
:5- 2 .
- - .
Namespace Devices
End Namespace
w w.pdf actory.com
:
83
Classes
Modules Structures Interfaces Enumd
:
Namespace Devices
Structure Mouse
End Structure
Structure Printer
End Structure
End Namespace
Namespace Animals
Structure Mouse
End Structure
Structure Cat
End Structure
End Namespace
Classes
Interfaces
. Modules -
Enums Structures .
w w.pdf actory.com
84
:
:Nested
Namespace Devices
Namespace Inputs
Structure Mouse
End Structure
Structure Keyboard
End Structure
End Namespace
Namespace Outputs
Structure Monitor
End Structure
Structure Printer
End Structure
End Namespace
End Namespace
:
Dim X As Animals.Mouse
Dim Y As Devices.Mouse
Structures:
w w.pdf actory.com
:
85
Dim X As Devices.OutPuts.Printer
Dim Y As Devices.OutPuts.Screen
Dim Z As Devices.Inputs.Keyboard
) (
' Devices.Inputs
Dim X As Keyboard
Dim Y As Mouse
' Dim Z As OutPuts.Printer
Imports
Dim X As Devices.OutPuts.Printer
Dim Y As Devices.OutPuts.Screen
Dim Z As Devices.Inputs.Keyboard
Devices :Imports
Imports MyNameSpace.Devices
Dim X As OutPuts.Printer
Dim Y As OutPuts.Screen
Dim Z As Inputs.Keyboard
:
Imports MyNameSpace.Devices.OutPuts
Imports MyNameSpace.Devices.Inputs
Dim X As Printer
Dim Y As Screen
Dim Z As Keyboard
w w.pdf actory.com
86
:
Imports
)
( .
MyNameSpace .
Imports MyNameSpace.Animals
Imports MyNameSpace.Devices.Inputs
Dim X As Mouse
Mouse .
Imports MyNameSpace.Animals
Imports tmp = MyNameSpace.Devices.Inputs
Dim X As Mouse
Dim Y As tmp.Mouse
) .NET
(Framework
) Solution Explorer 6- 2 (.
w w.pdf actory.com
:
87
:6- 2 .
Imports
)
(Imports
Imports ) Project Property Pages .(7- 2
:7- 2 .Imports
w w.pdf actory.com
88
:
Imports .
Delegates .
w w.pdf actory.com
OOP Visual Basic
Visual Basic .NET ! Visual
Basic .NET OOP OOP
.NET Framework
- OOP
. !
Structure Person
Dim Name As String
Dim Age As Integer
End Structure
Class :Structure
w w.pdf actory.com
90
:
Class Person
Dim Name As String
Dim Age As Integer
End Class
Private Public :
Class Person
' Public
Public Name As String
Public Age As Integer
End Class
) ( Person
New :
)(Dim Turki As New Person
" " = Turki.Name
Turki.Age = 99
'
' 99
)ArabicConsole.WriteLine(Turki.Name
)ArabicConsole.WriteLine(Turki.Age
) Sub (Function
Public :
Class Person
)( Sub PublicMethod
End Sub
' Public
' Public
End Sub
w w.pdf actory.com
:
91
' Friend
' Private
End Sub
)( Private Sub PrivateMethod
End Sub
End Class
:
'
Class PersonClass
End Class
'
Structure PersonStructure
End Structure
Interfaces
.
Nested:
Class Car
Class Engine
Public Cylinder As Integer
End Class
Public Model As String
)(Public CarEngine As New Engine
End Class
w w.pdf actory.com
92
:
New :
)ArabicConsole.WriteLine(BMW.Model
)ArabicConsole.WriteLine(BMW.CarEngine.Cylinder
Visibility Friend
Public
Private
Private Module Class
:Structure
' Friend
Class FriendClass
End Class
Module Module1
' Friend
Class FriendClass2
End Class
' Friend
Friend Class FriendClass3
End Class
' Public
Public Class PublicClass
End Class
' Private
Private Class PrivateClass
End Class
End Module
w w.pdf actory.com
:
93
Friend Private Public
Protected .Protected Friend
) .
(!
) (ByVal
. )
(:
Module Module1
Class TestClass
Public X As Integer
End Class
)(Sub Main
)(Dim TestObject As New TestClass
TestObject.X = 10
)SendByValue(TestObject
1 ArabicConsole.WriteLine(TestObject.X) ' 10End Sub
)Sub SendByValue(ByVal obj As TestClass
obj.X = -1
End Sub
End Module
Classes Structures
- .
.NET C )
( PascalCase
w w.pdf actory.com
94
:
:Private
' Private
' Private
'
' CEmployeeData
Class EmployeeData
Public EmployeeName As String
Friend EmployeeAge As Integer
Dim motherName As String
Private salaryAmount As Decimal
End Class
Class
Members : .
Fields
Fields -
-.NET .
5:
Class SimpleClass
Public Field1 As String
Freind Field2 As Integer
Dim field3 As Double
Dim field4 As Boolean
Private field5 As PersonClass
End Class
Structure
:
Class SimpleClass
" " = Public Field1 As String
Freind Field2 As Integer = 99
End Class
w w.pdf actory.com
:
95
) LIFO :(FIFO
Class SimpleClass
Public Field1 As SimpleClass
Public Field2 As Integer = 0
End Class
:
)(Dim SimpleObject As New SimpleClass
)(SimpleObject.Field1 = New SimpleClass
SimpleObject.Field1.Field2 = 10
' 10
ArabicConsole.WriteLine(SimpleObject.Field2) ' 0
)ArabicConsole.WriteLine(SimpleObject.Field1.Field2
(Last-In-First-Out) LIFO (First-In-First-Out) FIFO
.
. .NET Framework Stack
Queue
.
) (
Class ArrayClass
Public X() As Integer
Public Y(9) As Integer
End Class
ReDim
:
w w.pdf actory.com
96
:
'
)ReDim ArrayObject.Y(99
ArrayObject.Y(0) = 10
ArrayObject.Y(1) = 20
ReadOnly :
Class SimpleClass
)(Public ReadOnly CreatedDate As Date = Now
End Class
ReadOnly
:
Methods
Fields Methods
) Subs (Functions .
.NET Framework -
.Methods
w w.pdf actory.com
:
97
Class PersonRecord
Public Name As String
Public Age As Integer
Public Address As String
_ Sub SetValues(ByVal PersonName As String,
)ByVal PersonAge As Integer, ByVal PersonAddress As String
Name = PersonName
Age = PersonAge
Address = PersonAddress
End Sub
End Class
:
Dim PersonObject As New PersonRecord
'
" " = PersonObject.Name
PersonObject.Age = 99
" " = PersonObject.Address
'
)" " ", 99, "(PersonObject.SetValues
Structures
Static
:
'
Class TestClass
)(Sub Method
Static X As Integer
End Sub
End Class
'
Structure TestStructure
)(Sub Method
Static X As Integer
End Sub
End Structure
w w.pdf actory.com
98
:
.NET PascalCase
camelCase :
End Sub
:Overloading
OOP Overloading
Class SimpleClass
' SameName
'
)(Sub SameName
End Sub
)Sub SameName(ByVal X As Integer
End Sub
)Sub SameName(ByVal Y As String
End Sub
End Class
)( SameName
:
End Sub
'
)Sub SameName(ByVal Y As String
End Sub
w w.pdf actory.com
:
99
) ByRef
(ByVal :
End Sub
'
)Sub SameName(ByRef Y As String
End Sub
:
)Public Sub SameName(ByVal X As String
End Sub
'
)Friend Sub SameName(ByVal X As String
End Sub
Optional . :
)Sub SameName(Optional ByVal X As Integer = 0
End Sub
'
)"Sub SameName(Optional ByVal X As String = "...
End Sub
Optional .
.
Overloads
:
w w.pdf actory.com
100
:
End Sub
)Overloads Sub SameName(ByVal X As Integer
End Sub
- Overloads -
) (
.
Class TestClass
)Overloads Sub SameName(ByVal X As Integer
)" "(ArabicConsole.WriteLine
End Sub
)Overloads Sub SameName(ByVal X As String
)" "(ArabicConsole.WriteLine
End Sub
End Class
:
)(Dim TestObject As New TestClass
Dim A As Integer = 100
"Dim B As String = "100
' )TestObject.SameName(A
' )TestObject.SameName(B
w w.pdf actory.com
:
101
Widening Conversion
Narrowing Conversion :
Dim A As Byte = 10
Dim B As Char = "A"c
Dim C As Long = 10
' )TestObject.SameName(A
' )TestObject.SameName(B
) ( ' )TestObject.SameName(C
) ( :
End Sub
)Sub OpenByName (ByVal name As String
End Sub
) String (Integer
w w.pdf actory.com
102
:
Open
:
End Sub
)Overloads Sub Open (ByVal name As String
End Sub
Modules .Structures
:Constructors
Constructor Method
)( Sub New :
Class TestClass
)(Sub New
)" "(ArabicConsole.WriteLine
End Sub
End Class
TestClass
:New
'
'
)(Dim TestObject As New TestClass
)
(:
'
'
'
TestObject2 = TestObject
w w.pdf actory.com
:
103
Parameters .
) ( :
Class PersonClass
Public FirstName As String
Public LastName As String
'
)Sub New(ByVal firstN As String, ByVal lastN As String
FirstName = firstN
LastName = lastN
End Sub
End Class
'
)(Dim TestObject As New PersonClass
'
)"" ","(Dim TestObject As New PersonClass
Optional ) Overloading (
:
'
Class PersonClass
w w.pdf actory.com
104
:
'
'
Class PersonClass
)(Sub New
End Sub
)Sub New(ByVal firstN As String, ByVal lastN As String
FirstName = firstN
LastName = lastN
End Sub
End Class
Overloads
.
Recursively
:Recursion
'
Class TestClass
)(Sub New
)(New
End Sub
End Class
) Me
Me (:
Class TestClass
)(Sub New
' )Me.New(100
End Sub
)Sub New(ByVal X As Integer
End Sub
End Class
w w.pdf actory.com
:
105
)( Sub New
) Sub New(X As Integer Visual Basic .NET .
:ReadOnly
Class TestClass
Public ReadOnly X As Integer = -1
'
)(Sub New
X = 100
End Sub
End Class
Properties
Properties Fields Methods
. Methods
. Property
:
Class PersonClass
Property BirthDate() As Date ' Date
End Property
End Class
Get
Set
Private :
'
Private m_BirthDate As Date
Property BirthDate() As Date
Get
Return m_BirthDate
End Get
w w.pdf actory.com
106
:
' Value
Date ' ByVal
)Set(ByVal Value As Date
m_BirthDate = Value
End Set
End Property
Get Set :
BirthDate Set
) Value (ByVal
BirthDate Get
- Return .Functions
Read Only
( .
Age )
:(BirthDate
WriteOnly Get
) (
:
w w.pdf actory.com
:
107
Parameters
:
Dim Turki As New PersonClass()
Dim counter As Integer
Turki.Address(0) = ""
Turki.Address(1) = ""
Turki.Address(2) = " - "
For counter = 0 To 2
ArabicConsole.WriteLine(Turki.Address(counter))
Next
Overloading
Structure Modules
Static
.Structures
w w.pdf actory.com
108
:
:Default Properties
Default :
End Property
) Address (
:
Address
Parameters
.Parameters
Address
Turki
! Turki :
w w.pdf actory.com
:
109
Address ) (
Address:
Age :
Class PersonClass
'
Public Age As Integer
'
Private m_Age As Integer
Property Age() As Integer
Get
Return m_Age
End Get
)Set(ByVal Value As Integer
m_Age = Value
End Set
End Property
'
Function Age(Optional ByVal newValue As Integer = -1) As Integer
Static AgeValue As Integer
If newValue <= 0 Then
Return AgeValue
Else
AgeValue = newValue
End If
End Function
End Class
w w.pdf actory.com
110
:
) (Note
) NumOfFrogs
Action ) Smile (.
Events
) (
.Reusable
.Events
PersonClass Die
) - Fire
Event ( . :Event
Class PersonClass
)(Event Die
End Class
w w.pdf actory.com
:
111
WithEvents
Handles :
Module Module1
)(Dim WithEvents Turki As New PersonClass
)(Sub Main
End Sub
' Die
Sub PersonHasDied() Handles Turki.Die
)" "(ArabicConsole.WriteLine
End Sub
End Module
WithEvents
Local Varaibles
Module Class .Global
Turki
Die
:
)(PersonHasDied
RaiseEvent )( KillHim
:Die
Class PersonClass
)(Event Die
)(Sub KillHim
)(RaiseEvent Die
End Sub
End Class
)( KillHim Die
)(:KillHim
w w.pdf actory.com
112
:
Module Module1
)(Dim WithEvents Turki As New PersonClass
)(Sub Main
'
)(Turki.KillHim
End Sub
Sub PersonHasDied() Handles Turki.Die
)" "(ArabicConsole.WriteLine
End Sub
End Module
Handles
End Sub
Handles
Parameters
:
Class TestClass
)Event TestEvent(ByVal x As Integer
End Class
Handles :
'
Sub TestSub() Handles TestObject.TestEvent
End Sub
'
Sub TestSub(ByVal Y As Integer) Handles TestObject.TestEvent
End Sub
w w.pdf actory.com
:
113
RaiseEvent
:
)RaiseEvent TestEvent(10
:AddHandler
.AddHandler
. AddHandler
) :(AddressOf
Module Module1
)(Dim Turki As New PersonClass
)(Sub Main
'
AddHandler Turki.Die, AddressOf PersonHasDied
)(Turki.KillHim
End Sub
)(Sub PersonHasDied
)" "(ArabicConsole.WriteLine
End Sub
End Module
)( PersonHasDied Die
Turki ) (
RemoveHandler :AddHandler
w w.pdf actory.com
114
:
RemoveHandler )(PersonHasDied
Die .
WithEvents AddHandler
WithEvents
AddHandler .
:WithEvents
Module Module1
)(Dim WithEvents Turki As New PersonClass
)(Sub Main
Turki Turki2 '
Dim Turki2 As PersonClass = Turki
'
' PersonHasDied
)(Turki2.KillHim
) ' ( WithEvents
Turki = Nothing
'
' PersonHasDied
)(Turki2.KillHim
End Sub
Sub PersonHasDied() Handles Turki.Die
)" "(ArabicConsole.WriteLine
End Sub
End Module
WithEvents
)(
WithEvents )( PersonHasDied
Die .
w w.pdf actory.com
:
115
AddHandler
) ( ) (
:AddHandler
Module Module1
)(Dim Turki As New PersonClass
)(Sub Main
AddHandler Turki.Die, AddressOf PersonHasDied
Turki Turki2 '
Dim Turki2 As PersonClass = Turki
'
' PersonHasDied
)(Turki.KillHim
'
Turki = Nothing
'
PersonHasDied '
)(Turki2.KillHim
End Sub
)(Sub PersonHasDied
)" "(ArabicConsole.WriteLine
End Sub
End Module
)( PersonHasDied Die
)( PersonHasDied
(.
AddHandles
WithEvents WithEvents
:
'
Dim WithEvents Turki(9) As PersonClass
w w.pdf actory.com
116
:
WithEvents
:AddHandles
Module Module1
Dim Turki(5) As PersonClass
)(Sub Main
Dim counter As Integer
Dim Turki(5) As PersonClass
)For counter = 0 To UBound(Turki
)(Turki(counter) = New PersonClass
'
AddHandler Turki(counter).Die, AddressOf PersonHasDied
Next
)(Turki(0).KillHim
)(Turki(5).KillHim
End Sub
)(Sub PersonHasDied
)" "(ArabicConsole.WriteLine
End Sub
End Module
Reference Type
Classes Arrays Strings
Pointer Turki:
w w.pdf actory.com
:
117
Class PersonClass
End Class
Turki Ali
Age Turki
Ali ) 1- 3 (.
w w.pdf actory.com
118
:
Classes String
- :Reference Type
"" = Turki.FirstName
FirstName
) Managed Heap .(2- 3
:2- 3 FirstName .
w w.pdf actory.com
:
119
Turki Ali
FirstName .
Turki FirstName )
""(.
.
.New
:New
New
Managed Heap )(
"=":
'
)( Dim TestObject As New TestClass
'
Dim TestObject As TestClass
'
TestObject = New TestClass
New Fields
:Structures
Structure TestStructure
' )( Dim TestObject As New TestClass
End Structure
New
w w.pdf actory.com
120
:
)(Sub Main
'
))(TestSub(New TestClass
End Sub
)Sub TestSub(ByVal obj As TestClass
)( obj.DoMethod
End Sub
New
New
:
'
)( Dim TestObject As New TestClass
'
)Dim AnotherObject As New AnotherClass(2, 5
TestObject.Field1 = 10
TestObject.Field2 = 20
)TestObject.Method1 (10
TestObject.Property1 (2, 2) = 10
With TestObject
.Field1 = 10
.Field2 = 20
).Method1 (10
.Property1 (2, 2) = 10
End With
w w.pdf actory.com
:
121
:Nothing
Nothing
: Nothing
.
:Is
Is :
Is ) (Boolean
Is
:Nothing
Turki '
If Turki Is Nothing Then
)(Turki = New PersonClass
End If
w w.pdf actory.com
122
:
:TypeOf Is
TypeOf Is Is
:Me
Me Me
: :
Class PersonClass
Public Name As String
)( Sub PrintName
Name '
) ArabicConsole.WriteLine ( Me.Name
End Sub
End Class
Me
)( . Me
Private :Me
Class PersonClass
Private Name As String
)( Sub PrintName
' )ArabicConsole.WriteLine (Me.Name
' Me = Nothing
End Sub
End Class
w w.pdf actory.com
:
123
"="
- :
New
Dim X As ClassA
' )( X = New ClassA
' )( X = New ClassB
New
:Object
Dim X As Object
Dim Y As Object
' ClassA
)( X = New ClassA
'
Y = X
)( Y.MethodInClassA
' ClassB
)( Y = New ClassB
w w.pdf actory.com
124
:
'
X = Y
)( X.MethodInClassB
Object
Late Binding
Early Binding -
- :
'
)( Dim X As TestClass = New TestClass
'
)( Dim X As Object = New TestClass
Option Strict :
'
' Option Strict On
Dim X As Object
'
)( X = New ClassA
'
)(X.MethodInClassA
)( MethodInClassA
X
Parameter )
(ArabicConsole
w w.pdf actory.com
:
125
Dim X As Object
Dim Y As ClassA
)( X = New ClassA
' Y = X
X ) Object (ClassA
Y ClassA
CType :
Dim X As Object
Dim Y As ClassA
)( X = New ClassA
Y = CType (X, ClassA) ' CType
' )(Y.MethodInClassA
w w.pdf actory.com
126
:
Value Type
Lifetime x:
)( Sub MySub
Dim X As Integer = 10
End Sub
.
:Reference Type
)( Sub MySub
Dim X As New SimpleClass
End Sub
X ) (Managed Heap
X
! ) .(3- 3
)
4- 3 (.
w w.pdf actory.com
:
127
.NET
- .Garbage Collection
:Circular Reference
Garbage Collection
.Circular Reference
) (Counter
.
Circular Reference .
)
.NET (Garbage Collection
w w.pdf actory.com
128
:
Class PersonClass
Public Name As String
Public Brother As PersonClass
End Class
:
)(Dim Turki As New PersonClass
)(Dim Abdullah As New PersonClass
" " = Turki.Name
" " = Abdullah.Name
Brother
Turki.Brother = Abdullah
Adbdullah.Brother = Turki
Turki Abdullah
w w.pdf actory.com
:
129
'
Turki.Brother = Nothing
Abdullah.Brother = Nothing
'
Turki = Nothing
Abdullah = Nothing
w w.pdf actory.com
130
:
:Garbage Collection
)
(J Windows API
Garbage
.Collection
) (6- 3
Brother Garbage
Collection .
Managed Heap
Garbage Collection
Garbage Collection
)( Collect :GC
)(GC.Collect
)(GC.WaitForPendingFinalizers
)( GC.Collect
- -
w w.pdf actory.com
:
131
.NET Framework
)( WaitForPendingFinalizers
Thread .
Threading .Threading
Garbage Collection
Managed Heap :
)( Sub Test
)(Dim TestObject As New TestClass
End Sub
TestObject
.Garbage Collection
Garbage
) Collection (:
Class TestClass
End Sub
End Class
w w.pdf actory.com
132
:
Protected
Overrides )( Finalize
System.Object .
)( Finalize
OOP
.Garbage Collection
)() Finalize
ArabicConsole(
. )( Finalize
.
.NET )( Dispose :
Class TestClass
Implements IDisposable
Public Sub Dispose() Implements System.IDisposable.Dispose
End Sub
End Class
w w.pdf actory.com
:
133
Implements Interfaces
.
)( Dispose
)
...(:
'
)(TestObject.Dispose
'
TestObject = Nothing
- )( Dispose
)( Finalize )( Dispose :
)( Dispose
:
CancelDisposing = True
End Sub
w w.pdf actory.com
134
:
)( Finalize )(:Dispose
)( Dispose
)
(:
'
)(TestObject.Dispose
'
'
)( TestObject.MethodInClass
)( Dispose
:Exit Sub
Class TestClass
End Sub
Public Sub Dispose() Implements System.IDisposable.Dispose
If CancelDisposing Then
Exit Sub
End If
CancelDisposing = True
End Sub
End Class
w w.pdf actory.com
:
135
)( Sub MethodInClass
'
)(' Dispose
If CancelDisposing Then
)"Throw New ObjectDisposedException("TestClass
End If
End Sub
End Class
Throw an Exception
Run Time Error
.
)( Dispose )( Finalize
-
:
- )( Finalize
Garbage Collection
)( Dispose Garbage
Collection
w w.pdf actory.com
136
:
. )( GC.SuppressFinalize
)( Dispose Garbage Collection )(:Finalize
Class TestClass
)( Dispose
)( Finalize
) ( .
)( Dispose
.Garbage Collection
Overloads )( Dispose
)
( )() Finalize (
)( Finalize )() Dispose .NET
(Framework:
Class TestClass
Implements IDisposable
w w.pdf actory.com
:
137
. ByVal
ByRef ByVal
. ByRef
) ( :
'
)Sub ByValSub(ByVal TestObject As TestClass
TestObject = Nothing
End Sub
'
'
)Sub ByRefSub(ByRef TestObject As TestClass
TestObject = Nothing
End Sub
w w.pdf actory.com
138
:
ByRef
Visual Basic .NET ) (:
Shared Members
.
Shared Fields
Shared Fields
Shared .
Class TestShared
Public FirstName As String
Shared Public LastName As String
End Class
FirstName
:
)ArabicConsole.WriteLine(Meshari.FirstName
)ArabicConsole.WriteLine(Turki.FirstName
w w.pdf actory.com
:
139
LastName
. :
"" = Meshari.LastName
"" = Turki.LastName
'
'
)ArabicConsole.WriteLine(Meshari.LastName
)ArabicConsole.WriteLine(Turki.LastName
' TestShared
' Turki
"" = TestShared.LastName
- :
Class TestShared
Public Shared NumOfObjects As Integer = 0
)(Sub New
NumOfObjects += 1
End Sub
End Class
NumOfObjects
:TestShared
)ArabicConsole.WriteLine(ObjectOne.NumOfObjects
)(Dim ObjectThree As New TestShared
' 3
)ArabicConsole.WriteLine(ObjectThree.NumOfObjects
w w.pdf actory.com
140
:
)(Sub New
NumOfObjects += 1
If NumOfObjects > 10 Then
'
: '
'
)(Throw New Exception
End If
End Sub
Shared Methods
Shared Methods
Object Instance
:
Class TestShared
)( CheckNumOfObjects :
Dim X As TestShared
If TestShared.CheckNumOfObjects < 10 Then
)(X = New TestShared
)ArabicConsole.WriteLine(X.NumOfObjects
End If
w w.pdf actory.com
:
141
.
:
'
)(' SharedFun
'
Class My_Class
Public X As Integer
Public Shared Function SharedFun() As Integer
Return X
End Function
End Class
ArabicConsole )( WriteLine
)( WriteLine
:
)" "(ArabicConsole.WriteLine
Module
Sub Main
Shared Properties
:
w w.pdf actory.com
142
:
End Get
)Set (ByVal Value As Integer
End Set
End Property
Shared Events
) (
. Shared:
Class PersonClass
)(Event Die
' )(Shared Event AllDie
)(Sub KillHim
)(RaiseEvent Die
End Sub
)(Shared Sub EarthQuick
)(RaiseEvent AllDie
End Sub
End Class
)( EarthQuick )
(
AllDie
Die :
Module Module1
)(Sub Main
)(Dim Turki As New PersonClass
)(Dim Ali As New PersonClass
'
AddHandler Turki.Die, AddressOf PersonDie
AddHandler Ali.Die, AddressOf PersonDie
w w.pdf actory.com
:
143
)(Turki.KillHim
)(Ali.KillHim
End Sub
)(Sub PersonDie
)" "(ArabicConsole.WriteLine
End Sub
End Module
Die )(PersonDie
)( KillHim
AllDie
:
Module Module1
)(Sub Main
)(Dim Turki As New PersonClass
)(Dim Ali As New PersonClass
'
AddHandler PersonClass.AllDie, AddressOf PersonDie
)(Turki.EarthQuick
)(Ali.EarthQuick
EarthQuick '
'
)(PersonClass.EarthQuick
End Sub
)(Sub PersonDie
)" "(ArabicConsole.WriteLine
End Sub
End Module
Windows
.
w w.pdf actory.com
144
:
: .NET
Visual
.NET
.
.NET Framework
.
.
sender :e
Class PersonClass
)Event Die(ByVal sender As Object, ByVal e As System.EventArgs
End Class
sender e Parameters
Die
Class PersonClass
)(Sub KillHim
))(RaiseEvent Die(Me, New System.EventArgs
End Sub
End Class
WithEvents :AddHandler
w w.pdf actory.com
:
145
Module Module1
Sub Main()
Dim Turki As New PersonClass()
AddHandler Turki.Die, AddressOf PersonHasDied
Turki.KillHim()
End Sub
Sub PersonHasDied(ByVal sender As Object, ByVal e As _
System.EventArgs)
ArabicConsole.WriteLine(")"
End Sub
End Module
) .NET
(Inherits System.EventArgs
:Travel
Class TravelEventArgs
Inherits System.EventArgs
Public FromCity As String
Public ToCity As String
Sub New(ByVal fromCity As String, ByVal toCity As String)
Me.FromCity = fromCity
Me.ToCity = toCity
End Sub
End Class
: PersonClass
Class PersonClass
Event Travel(ByVal sender As Object, ByVal e As TravelEventArgs)
Sub Move(ByVal fromCity As String, ByVal toCity As String)
RaiseEvent Travel(Me, New TravelEventArgs(fromCity, toCity))
End Sub
End Class
w w.pdf actory.com
146
:
Travel
) WithEvents :(AddHandler
Module Module1
)(Sub Main
)(Dim Turki As New PersonClass
AddHandler Turki.Travel, AddressOf PersonHasTraveld
)"" ","(Turki.Move
End Sub
Sub PersonHasTraveld(ByVal sender As Object, ByVal e As
)TravelEventArgs
_ " & e.FromCity "(ArabicConsole.WriteLine
) " & e.ToCity" &
End Sub
End Module
.NET Framework .
.
w w.pdf actory.com
.NET Framework .
.NET Framework .
Visual
Basic .NET
w w.pdf actory.com
148
:
.
) Person( )(Employee
.NET Framework
)
:(1- 4
Class TestClass
'
End Class
:1- 4 .
w w.pdf actory.com
:
149
System.Object
.NET Framework
.
- -OOP Is a
Employee .Person
Class Person
Public Name As String
Public Age As Integer
End Class
Inherits :
Class Employee
Inherits Person ' Person
Public Job As String
Public Salary As Double
End Class
)(Sub Main
)(Dim Turki As New Employee
'
" " = Turki.Name
'
" " = Turki.Job
w w.pdf actory.com
150
:
'
'
)ArabicConsole.WriteLine(Turki.Name
)ArabicConsole.WriteLine(Turki.Job
End Sub
Employee Person
Person (:
Person :
Class Student
Inherits Person
Public Department As String
Public Grade As Integer
End Class
Driver
Employee ) Person 2- 4 (:
Class Driver
Inherits Employee
Public CarModel As String
Public LicenseNumber As String
End Class
w w.pdf actory.com
:
151
:2- 4 .
Driver Employee
:Person
' Employee
" " = Abbas.Job
' Driver
"Abbas.CarModel = "BMW - 7 Class
OOP ) -4
(2
Containment .
w w.pdf actory.com
152
:
'
Class Thing
Inherits Person
Inherits Animal
End Class
Base Classes
Derived Classes Visual Basic
.NET Inherits
. .
)
( :
Class Person
'
)(Event Die
'
Private m_BirthDate As Date
Property BirthDate() As Date
Get
Return m_BirthDate
End Get
)Set(ByVal Value As Date
m_BirthDate = Value
End Set
End Property
'
)(Sub KillHim
)(RaiseEvent Die
End Sub
End Class
Inherits
:
w w.pdf actory.com
:
153
Module Module1
)(Sub Main
)(Dim Turki As New Employee
'
AddHandler Turki.Die, AddressOf PersonHasDied
'
Turki.BirthDate = #1/1/9999#
'
)(Turki.KillHim
End Sub
)(Sub PersonHasDied
)" "( ArabicConsole.WriteLine
End Sub
End Module
Shared Members
Class Person
Public Shared LastName As String
End Class
) Person (Employee :
'
'
'
' )ArabicConsole.WriteLine(Abdullah.LastName
w w.pdf actory.com
154
:
Class Employee
Inherits Person
)(Sub MethodInEmployee
'
" " = Me.Name
Me.Age = 99
End Sub
End Class
Overriding
Overriding .
Constructors
. :
:
Class Person
'
End Class
Class Employee
Inherits Person
'
)Sub New(ByVal Job As String
Me.Job = Job
End Sub
End Class
w w.pdf actory.com
:
155
Employee
:
)(Sub Main
'
)" "(Dim Turki As New Employee
" " = Turki.Name
)ArabicConsole.WriteLine(Turki.Job
End Sub
MyBase ) Me MyBase( .
:
Class Person
'
)Sub New(ByVal Name As String
Me.Name = Name
End Sub
End Class
Class Employee
Inherits Person
'
'
)(Sub New
)" "(MyBase.New
End Sub
End Class
. Employee
:
w w.pdf actory.com
156
:
)(Sub Main
'
)(Dim Turki As New Employee
" " = Turki.Job
)ArabicConsole.WriteLine(Turki.Name
End Sub
Class Person
End Sub
End Module
w w.pdf actory.com
:
157
MyBase
:
)Sub New(ByVal Name As String, ByVal Job As String
'
'
Me.Job = Job
)MyBase.New(Name
End Sub
Object :
:
- .NET ) Object
,(System.Object
Person
w w.pdf actory.com
158
:
'
Turki2.Salary = 1
Person
:Person
'
)PrintInfo(Turki
)PrintInfo(Ali
)PrintInfo(Umar
Employee :Person
'
' Option Strict Off
Dim Abood As Person
Dim Abood2 As Employee
w w.pdf actory.com
:
159
Option Strict On
) ( :CType
'
' Option Strict On
CType
.
OOP
Polymorphism
.
Overriding
)( ShowName Person
:Employee
Class Person
"" = Public FirstName As String
"" = Public LastName As String
)(Sub ShowName
)ArabicConsole.WriteLine(Me.FirstName & " " & Me.LastName
End Sub
End Class
w w.pdf actory.com
160
:
Class Employee
Inherits Person
End Class
Employee
)( ShowName
:Person
Class Person
)(Sub ShowName
)ArabicConsole.WriteLine(Me.LastName & ", " & Me.FirstName
End Sub
End Class
!
Person
) (
)( ShowName
Employee
.Overriding
:Overridable
Class Person
"" = Public FirstName As String
"" = Public LastName As String
'
'
)(Overridable Sub ShowName
)ArabicConsole.WriteLine(Me.FirstName & " " & Me.LastName
End Sub
End Class
w w.pdf actory.com
:
161
Overrides :
Class Employee
Inherits Person
'
)(Overrides Sub ShowName
)ArabicConsole.WriteLine(Me.LastName & ", " & Me.FirstName
End Sub
End Class
Person
Employee :
)(Abbas.ShowName
)(Abbas2.ShowName
Methods Properties .
Overridable
.Overrides
Overrides Overridable
Employee
) Driver(
:Overrides
Class Driver
Inherits Employee
)(Overrides Sub ShowName
'
End Sub
End Class
w w.pdf actory.com
162
:
.Overrides )( ShowName
Employee :NotOverridable
Class Employee
Inherits Person
'
'
)(NotOverridable Overrides Sub ShowName
)ArabicConsole.WriteLine(Me.LastName & ", " & Me.FirstName
End Sub
End Class
:ReadOnly
Class Person
'
Overridable ReadOnly Property BirthDate() As Date
Get
End Get
End Property
End Class
WriteOnly :
w w.pdf actory.com
:
163
Class Employee
Inherits Person
'
Overrides WriteOnly Property BirthDate() As Date
)Set(ByVal Value As Date
End Set
End Property
End Class
. Default Properties
Default Properties
.
)(:
)(Abbas.ShowName
)(Abbas2.ShowName
Abbas Person
.Employee
w w.pdf actory.com
164
:
:Overloading
- )
( Overloads
:Overrides
Class BaseClass
)(Overloads Sub TestMethod
)" "(ArabicConsole.WriteLine
End Sub
End Class
Class DerivedClass
Inherits BaseClass
)Overloads Sub TestMethod(ByVal x As Integer
)" "(ArabicConsole.WriteLine
End Sub
End Class
Overloads
Class BaseClass
)(Overloads Sub TestMethod
)" "(ArabicConsole.WriteLine
End Sub
End Class
Class DerivedClass
Inherits BaseClass
'
'
)(Overloads Sub TestMethod
)" "(ArabicConsole.WriteLine
End Sub
End Class
! :
w w.pdf actory.com
:
165
)(obj.TestMethod
)(obj2.TestMethod
Overriding Overloading
Overrides Overloads .
:
Class BaseClass
Overrides
Overloads
:
w w.pdf actory.com
'
'
)(obj.TestMethod
)(obj2.TestMethod
'
'
)(obj.TestMethod2
)(obj2.TestMethod2
166
:
Overloads Overrides
Shadowing
.
MyBase
Me
MyBase . Me
:MyBase
Class BaseClass
)(Sub MethodInBase
End Sub
End Class
Class DerivedClass
Inherits BaseClass
)(Sub MethodInDerived
'
)(MyBase.MethodInBase
'
)(Me.MethodInBase
End Sub
End Class
Me
Overrided :
Class BaseClass
End Sub
End Class
w w.pdf actory.com
:
167
Class DerivedClass
Inherits BaseClass
End Sub
)(Sub TestMethod
'
)(MyBase.MyMethod
'
)(Me.MyMethod
End Sub
End Class
Me - MyBase
.
MyBase Me Private
- Me MyBase
:
Class BaseClass
Private fieldBase As Integer
End Class
Class DerivedClass
Inherits BaseClass
Private fieldDerived As Integer
)(Sub Test
'
Me.fieldDerived = 99
'
MyBase.fieldBase = 99
End Sub
End Class
Private .
w w.pdf actory.com
168
:
MyBase
)( Finalize )( Dispose
:
Class DerivedClass
Inherits BaseClass
End Sub
End Class
)( Finalize )( Dispose
Protected
.
)( MyBase.Finalize
Finalize
MyClass
Me
) (
Class BaseClass
)(Sub Test
Me '
'
)(Me.OverridedMethod
End Sub
w w.pdf actory.com
:
169
:Me
MyClass
:Me
Class BaseClass
)(Sub Test
'
)(MyClass.OverridedMethod
End Sub
End Class
Shadowing
Shadowing
) DLL(
:Overridable
Class BaseClass
)(Sub Method
End Sub
End Class
w w.pdf actory.com
170
:
) (Overrides
Overridable
Visual
Basic .NET )
Warnning (:
Class DerivedClass
Inherits BaseClass
)(Sub MyMethod
End Sub
End Class
: )( MyMethod Shadows
)( MyMethod
:
Shadows )
Warnings (:
Class DerivedClass
Inherits BaseClass
)(Shadows Sub MyMethod
End Sub
End Class
Warnings
.
w w.pdf actory.com
:
171
Overloading :
Overloads
:Shadows
Class DerivedClass
Inherits BaseClass
' Overloads
)(Overloads Sub MyMethod
End Sub
End Class
Shadows Overloads
Shadows Overloads
. - Shadows
Overloads
Class A
)(Sub MyMethod
)"ArabicConsole.WriteLine("A.MyMethod
End Sub
)Sub MyMethod(ByVal x As Integer
)")ArabicConsole.WriteLine("A.MyMethod (x
End Sub
)(Sub MyMethod2
)"ArabicConsole.WriteLine("A.MyMethod2
End Sub
)Sub MyMethod2(ByVal x As Integer
)")ArabicConsole.WriteLine("A.MyMethod2 (x
End Sub
End Class
Overloads
:Shadows
w w.pdf actory.com
172
:
Class B
Inherits A
)(Overloads Sub MyMethod
)"ArabicConsole.WriteLine("B.MyMethod
End Sub
)(Shadows Sub MyMethod2
)"ArabicConsole.WriteLine("B.MyMethod2
End Sub
End Class
:
)(Dim obj As New B
obj.MyMethod() ' B.MyMethod
)obj.MyMethod(10
)' A.MyMethod (x
)(obj.MyMethod2
' B.MyMethod2
) obj.MyMethod2 (x
Shadows
)( MyMethod .
:Subclassing
(
:
Class B
Inherits A
w w.pdf actory.com
:
173
Subclassing :
Class B
Inherits A
End If
End Sub
End Class
Shared Members
End Sub
End Class
Class DerivedClass
Inherits BaseClass
'
)(Shared Shadows Sub MyMethod
End Sub
End Class
MyBase
w w.pdf actory.com
174
:
Class DerivedClass
Inherits BaseClass
)(Shared Shadows Sub MyMethod
'
)( MyBase.MyMethod
' )( BaseClass.MyMethods
End Sub
End Class
NotInheritable
NotInheritable :
'
NotInheritable Class MyClass
End Class
ArabicConsole Console :
Class DerivedClass
! ' Inherits ArabicConsole
End Class
MustInherit
MustInherit
w w.pdf actory.com
:
175
End Class
DerivedClass( :
Abstract Classes
) (dev4arabs.com
)(Sub Delete
End Sub
)(Overridable Sub Update
End Sub
)(Overridable Sub AddNew
End Sub
End Class
w w.pdf actory.com
176
:
'
Class SourceCode
Inherits Item
End Class
'
Class Tip
Inherits Item
End Class
'
Class Article
Inherits Item
Public Introduction As String
End Sub
)(Public Overrides Sub AddNew
End Sub
End Class
MustOverride
Item :
)(Sub ShowDate
End Sub
End Class
MustOverride
w w.pdf actory.com
:
177
MustOverride
MustInherit
.
Visibility:
:
:Private
Private
- Module Structure
Class :
'
Private Class TestClass
End Class
w w.pdf actory.com
178
:
Module Module1
'
Private Class TestClass
End Class
End Module
Nested Private
Class Outer
Private Class Inner
End Class
End Class
Module Module1
)(Sub Main
' )(Dim X As New Outer.Inner
End Sub
End Module
Inner Outer
:Outer
Class Outer
Private Class Inner
End Class
Class Inner2
' Public X As Inner
End Class
End Class
:Friend
) Friend (
Friend :
w w.pdf actory.com
:
179
End Class
End Class
Module Module1
)(Sub Main
' )(Dim X As New Outer.Inner
End Sub
End Module
Friend Private
C:
Class A
Private Class B
Friend Class C
End Class
End Class
End Class
B .Friend
Friend B
:
Class A
Class B
End Class
End Class
:
' )(Dim obj As New A.B
' )(Dim obj As New B
w w.pdf actory.com
180
:
:Public
Friend Public Friend
. Public
Class Library DLL.
:Protected
Inner:
Class BaseClass
Protected Class Inner
End Class
End Class
BaseClass:
Class DerivedClass
Inherits BaseClass
' Private X As Inner
End Class
Module Module1
)(Sub Main
' Dim X As Inner
End Sub
End Module
BaseClass Inner
Inner Private :
Class DerivedClass
' Inherits Inner
End Class
w w.pdf actory.com
:
181
:Protected Friend
Protected Friend
Friend Friend Protected Friend
Inner:
Class BaseClass
Friend Class Inner
End Class
Protected Friend Class Inner2
End Class
End Class
Inner2
.
.
:Private
Private
Fields Private :
Class TestClass
Dim Private ' Dim X As Integer
)(Private Sub MyMethod
End Sub
End Class
Events Private :
w w.pdf actory.com
182
:
Class TestClass
)(Private Event MyEvent
)(Public Sub MySub
AddHandler Me.MyEvent, AddressOf Me.EventHandler
End Sub
)(Public Sub EventHandler
End Sub
End Class
:Private
Class Outer
Private X As Integer
Class Inner
' Dim obj As Outer
)(Sub MyMethod
' obj.X = 10
End Sub
End Class
End Class
:Friend
Friend )
( Public Friend
Private :
Class TestClass
Friend X As Inner
Friend Sub MyMethod () ' Friend
End Sub
Sub MyMethod2 () ' Public
End Sub
w w.pdf actory.com
:
183
End Class
Friend
) Private (:
Class Outer
' Friend X As Inner
Private Class Inner
End Class
End Class
:Public
Public ) Friend
(Public
Public Friend .
:Protected
Protected ) Private
Private Protected( :
Class BaseClass
Protected X As Integer
End Class
X :BaseClass
Class DerivedClass
Inherits BaseClass
)(Sub MyMethod
Me.X = 10
End Sub
End Class
w w.pdf actory.com
184
:
:Protected Friend
End Sub
End Class
Public
TestClass
) ( )
New( . .Not Creatable Class
:Private
Private
.
w w.pdf actory.com
:
185
:Friend
Friend
.
:Public
:Protected
Protected
End Sub
End Class
:
Class DerivedClass
Inherits BaseClass
)(Public x As New BaseClass
End Class
:Protected Friend
Friend
w w.pdf actory.com
186
:
Public Friend
Assembly
.Assemblies
.NET Framework
OOP -
w w.pdf actory.com
Visual Basic .NET
Interfaces Polymorphism
Delegates
Attributes
.Visual Basic .NET
.OOP Interface
:
Class Person
)(Event Die
Public Property Name() As String
End Property
)(Sub Move
End Sub
End Class
w w.pdf actory.com
188
:
OOP Polymorphism
Polymorphism
TextFile
RTFFile HTMLFile
XMLFile PictureFile
FileName
FileSize )( Save )( Delete
.
:TextFile
FileObject.Save
End Sub
:
)Sub SaveRTFFile(ByVal FileObject As RTFFile
FileObject.Save
End Sub
)Sub SaveHTMLFile(ByVal FileObject As HTMLFile
FileObject.Save
End Sub
w w.pdf actory.com
:
189
Case 2
"RTFFileObject.FileName = "xxxx
) RTFRTFFile ( RTFFileObject
Case 3
"HTMLFileObject.FileName = "xxxx
) HTMLTextFile ( HTMLFileObject
End Sub
BinaryFile
IFile
:IFile
)( FileObject.Save
End Sub
w w.pdf actory.com
190
:
)TextFile
IFile
. Visual Basic .NET
'
)(Sub Save
)Sub Save(ByVal TargetFile As String
)(Sub Delete
End Interface
OOP I
.NET
PascalCase .
Visibility Friend
w w.pdf actory.com
:
191
' Friend
Interface IFile
End Interface
' Public
Public Interface IView
End Interface
Module Module1
' Private
Private Interface ITool
End Interface
Sub Main()
End Sub
End Module
: Public
Interface ITest
'
'
Public Sub MyMethod ()
Private Sub YourMethod ()
End Interface
:Nested
Interface IView
Interface IWindow
End Interface
Interface IWEB
End Interface
End Interface
w w.pdf actory.com
192
:
Interface IMyInterface
' X As Inetger
End Interface
:Implement
Class TextFile
' Implements IFile
End Class
Class TextFile
Implements IFile
' FileName
Property FileName() As String Implements IFile.FileName
Get
End Get
)Set(ByVal Value As String
End Set
End Property
)(' Delete
Sub Delete() Implements IFile.Delete
End Sub
'
End Class
w w.pdf actory.com
:
193
) .(1- 5
:1- 5 .
.Functions ) ReadOnly
(WriteOnly .
TestClass :%100
Interface IMyInterface
'
ReadOnly Property BirthDate() As Date
'
Function MyMethod() As String
End Interface
w w.pdf actory.com
194
:
Class TestClass
Implements IMyInterface
'
Public WriteOnly Property BirthDate() As Date Implements _
IMyInterface.BirthDate
Set(ByVal Value As Date)
End Set
End Property
'
Public Function MyMethod() As Integer Implements _
IMyInterface.MyMethod
End Function
End Class
Interface IView
Interface IWindow
End Interface
Interface IWEB
End Interface
End Interface
Class TestClass
Implements IView.IWindow '
End Class
:
Class TestClass2
Implements IView
End Class
w w.pdf actory.com
:
195
IView
) IWindow (IWeb .
:
Class ManyInterfaces
Implements IFile
Implements IView
Implements IView.IWindow
Implements IView.IWEB
End Class
)( MyMethod IView
IFile :
Class ManyInterfaces
Implements IFile
Implements IView
End Sub
'
Sub MyMethod2() Implements IView.MyMethod
End Sub
End Class
Implements
:
w w.pdf actory.com
196
:
Class ManyInterfaces
Implements IFile
Implements IView
End Sub
End Sub
End Class
:IFile
Sub DoSave(ByVal fileObject As IFile)
fileObject.Save ()
End Sub
w w.pdf actory.com
:
197
)DoSave (htmlFileObject
Interface IMyInterface
)(Sub MyMethod
End Interface
Class BaseClass
Implements IMyInterface
Sub MyMethod() Implements IMyInterface.MyMethod
End Sub
End Class
BaseClass IMyInterface
Class DerivedClass
Inherits BaseClass
End Class
DerivedClass :BaseClass
)(Dim DerivedObject As New DerivedClass
Dim X As IMyInterface
X = DerivedObject
'
)(X.MyMethod
w w.pdf actory.com
198
:
: Inherits
Interface IBaseInterface
Sub MyMethodInBase()
End Interface
Interface IDerivedInterface
Inherits IBaseInterface
Sub MyMethodInDerived()
End Interface
IDerivedInterface
:
Class TestClass
Implements IDerivedInterface
'
Sub MyMethodInBase() Implements IDerivedInterface.MyMethodInBase
End Sub
'
Sub MyMethodInDerived() Implements
IDerivedInterface.MyMethodInDerived
End Sub
End Class
.NET Framework
IDisposable
: Destructors Dispose()
Class TestClass
Implements IDisposable
Public Sub Dispose() Implements System.IDisposable.Dispose
End Sub
End Class
w w.pdf actory.com
:
199
.NET Framework
IComparable
)>
<... => ( Strings
ASCII
UNICODE :
Dim X As Integer = 10
"" = Dim Y As String
If X > 5 Then
" Then" < If Y
Person
IComparable
)( CompareTo 1-
0 1 :
Class Person
Implements IComparable
Public Name As String
_ Function CompareTo(ByVal obj As Object) As Integer Implements
System.IComparable.CompareTo
)Dim tempObj As Person = CType(obj, Person
'
If Me.Name < tempObj.Name Then
Return -1
'
ElseIf Me.Name > tempObj.Name Then
Return 1
w w.pdf actory.com
200
:
'
Else
Return 0
End If
End Function
End Class
Name
: Age
Class Person
Implements IComparable
Public Age As Integer
Function CompareTo(ByVal obj As Object) As Integer Implements _
System.IComparable.CompareTo
Dim tempObj As Person = CType(obj, Person)
' Age
If Me.Age < tempObj.Age Then
Return -1
ElseIf Me.Age > tempObj.Age Then
Return 1
Else
Return 0
End If
End Function
End Class
IComparable Person
) .NET Framework
w w.pdf actory.com
:
201
Array.Sort '
' IComparable
)Array.Sort(PersonObject
)For Counter = 0 To UBound(PersonObject
)ArabicConsole.WriteLine(PersonObject(Counter).Age
Next
ICloneable
'
'
Ali = Turki
.NET ICloneable
)( Clone
:
Class Person
Implements ICloneable
Public Name As String
Public Age As Integer
Function Clone() As Object Implements ICloneable.Clone
'
)(Dim tmpObject As New Person
'
'
tmpObject.Name = Me.Name
tmpObject.Age = Me.Age
w w.pdf actory.com
202
:
'
Return tmpObject
End Function
End Class
Static (
)( MemberwiseClone ) System.Object
.NET :(System.Object
Class Person
Implements ICloneable
Public Name As String
Public Age As Integer
Function Clone() As Object Implements ICloneable.Clone
'
)(Return Me.MemberwiseClone
End Function
End Class
:
)(Dim Turki As New Person
Dim Ali As Person
"" = Turki.Name
'
)Ali = CType(Turki.Clone, Person
"" = Ali.Name
'
)ArabicConsole.WriteLine(Turki.Name
CType
Option Strict On
w w.pdf actory.com
:
203
)( Clone
Class Person
Implements ICloneable
)( Clone :CType
Ali = Turki.Clone
ICloneable
) )( (MemberwiseClone
.
Object
.Serialization .
IEnumerable IEnumerator
For Each Next
Arrays Collections
IEnumerable IEnumerator
For Each
SplitString
Sentence :
w w.pdf actory.com
204
:
Class SplitString
Private currentPosition As Integer = 0
'
Private m_Sentence As String
Property Sentence() As String
Get
Return m_Sentence
End Get
Set(ByVal Value As String)
m_Sentence = Value
Me.Reset()
End Set
End Property
End Class
: IEnumerator IEnumerable
Class SplitString
Implements IEnumerable
Implements IEnumerator
End Class
GetEnumerator() IEnumerable
For Each
: Return Me .IEnumerator
Class SplitString
w w.pdf actory.com
:
205
IEnumerator
Reset()
: For Each
Class SplitString
Current
:ReadOnly
Class SplitString
w w.pdf actory.com
206
:
w w.pdf actory.com
:
207
SplitString
IEnumerable IEnumerator
.NET
Framework .
IEnumerable IEnumerator
IEnumerable
IEnumerator OOP
.
:Delegates
:
)Sub MySub (ByVal X As Integer
End Sub
)Sub YourSub (ByVal X As Integer
End Sub
:
' Dlgt
'
)Dlgt.Invoke (100
w w.pdf actory.com
208
:
. - -
) ( Shared
C\C++
Function
Pointers .
C\C++
(Functions Classes )
(Shared .Modules
:Delegates
Module Module1
'
'
Delegate Function OneParameter(ByVal X As Integer) As Integer
)(Sub Main
End Sub
End Module
w w.pdf actory.com
:
209
:
Function Abs(ByVal x As Integer) As Integer
If x < 0 Then
Return -x
Else
Return x
End If
End Function
Function Square(ByVal x As Integer) As Integer
Return x * x
End Function
) OneParameter
(Delegate :
)( Sub Main
)( ' Abs
)Dim Dlgt As New OneParameter(AddressOf Abs
End Sub
)( Abs )(Invoke
)( Sub Main
)Dim Dlgt As New OneParameter(AddressOf Abs
'
ArabicConsole.WriteLine( Dlgt.Invoke(-5) ) ' 5
End Sub
)( Square )
(AddressOf Dlgt
)(:Invoke
)( Sub Main
)( ' Square
Dlgt = AddressOf Square
ArabicConsole.WriteLine( Dlgt.Invoke(-5) ) ' 25
End Sub
w w.pdf actory.com
210
:
OneParameter
:
)(Sub Main
)Dim Dlgt As New OneParameter(AddressOf Abs
)MySub(Dlgt
End Sub
' OneParameter
)Sub MySub(ByVal delegatePointer As OneParameter
))ArabicConsole.WriteLine(delegatePointer.Invoke(-5
End Sub
Delegates :OneParameter
OneParameter
) System.MulticastDelegate (System.Delegate
:OneParameter
'
Class OneParameter
Inherits System.MulticastDelegate
End Class
New
w w.pdf actory.com
:
211
Dlgt
) )( Invoke (
:
)Dim Dlgt As New OneParameter(AddressOf Abs
Dim X As OneParameter
'
X = Dlgt
ArabicConsole.WriteLine(X.Invoke(-5)) ' 5
) (AddressOf :
Class TestClass
)(Sub TestMethod
)" "(ArabicConsole.WriteLine
End Sub
End Class
Module Module1
)(Delegate Sub NoParameter
)(Sub Main
)(Dim testObject As New TestClass
' testObject
)Dim dlgt As New NoParameter(AddressOf testObject.TestMethod
)(dlgt.Invoke
End Sub
End Module
w w.pdf actory.com
212
:
Class TestClass
Sub InstanceMethod()
End Sub
Shared Sub SharedMethod()
'
InstanceMethod()
End Sub
End Class
: Global Variables
Class TestClass
Sub InstanceMethod()
ArabicConsole.WriteLine(")"
End Sub
Shared Sub SharedMethod(ByVal methodPointer As NoParameter)
methodPointer.Invoke()
End Sub
End Class
Module Module1
Delegate Sub NoParameter()
Sub Main()
Dim testObject As New TestClass()
Dim dlgt As New NoParameter(AddressOf
testObject.InstanceMethod)
' InstanceMethod()
' SharedMethod()
testObject.SharedMethod(dlgt)
End Sub
End Module
Events
: Die Delegates
Class Person
Event Die()
Sub Kill()
RaiseEvent Die()
End Sub
End Class
w w.pdf actory.com
:
213
Module Module1
)(Sub Main
)(Dim Turki As New Person
AddHandler Turki.Die, AddressOf PeronHasDied
)(Turki.Kill
End Sub
)(Sub PeronHasDied
)" "(ArabicConsole.WriteLine
End Sub
End Module
Die
.AddHandler
) NoParameter(
Die )( Invoke
.RaiseEvent
:
)(Delegate Sub NoParameter
Class Person
Public Die As NoParameter
)(Sub Kill
)(Die.invoke
End Sub
End Class
Module Module1
)(Sub Main
)(Dim Turki As New Person
)Turki.Die = New NoParameter(AddressOf PeronHasDied
)(Turki.Kill
End Sub
)(Sub PeronHasDied
)" "(ArabicConsole.WriteLine
End Sub
End Module
w w.pdf actory.com
214
:
)(Sub MySub1
)" "(ArabicConsole.WriteLine
End Sub
)(Sub MySub2
)" "(ArabicConsole.WriteLine
End Sub
-
)(:Invoke
)(Delegate Sub NoParameter
)( sub Main
)Dim dlgt As New NoParameter(AddressOf MySub1
)Dim dlgt2 As New NoParameter(AddressOf MySub2
)(dlgt.Invoke
)(dlgt2.Invoke
End Sub
)( Combine
)( MySub1 )( MySub2
)( .Invoke :
w w.pdf actory.com
:
215
:
)(Delegate Sub NoParameter
)(Sub Main
Dim dlgt As NoParameter
_ dlgt = dlgt.Combine(New NoParameter(AddressOf MySub1),
))New NoParameter(AddressOf MySub2
MySub1 ' MySub2
)(dlgt.Invoke
End Sub
dlgt .
System.Delegate CType
Option Strict On:
dlgt
)( Invoke ) (:
'
_ dlgt = CType(dlgt.Combine(dlgt, New NoParameter(AddressOf MySub3)),
)NoParameter
'
)(' MySub1
)(' MySub2
)(' MySub3
'
)(dlgt.Invoke
Function
w w.pdf actory.com
216
:
Module Module1
Delegate Function NoParameterFun() As Boolean
Sub Main()
Dim dlgt As New NoParameterFun(AddressOf MyFunction1)
Dim dlgt2 As New NoParameterFun(AddressOf MyFunction2)
dlgt = CType(dlgt.Combine(dlgt, dlgt2), NoParameterFun)
ArabicConsole.WriteLine(dlgt.Invoke()) ' True
End Sub
Function MyFunction1() As Boolean
Return False
End Function
Function MyFunction2() As Boolean
Return True
End Function
End Module
:Remove()
Remove()
.
. GetInvocationList
:
dlgt.Remove(dlgt, dlgt.GetInvocationList(0))
ArabicConsole.WriteLine(dlgt.Invoke()) ' True
w w.pdf actory.com
:
217
-
Source Codes
Textual .Compiler
.
Compiler
.
Structure .
Attributes .NET .
Classes
> <
>)"<System.ComponentModel.DefaultProperty ("XXX
Namespace Imports
Imports System.ComponentModel
>)"<DefaultProperty ("XXX
w w.pdf actory.com
218
:
. DebuggerStepThrough
End Sub
_
:
_ >)(<System.Diagnostics.DebuggerStepThrough
)(Sub MySub
End Sub
.NET Framework
.NET Framework
Visual Basic .NET
Conditional Attribute
#If :
End Sub
#End If
w w.pdf actory.com
:
219
Sub Main
)( MySub
)( MySub
End Sub
)( MySub )
MyCondition (False
- )( MySub
#If :
Sub Main
#If MyCondition Then
)( MySub
#End If
End Sub
)( MySub :
)( Sub MySub
#If MyCondition Then
#End If
End Sub
MyCondition False
) )( MySub(
- .
w w.pdf actory.com
220
:
:Sub
_ >)"<Conditional("MyCondition
)(Sub MySub
End Sub
Sub Main
)( MySub
)( MySub
End Sub
)( MySub
MyCondition .False
Conditional
.Function
MyCondition
Project Property Pages
w w.pdf actory.com
:
221
DebuggerStepThrough Attributes
Debugging
System.Diagnostics.DebuggerStepThrough
_ >)(<System.Diagnostics.DebuggerStepThrough
)(Sub MySub
End Sub
Obsolete Attribute
Warning
w w.pdf actory.com
222
:
_ >)" "(<Obsolete
)(Sub MySub
End Sub
Warning ) Output
:3- 5 Warning .
Obsolete Boolean
True
End Sub
.Obsolete
w w.pdf actory.com
:
223
FieldOffset StructLayout
Structure StructLayout
: LayoutKind.Auto
'
Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Auto)> _
Structure RGBValue
Dim Red As Byte
Dim Green As Byte
Dim Blue As Byte
End Structure
LayoutKind.Explicit
:FieldOffset
<StructLayout(LayoutKind.Explicit)> _
Structure RGBValue
<FieldOffset(0)> Dim Red As Byte
<FieldOffset(1)> Dim Green As Byte
<FieldOffset(2)> Dim Blue As Byte
End Structure
FieldOffset
<StructLayout(LayoutKind.Explicit)> _
Structure RGBValue
<FieldOffset(0)> Dim Red As Byte
<FieldOffset(0)> Dim Green As Byte
<FieldOffset(0)> Dim Blue As Byte
End Structure
:
Dim X As RGBValue
X.Blue = 10
ArabicConsole.WriteLine(X.Red) ' 10
w w.pdf actory.com
224
:
_ >)<StructLayout(LayoutKind.Explicit
Structure RGBValue
<FieldOffset(0)> Dim Red As Byte
<FieldOffset(1)> Dim Green As Byte
<FieldOffset(2)> Dim Blue As Byte
<FieldOffset(3)> Dim Extra As Byte
<FieldOffset(0)> Dim Value As Integer
End Structure
) Value
( :
Dim X As RGBValue
' 0
' 0
' 0
X.Value = 0
)ArabicConsole.WriteLine(X.Red
)ArabicConsole.WriteLine(X.Green
)ArabicConsole.WriteLine(X.Blue
' 16777215
X.Red = 255
X.Green = 255
X.Blue = 255
)ArabicConsole.WriteLine(X.Value
) (4- 5 RGBValue .
:4- 5 RGBValue .
w w.pdf actory.com
:
225
Custom Attributes Classes
-Attributes
.
CodeInfo
) .... (.
: :Attribute
Class CodeInfoAttribute
End Class
: :System.Attribute
Class CodeInfoAttribute
Inherits System.Attribute
End Class
: AttributeUsage
_ )<AttributeUsage(AttributeTargets.All
Class CodeInfoAttribute
Inherits System.Attribute
End Class
AttributeTargets.All
w w.pdf actory.com
226
:
AttributeTargets.All
AttributeTargets.Assembly
AttributeTargets.Class
AttributeTargets.Constructor
AttributeTargets.Delegate
AttributeTargets.Enum
.Enum
.Delegate
.
AttributeTargets.Event
AttributeTargets.Field
AttributeTargets.Interface
AttributeTargets.Method
AttributeTargets.Module
AttributeTargets.Parameter
AttributeTargets.Property
AttributeTargets.ReturnValue
AttributeTargets.Struct
.Functions
.Structure
Or
AttributeUsage
:
<AttributeUsage(AttributeTargets.Method Or
)AttributeTargets.Property
: Boolean :
w w.pdf actory.com
:
227
:
_ )<AttributeUsage(AttributeTargets.All
Class CodeInfoAttribute
Inherits System.Attribute
'
'
'
) Attribute (:
_ >)" "(<CodeInfo
)(Sub DoSomthing
End Sub
TesterName Tested
_ >)" "(<CodeInfo
Class Person
_ >)", Tested:=False "=", TesterName: "(<CodeInfo
)( Sub Move
End Sub
_ >)", Tested:=True "=", TesterName: "(<CodeInfo
)( Sub Kill
End Sub
End Class
w w.pdf actory.com
228
:
CodeInfo
Class Library
w w.pdf actory.com
.NET Framework
w w.pdf actory.com
w w.pdf actory.com
.NET Framework
.NET Framework
MSDN
.NET Framework .
.NET Documentation
System.Object
.NET Framework
- System.Object
System.Object .
Derived Class
(:
'
Dim X As Object '
Dim X As System.Object
X = New AnyClass
w w.pdf actory.com
232
: .NET Framework
System.Object .NET
Interfaces .
Object
Object
.
)(:Equals
Overridable True
.NET Framework
Overrides ) ( .
Value Type Variables
True :
Dim X As Integer = 10
ArabicConsole.WriteLine(X.Equals(10)) ' True
)(:GetType
System.Type .
System.Type
.Reflection Classes
w w.pdf actory.com
:
233
)(:ToString
Overridable ) (String
) :(Namespaces
.NET Framework
Dim X As Integer = 10
"Dim Y As String = "xxx
ArabicConsole.WriteLine(X.ToString) ' 10
ArabicConsole.WriteLine(Y.ToString) ' xxx
)(:ReferenceEquals
)( ReferenceEquals True
)( ReferenceEquals :Is
)( ReferenceEquals )( Equals
. Not Overridable
)(:MemberwiseClone
)( MemberwiseClone
.ICloneable
w w.pdf actory.com
234
: .NET Framework
)( MemberwiseClone Protected
) .(System.Object
Protected
.
)(:Finalize
)( Finalize Overridable Protected
)( .MemberwiseClone
.Destructors
.NET Framework
Managed Heap
.
) Numbers ( Booleans
Boolean -
.Value Type
System.ValueType )
)( Equals Overrides
(.
w w.pdf actory.com
:
235
Arrays .Strings
Numbers Structures Enums
.Value Type
(23 .
Value Type
Reference Type :
) (
Managed Heap .
Structures
Inheritance .
Structure Person
Public Name As String
Public Age As Integer
End Structure
)
4(.
w w.pdf actory.com
236
: .NET Framework
Boxing
.Unboxing Value
Type Object
:Object
Dim X As Integer = 10
' Boxing
Dim Y As Object = X
Reference Type
Y .
) Object (Value Type
:Unboxing
Object ) )( WriteLine
String
:
Dim x As String
'
)ArabicConsole.WriteLine(x.Length
w w.pdf actory.com
:
237
x Length
New
:
Char ' String
)Dim X As New String("A"c, 5
"Dim Y As String = "AAAAA
-
.
Reference Type
:
) String 1- 6 (.
w w.pdf actory.com
238
: .NET Framework
X Y
. &
:Compiling
w w.pdf actory.com
:
239
String Length Chars
Chars
Char ) (:
))ArabicConsole.WriteLine(X.Chars(0
))ArabicConsole.WriteLine(X.Chars(X.Length - 1
:
"---" = Dim x As String
"Dim y As String = "A-B-C-D
' ))ArabicConsole.WriteLine(x.Chars(0
' ))ArabicConsole.WriteLine(x.Chars(6
ArabicConsole.WriteLine(y.Chars(0)) ' A
ArabicConsole.WriteLine(y.Chars(6)) ' D
Strings Methods
.NET Documentation
.
)( Trim
"
' )ArabicConsole.WriteLine(MyString.Trim
)( Trim ) Char
(ParamArray :
w w.pdf actory.com
240
: .NET Framework
)( StartsWith )( EndsWith
End If
End If
)( Insert )(
)( Remove
w w.pdf actory.com
:
241
)( Replace
)( Split
" "c :
)( ToCharArray Char
.
)(Dim Words As Char() = MyString.ToCharArray
w w.pdf actory.com
242
: .NET Framework
)( ToUpper
)( Compare
0 1 -
1 :
Case-sensitive
:True
) ( ""
"":
' 1
' 0
))"" ",
))""" ,"(ArabicConsole.WriteLine(String.Compare
w w.pdf actory.com
:
243
)
(
.
)( Compare
)( CompareOrdinal
UNICODE ) ...(:
CultureInfo
... .
System.Globalization
.NET
Framework
.NET Documentation
Microsoft
- - .CultureInfo
CultureInfo
) ...(
LCID
w w.pdf actory.com
244
: .NET Framework
)( CurrentCulture .
'
Imports System.Globalization
'
)(Dim KSA As CultureInfo = CultureInfo.CurrentCulture
With KSA
' ar-SA
)ArabicConsole.WriteLine(.Name
)' Arabic (Saudi Arabia
)ArabicConsole.WriteLine(.EnglishName
) ( '
)ArabicConsole.WriteLine(.NativeName
' 1025
)ArabicConsole.WriteLine(.LCID
End With
ar-SA
1025 :
)"Dim KSA As New CultureInfo("ar-SA
'
)Dim KSA As New CultureInfo(1025
w w.pdf actory.com
:
245
ar-SA
0x0401
ar-DZ
0x1401
ar-BH
0x3C01
ar-EG
0x0C01
ar-IQ
0x0801
ar-JO
0x2C01
ar-KW
0x3401
ar-LB
0x3001
ar-LY
0x1001
ar-MA
0x1801
ar-OM
0x2001
ar-QA
0x4001
ar-SY
0x2801
ar-TN
0x1C01
ar-AE
0x3801
ar-YE
0x2401
ar
0x0001
.
.
.
.
) (243
' 0
_ "),"" ,"(ArabicConsole.WriteLine(String.Compare
)))", False, New CultureInfo("ar-SA
CultureInfo CompareInfo
w w.pdf actory.com
246
: .NET Framework
)""" ,
' 0
"(ArabicConsole.WriteLine(KSA.CompareInfo.Compare
_ ","" ,
))CompareOptions.IgnoreSymbols
CompareOptions.IgnoreNonSpace
' 0
_ ","" ,"(ArabicConsole.WriteLine(KSA.CompareInfo.Compare
))CompareOptions.IgnoreNonSpace
Enum
:Or
_ ArabicConsole.WriteLine(KSA.CompareInfo.Compare(s1, s2,
))CompareOptions.IgnoreNonSpace Or CompareOptions.IgnoreSymbols
CompareOptions.IgnoreSymbols
)( CompareInfo.Compare
: .... %.
)( IndexOf
1- :
"?Dim x As String = "Can you find the word find
' 8
' -1
))"ArabicConsole.WriteLine(x.IndexOf("find
))"ArabicConsole.WriteLine(x.IndexOf("Find
w w.pdf actory.com
:
247
)( IndexOf
"
")) ' 39"(ArabicConsole.WriteLine(x.IndexOf
"(ArabicConsole.WriteLine(x.IndexOf
")) ' 23
CultureInfo
)( IndexOf CompareInfo
:CompareOptions.IgnoreSymbols
" = Dim x As String
"
)"Dim KSA As New CultureInfo("ar-SA
' 23
_ "," ArabicConsole.WriteLine(KSA.CompareInfo.IndexOf(x,
CompareOptions.IgnoreSymbols)) ' 23
Char
Char
Char c
:String
'
w w.pdf actory.com
248
: .NET Framework
) )( (Isxxx Boolean
:
' True
' True
' True
' True
' True
'
))ArabicConsole.WriteLine(Char.IsDigit("1"c
'
))"c"(ArabicConsole.WriteLine(Char.IsLetter
'
))ArabicConsole.WriteLine(Char.IsLetterOrDigit("X"c
'
))ArabicConsole.WriteLine(Char.IsLower("a"c
'
))ArabicConsole.WriteLine(Char.IsPunctuation(""""c
String
StringBuilder
)
( :
w w.pdf actory.com
:
249
" " :
)ArabicConsole.WriteLine(x
)ArabicConsole.WriteLine(y
)ArabicConsole.WriteLine(z
Reference Type
Garbage Collection
Reference Type
.
System.Text.StringBuilder
) (String Buffer
.
w w.pdf actory.com
250
: .NET Framework
String
) )( Remove() Insert(
- StringBuilder - :
)"" x.Insert(0,
)" " x.Insert(4,
'
' )ArabicConsole.WriteLine(x
)( Append
StringBuilder
String String
:StringBuilder
.NET Framework
Int32 Int64
.
w w.pdf actory.com
:
251
.50-49
. MaxValue MinValue
ReadOnly :Shared
Byte
Integer
Long
Double
0
-2147483648
9223372036854775807
1.79769313486232E+308
'
'
'
'
As
As
As
As
X
Y
Z
W
Dim
Dim
Dim
Dim
)ArabicConsole.WriteLine(X.MinValue
)ArabicConsole.WriteLine(Y.MinValue
)ArabicConsole.WriteLine(Z.MaxValue
)ArabicConsole.WriteLine(W.MaxValue
)( Epsilon
- :
Dim X As Double
Dim Y As Single
ArabicConsole.WriteLine(X.MinValue) ' -1.79769313486232E+308
ArabicConsole.WriteLine(X.Epsilon) ' 4.94065645841247E-324
ArabicConsole.WriteLine(Y.MinValue) ' -3.402823E+38
ArabicConsole.WriteLine(Y.Epsilon) ' 1.401298E-45
w w.pdf actory.com
252
: .NET Framework
)( ToString
:String
)(ToString
# 0 :
Dim x As Integer = 10
ArabicConsole.WriteLine(x.ToString("####")) ' 10
ArabicConsole.WriteLine(x.ToString("0000")) ' 0010
.NET Documentation " ". " ",
:Exponential Form
Single = 100.1234
Integer = 9999999
Double = 0.1
Long = 1500000000000
0100.1
9,999,999
10.0 %
150 E+10
'
'
'
'
As
As
As
As
X
Y
Z
w
Dim
Dim
Dim
Dim
))"ArabicConsole.WriteLine(X.ToString("0000.#
))"ArabicConsole.WriteLine(Y.ToString("###,###,###
))"ArabicConsole.WriteLine(Z.ToString("##.0 %
))"ArabicConsole.WriteLine(w.ToString("### E+0
) (:
w w.pdf actory.com
:
253
' Percent
ArabicConsole.WriteLine(MyDouble.ToString("P")) ' 12,345,678,900.00%
' Number
ArabicConsole.WriteLine(MyDouble.ToString("N")) ' 123,456,789.00
' Fixed-point
ArabicConsole.WriteLine(MyDouble.ToString("F")) ' 123456789.00
NumberFormat
)ToString() CultureInfo
:(
Imports System.Globalization
.NumberFormat))
.NumberFormat))
.NumberFormat))
.NumberFormat))
.NumberFormat))
NumberFormat
NumberFormatInfo
:
Imports System.Globalization
w w.pdf actory.com
254
: .NET Framework
Math
Microsoft.VisualBasic.Math
Microsoft.VisualBasic
:
Imports Microsoft.VisualBasic
)( Log10 )( Sign 1
1 0 :' 10
8
2
2
-1
1
'
'
'
'
'
))ArabicConsole.WriteLine(Math.Abs(-10
))ArabicConsole.WriteLine(Math.Sqrt(9
' 3
))ArabicConsole.WriteLine(Math.Pow(2, 3
))ArabicConsole.WriteLine(Math.Log(9, 3
))ArabicConsole.WriteLine(Math.Log10(100
))ArabicConsole.WriteLine(Math.Sign(Double.MinValue
))ArabicConsole.WriteLine(Math.Sign(Double.Epsilon
)( Sqrt
)( NthSqr:
'
ArabicConsole.WriteLine(NthSqr(8, 3)) ' 2
)( IEEERemainder
)( Ceiling
)( Floor :
w w.pdf actory.com
:
255
1
2
-1
1
-2
'
'
'
'
'
))ArabicConsole.WriteLine(Math.IEEERemainder(9, 2
))ArabicConsole.WriteLine(Math.Ceiling(1.2
))ArabicConsole.WriteLine(Math.Ceiling(-1.2
))ArabicConsole.WriteLine(Math.Floor(1.2
))ArabicConsole.WriteLine(Math.Floor(-1.2
)( Round
. .NET Documentation
Random Numbers
System.Random
)( Next Integer:
)( NextDouble Double 0 :1
)(Dim Rnd As New Random
Dim counter As Integer
For counter = 1 To 10
ArabicConsole.WriteLine(Rnd.NextDouble) ' 0.01234865
Next
w w.pdf actory.com
256
: .NET Framework
Byte
)(:NextBytes
Date System.DateTime
:
26 ' 2002
12:00 '
)Dim today As New Date(2002, 9, 26
w w.pdf actory.com
:
257
12:00
26 ' 2002
1:30 '
)Dim today As New Date(2002, 9, 26, 13, 30, 0
)( Now :
26 ' 2002
3:30:23 '
Dim today As Date = Date.Now
# :#
20 ' 2003
2:00:00 '
Dim today As Date = #1/20/2003 2:00:00 AM#
Minute Second :
)ArabicConsole.WriteLine(today.Year
)ArabicConsole.WriteLine(today.Month
)ArabicConsole.WriteLine(today.Day
)ArabicConsole.WriteLine(today.Hour
)ArabicConsole.WriteLine(today.Minute
)ArabicConsole.WriteLine(today.Second
Date
w w.pdf actory.com
258
: .NET Framework
)( DaysInMonths
( -
'
)Dim today As New Date(2002, 9, 26
'
) ( '
'
ArabicConsole.WriteLine(today) ' 1423/7/20
today )(ToString
.
w w.pdf actory.com
:
259
Calendar
:CultureInfo
Imports System.Globalization
today )
( 6
) ( )(
:
Imports System.Globalization
HijriCalendar :
Imports System.Globalization
w w.pdf actory.com
260
: .NET Framework
HijriCalendar
Calendar .
Overrides - HijriCalendar
(.
)( GetDaysInMonth :
)(Dim hijra As New HijriCalendar
ArabicConsole.WriteLine(hijra.GetDaysInMonth(1423, 7)) ' 30
ArabicConsole.WriteLine(hijra.GetDaysInMonth(1423, 8)) ' 29
.NET
Framework
) 29 30( .
) 2-6 (
Windows Registry :
HKEY_CURRENT_USER\Control Panel\International\AddHijriDate
w w.pdf actory.com
:
261
'
'
'
'
)ArabicConsole.WriteLine(x.ToShortDateString
)ArabicConsole.WriteLine(x.ToLongDateString
)ArabicConsole.WriteLine(x.ToLongTimeString
)ArabicConsole.WriteLine(x.ToShortTimeString
w w.pdf actory.com
262
.NET Framework :
:ToString()
mm MM
.
( ... )
. ( )
)DateTimeFormatInfo
:(DateTimeFormatInfo CultureInfo DateTimeFormat
w w.pdf actory.com
:
263
.NET Documentation
.DateTimeFormatInfo
Enum
Enum -
System.Enum Visual Basic .NET
Enum Enum
:
Enum Programmer
VisualBasic
CSharp
CPlusPlus
Java
Delphi
End Enum
)ArabicConsole.WriteLine(Turki
)ArabicConsole.WriteLine(Turki.ToString
)( ToString )( Parse
'
' Option Strict Off
)"Turki = [Enum].Parse(GetType(Programmer), "CSharp
' 1
' CSharp
)ArabicConsole.WriteLine(Turki
)ArabicConsole.WriteLine(Turki.ToString
Option Strict
)(:CType
w w.pdf actory.com
264
.NET Framework :
'
' Option Strict On
Turki = CType([Enum].Parse(GetType(Programmer), "CSharp"), _
Programmer)
ArabicConsole.WriteLine(Turki)
ArabicConsole.WriteLine(Turki.ToString)
' 1
' CSharp
Case-Sensitive Parse()
:True
Enum
' 4
' Delphi
: IsDefined()
If [Enum].IsDefined(GetType(Programmer), 3) Then
Turki = CType(3, Programmer)
End If
String .GetValues() GetNames()
: Object
w w.pdf actory.com
:
265
:
VisualBasic = 0
CSharp = 1
CPlusPlus = 2
Java = 3
Delphi = 4
Enum :Bit-Coded
Enum Bit-Coded
And Or
... XOr . Flags Attribute :
_ >)(<Flags
Enum Programmer
None = 0
VisualBasic = 1
CSharp = 2
CPlusPlus = 4
Java = 8
Delphi = 16
End Enum
)( ToString :
Dim Ali As Programmer
Ali = Programmer.VisualBasic Or Programmer.CSharp
)ArabicConsole.WriteLine(Ali
' 3
ArabicConsole.WriteLine(Ali.ToString) ' VisualBasic, CSharp
Array
- System.Array
Reference Type Value Type
:
w w.pdf actory.com
266
: .NET Framework
)(' X
'
ArabicConsole.WriteLine(X(0)) ' 100
ArabicConsole.WriteLine(X(1)) ' 200
ArabicConsole.WriteLine(X(2)) ' 300
)( Clone
Array Rank
Length
GetLenght :
'
'
'
'
)ArabicConsole.WriteLine(X.Rank
)ArabicConsole.WriteLine(X.Length
))ArabicConsole.WriteLine(X.GetLength(0
))ArabicConsole.WriteLine(X.GetLength(1
w w.pdf actory.com
:
267
.NET )( Sort :
}Dim X() As Integer = {5, 2, 9
Dim counter As Integer
)Array.Sort(X
)For counter = 0 To UBound(X
))ArabicConsole.WriteLine(X(counter
Next
) (
)( Reverse :
w w.pdf actory.com
268
: .NET Framework
)( Sort
)( Sort
:UNICODE
)( Sort
Small Capital . a
Z.
w w.pdf actory.com
:
269
:
)( IndexOf
1- :
)( IndexOf -
1-
))"" ArabicConsole.WriteLine(Array.IndexOf(X,
))"" ArabicConsole.WriteLine(Array.IndexOf(X,
))"" ArabicConsole.WriteLine(Array.IndexOf(X,
Binary
Search )(BinarySearch
' 0
))"ArabicConsole.WriteLine(Array.BinarySearch(X, "Ahmed
'
'
)Array.Sort(X
))"ArabicConsole.WriteLine(Array.BinarySearch(X, "Ahmed
w w.pdf actory.com
270
: .NET Framework
System.Collections
System.Collections
.Collections Array
System.Collections
.
Interfaces
ICollection IList
System.Collections ICollection
) IEnumerable (
For Each .
ICollection Count
)( CopyTo
.Array
IList )( Add
Insert() Remove() Clear()
.
) (Array
IList ) )( Add
)(.(Remove
w w.pdf actory.com
:
271
System.Collections MSDN
.
Stack
Stack (LIFO) Last-In-First-Out
. )( Push
)( Pop :
:3- 6 .st
w w.pdf actory.com
272
: .NET Framework
Queue
. )( Enqueue
)( Dequeue :
)Dim qu As New Queue(100
)qu.Enqueue(10
)qu.Enqueue(20
)qu.Enqueue(30
ArabicConsole.WriteLine(qu.Dequeue) ' 10
ArabicConsole.WriteLine(qu.Dequeue) ' 20
ArabicConsole.WriteLine(qu.Dequeue) ' 30
:4- 6 .qu
ArrayList
ArrayList IList
ArrayList ) (Array
w w.pdf actory.com
:
273
16
:Capacity
16 '
100 ' 101
)(:Insert
' X
)"" X.Insert (0,
' Y
)"Y.Insert (99. "Visual Basic .NET
)(:Add
)""( X.Add
)""( X.Add
)""( X.Add
) )( (Add )
(
X 32 200 Y.
ArrayList )( AddRange
)( RemoveRange
)( Remove
)( Clear ) ArrayList
:(IList
w w.pdf actory.com
274
: .NET Framework
)""( X.Remove
)( Y.Clear
.NET Framework . .NET
Documentation .
.NET Framework
.
w w.pdf actory.com
" : Debugging
".
.NET Framework
.Visual Studio .NET
:
. :
(Errors
For .Next
Code Editor
:1- 7 .
w w.pdf actory.com
276
: .NET Framework
:2- 7 .
Yes ) (
No
:3- 7 .
Visual Basic .NET Run
Time Errors
. .NET .Exceptions
Exceptions
w w.pdf actory.com
:
277
)( Move
:System.IO.File
)"System.IO.File.Move("D:\File.EXE", "C:\File.EXE
D:\File.EXE
:4- 7 .Exception
- Visual Basic .NET
)( ( Exists :
If System.IO.File.Exists("D:\File.EXE") Then
)"System.IO.File.Move("D:\File.EXE", "C:\File.EXE
End If
D:\File.EXE
Read Only
)(:GetAttribtues
w w.pdf actory.com
278
: .NET Framework
Imports System.IO
_ If Not CBool(File.GetAttributes("C:\Test\program.exe") And
) FileAttributes.ReadOnly
If System.IO.File.Exists("D:\File.EXE") Then
)"System.IO.File.Move("D:\File.EXE", "C:\File.EXE
End If
End If
Read Only
) CD-ROM(
... ...
.
Exception Err
.
.Bugs - -
Bug
) (23:59:59
w w.pdf actory.com
:
279
Debugging
) (
Exception
.NET Exception )(
Microsoft
.NET Framework
Exception .
System.Exception
.
DivideByZeroException
OverFlowException NotFiniteNumberException
FileNotFoundException
... EndOfStreamException DirectoryNotFoundException
w w.pdf actory.com
280
: .NET Framework
. .NET
.Documentation
.System.Exception Exception
Exception
-String ) "Attempted to :
Throw an exception
Catching Exceptions
Try
:Catch
Try
'
'
'
Catch
'
'
'
End Try
Exception
:Catch
w w.pdf actory.com
:
281
Dim X, Y As Integer
Try
'
X = 10 \ Y
)X = CInt(10 ^ Y
Catch ex As Exception
'
'
If ex.Message = "Attempted to divide by zero." Then
)" "(ArabicConsole.WriteLine
& " ElseIf ex.Message = "Arithmetic operation resulted
_ & "in an overflow." Then
)" "(ArabicConsole.WriteLine
Else
)" "(ArabicConsole.WriteLine
End If
End Try
-
) MSDN
(:
Dim X, Y As Integer
Try
X = 10 \ Y
)X = CInt(10 ^ Y
Catch ex As DivideByZeroException
)" "(ArabicConsole.WriteLine
Catch ex As OverflowException
)" "(ArabicConsole.WriteLine
Catch ex As Exception
)" "(ArabicConsole.WriteLine
End Try
w w.pdf actory.com
282
: .NET Framework
Catch
Exception
Exception .
.Exit Try
StackOverflowException
OutOfMemoryException .
) (Catch
.
:When
When Catch
:
Dim x As Integer
Try
Catch ex As Exception
If x = 0 Then
ElseIf x = 1 Then
Else
End If
End Try
w w.pdf actory.com
:
283
When :
Integer
As Exception When x = 0
As Exception When x = 1
As Exception
Dim x As
Try
Catch ex
Catch ex
Catch ex
End Try
When
- :
As Integer
= 1
= 2
= 3
= 4
Dim StepNum
Try
StepNum
StepNum
StepNum
StepNum
End Try
w w.pdf actory.com
284
: .NET Framework
:Finally
Finally Try Catch End Try
Try
'
'
'
Catch
'
'
'
Finally
'
'
'
End Try
Finally
Exit Try Try Catch End Try
) .(Return Exit Function Exit Sub
Finally
.
Throwing Exceptions
.
Throw :
'
)(Throw New System.IO.FileNotFoundException
w w.pdf actory.com
:
285
Message
:Throw
.NET Framework
-
.
)(Sub AAA
)(BBB
End Sub
)(Sub BBB
)(CCC
End Sub
)(Sub CCC
)(Throw New Exception
End Sub
w w.pdf actory.com
286
: .NET Framework
:5- 7 .
)( CCC
)( BBB
)( AAA ) ... - 7
(5 .
)( AAA
- StackTrace :
)(Sub AAA
Try
)(BBB
Catch ex As Exception
)ArabicConsole.WriteLine(ex.StackTrace
End Try
End Sub
)(Sub BBB
)(CCC
End Sub
)(Sub CCC
)(Throw New Exception
End Sub
w w.pdf actory.com
:
287
:
at MyNameSpace.Module1.CCC() in D:\VB.NET\Module1.vb:line 31
at MyNameSpace.Module1.BBB() in D:\VB.NET\Module1.vb:line 28
at MyNameSpace.Module1.AAA() in D:\VB.NET\Module1.vb:line 21
False
Custom Exceptions
.NET Framework
Visual Basic .NET
:System.ApplicationException
Class UnableToLoadUserFileException
Inherits System.ApplicationException
End Class
Overrides
) Exception System.ApplicationException (:
Class UnableToLoadUserFileException
Inherits System.ApplicationException
' Message
Public Overrides ReadOnly Property Message() As String
Get
" " Return
End Get
End Property
End Class
w w.pdf actory.com
288
: .NET Framework
Throw :
Try
Catch ex As UnableToLoadUserFileException
)ArabicConsole.WriteLine(ex.Message
End Try
Custom
Exceptions -
.Serializable
Serialization .
Err
. Microsoft
Exception
Err .
Catching Exceptions
Err Try Catch End
Try On Error :
:
w w.pdf actory.com
:
289
)(Sub MySub
On Error GoTo Errorhandler
'
'
'
Exit Sub
Errorhandler:
'
'
End Sub
)(Sub MySub
On Error Resume Next
'
End Sub
Err
Description
Message :Exception
)(Sub MySub
On Error GoTo Errorhandler
'
'
Exit Sub
Errorhandler:
)ArabicConsole.WriteLine(Err.Description
End Sub
w w.pdf actory.com
290
: .NET Framework
Throwing Exceptions
Err
)( Raise :
)Err.Raise(11
11 DivideByZeroException MSDN
1001 :
Exception Err
. Err
On Error
On
On Error Try
End Try :
w w.pdf actory.com
:
291
)(Sub AAA
Try
)(BBB
Catch ex As DivideByZeroException
'
)ArabicConsole.WriteLine(ex.Message
End Try
End Sub
)(Sub BBB
On Error GoTo ErrorHandler
Dim X As Integer = 0
'
X = 10 \ X
Exit Sub
ErrorHandler:
End Sub
)( AAA
)( BBB
Catch )( AAA
)( BBB .
)( BBB
- )( AAA .
)(Sub BBB
On Error GoTo ErrorHandler
Dim X As Integer = 0
X = 10 \ X
Exit Sub
ErrorHandler:
Throw Err.GetException
End Sub
w w.pdf actory.com
292
: .NET Framework
Throw )( Err.Raise
.
On Error Goto X
On Error Resume Next
.Caller
] [F5 Start .Debug
Visual Studio .NET .
- Start without Debugging Debug
] [Ctrl] + [F5
w w.pdf actory.com
:
293
Breakpoints
Insert Breakpoint )
.(6- 7
:6- 7 Breakpoints .
Debug->Windows-
) Breakpoints (7- 7
>Breakpoints
:7- 7 .Breakpoints
Step Into
) .(8- 7
. Step Over
w w.pdf actory.com
294
: .NET Framework
Pause
) Breakpoints .(Step Into
. Local
Call Stack .
) Debug->Windows .(9- 7
w w.pdf actory.com
:
295
w w.pdf actory.com
296
: .NET Framework
:10- 7 .Exceptions
Configurations
Configurations
Compiling .
Debug Release
) 13- 1 .(32
Debug Release
) .(11- 7
w w.pdf actory.com
:
297
) 12- 7 (.
w w.pdf actory.com
298
: .NET Framework
:12- 7 .
.NET
Exceptions
..NET Documentations
.
w w.pdf actory.com
System.IO .NET Framework
Directory File
Streams Path
DirectoryInfo FileInfo .
:
Imports System.IO
Directory
Folders )( CreateDirectory -
:
)"Directory.CreateDirectory("C:\Test\My Folder
)" \Directory.CreateDirectory("C:
w w.pdf actory.com
300
: .NET Framework
:
Try
)"Directory.CreateDirectory ("C:\Test
Catch
End Try
)( Delete :
)" \Directory.Delete("C:
(
True :
'
)Directory.Delete("C:\Test", True
)( Delete -
Recycle Bin .
)( Move -
w w.pdf actory.com
:
301
)( Move
:
)"Directory.Move("C:\Test", "C:\TestEx
( )( Exists True
:
End If
)( GetCreationTime
)( GetLastAccessTime
)( GetLastWriteTime .
:Date
))"ArabicConsole.WriteLine(Directory.GetCreationTime("C:\Test
))"ArabicConsole.WriteLine(Directory.GetLastAccessTime("C:\Test
))"ArabicConsole.WriteLine(Directory.GetLastWriteTime("C:\Test
)(SetCreationTime
)( SetLastAccessTime )(:SetLastWriteTime
))"ArabicConsole.WriteLine(Directory.GetCreationTime("C:\Test
)Directory.SetCreationTime("C:\Test", Date.Now
))"ArabicConsole.WriteLine(Directory.GetCreationTime("C:\Test
)( GetCurrentDirectory )( GetDirectoryRoot )
(String :
' C:\Test
)ArabicConsole.WriteLine(Directory.GetCurrentDirectory
\' C:
))"ArabicConsole.WriteLine(Directory.GetDirectoryRoot("C:\Test
w w.pdf actory.com
302
: .NET Framework
)( GetCurrentDirectory
)(:SetCurrentDirectory
)"Directory.SetCurrentDirectory("C:\Test
)( GetFileSystemEntries String -
Dim x As String
For Each x In Directory.GetLogicalDrives
)ArabicConsole.WriteLine(x
Next
)( GetParent
DirectoryInfo
.
. )( PrintFilesAndFolders
Recursion .
:
w w.pdf actory.com
:
303
: True
' C:\Test
PrintFilesAndFolders("C:\Test")
' C:\Test
'
PrintFilesAndFolders("C:\Test", True)
File
File
Directory
: File
'
File.Delete ("C:\Test\File.EXE")
'
File.Move("C:\Pic.BMP", "D:\Pic.BMP")
'
x
x
x
= File.GetCreationTime("C:\MyFile.DAT")
= File.GetLastAccessTime("C:\MyFile.DAT")
= File.GetLastWriteTime("C:\MyFile.DAT")
w w.pdf actory.com
304
.NET Framework :
'
File.SetCreationTime("C:\MyFile.DAT", Now)
File.SetLastAccessTime("C:\MyFile.DAT", Now)
File.SetLastWriteTime("C:\MyFile.DAT", Now)
'
If File.Exists("C:\letter.doc") Then
End If
: Copy()
File.Copy("C:\program.EXE", "C:\program2.EXE")
: True -
'
File.Copy("C:\program.EXE", "C:\program2.EXE", True)
w w.pdf actory.com
:
305
)( SetAttributes -
'
)File.SetAttributes("C:\program.exe", FileAttributes.ReadOnly
'
_ File.SetAttributes("C:\program2.exe", FileAttributes.ReadOnly
)Or FileAttributes.Hidden
'
_ File.SetAttributes("C:\program3.exe",
)File.GetAttributes("C:\program3.exe") Or FileAttributes.Hidden
'
_ File.SetAttributes("C:\program4.exe",
)File.GetAttributes("C:\program4.exe") Xor FileAttributes.Hidden
)( GetAttributes )( SetAttributes
Folders
.File
Stream
w w.pdf actory.com
306
: .NET Framework
:1- 8 .
Abstract Classes
.
Stream
.FileStream
-NetworkStream
. ) (
Buffering
) (FileStream
Buffer
w w.pdf actory.com
:
307
)( Flush
) .(2- 8
:2- 8 )( Flush
- Stream
Stream Length
Position
.
)( Read
. )( Write
Byte Array )( WriteByte
Position
: + .
w w.pdf actory.com
308
: .NET Framework
)( Close
)( Close
- )( Flush - Buffering
.FileStream
Byte Array
)
... Double Integer(
StreamReader
StreamWriter
BinaryReader
BinaryWriter
XmlTextReader .XmlTextWriter
FileStream ) .(3- 8
:3- 8 .FileStream
w w.pdf actory.com
:
309
) !( :
-
)( Close .
StreamWriter StreamReader
BinaryReader .BinaryWriter
XmlTextReader XMLTextWriter
.XML
.MSDN
Append True :
ASCII :Unicode
' ASCII
_ Dim textFile As New StreamWriter("C:\Test.TXT", True,
)System.Text.Encoding.ASCII
' UNICODE
_ Dim textFile2 As New StreamWriter("C:\Test2.TXT", True,
)System.Text.Encoding.Unicode
w w.pdf actory.com
310
: .NET Framework
FileStream
) Sharing MSDN (:
_Dim textStream As FileStream = File.Open("C:\Test.TXT",
_ FileMode.CreateNew,
_ FileAccess.ReadWrite,
)FileShare.Read
)Dim textFile As New StreamWriter(textStream
String NewLine :
)" "(textFile.WriteLine
)textFile.Write(99.9
)(textFile.Close
)( Write StreamWriter
.FileStream FileStream
Byte Array.
Buffering
True AutoFlush
False
) )( (Close
)(.Flush
w w.pdf actory.com
:
311
.StreamReader StreamWriter
:
)"Dim textFile As New StreamWriter("C:\Test.TXT
)( ReadLine :String
) )(ArabicConsole.WriteLine( textFile.ReadLine
)(textFile.Close
)( ReadToEnd
)ArabicConsole.WriteLine(textFile.ReadLineToEnd
)(textFile.Close
)( Read Overloads
MSDN .
StreamWriter StreamReader
w w.pdf actory.com
312
.NET Framework :
ArabicConsole.WriteLine( textFile.BaseStream.Length )
textFile.Close()
.BinaryReader
: FileStream
Write()
binaryFile.Close()
BinaryReader
: ReadXXX()
w w.pdf actory.com
:
313
)( ReadXXX
.
Strings
)( Write
:
)( ReadString
)( Seek
.Position
Char Array
)( Write )( ReadChars
w w.pdf actory.com
314
: .NET Framework
Prefixed-length Strings
.Fixed-length Strings
.NET
.Documentation
Custom Streams
)... BinaryReader StreamWriter StreamReader(
Class Person
Public Name As String
Public Age As Integer
End Class
:
)Dim st As FileStream = File.Open("C:\test.dat", FileMode.OpenOrCreate
)Dim binaryFile As New BinaryWriter(st
)(Dim Turki As New Person
" " = Turki.Name
Turki.Age = 99
)binaryFile.Write(Turki.Name
)binaryFile.Write(Turki.Age
. Inheritance
BinaryWriter :BinaryReader
w w.pdf actory.com
:
315
'
Class PersonWriter
Inherits BinaryWriter
Sub New(ByVal st As System.IO.Stream)
MyBase.New(st)
End Sub
Public Overloads Sub Write(ByVal personObject As Person)
MyBase.Write(personObject.Name)
MyBase.Write(personObject.Age)
End Sub
End Class
'
Class PersonReader
Inherits BinaryReader
Sub New(ByVal st As System.IO.Stream)
MyBase.New(st)
End Sub
Function ReadPerson() As Person
Dim tmpPerson As New Person()
tmpPerson.Name = MyBase.ReadString
tmpPerson.Age = MyBase.ReadInt32
Return tmpPerson
End Function
End Class
:
Dim st As FileStream = File.Open("C:\test.dat", FileMode.OpenOrCreate)
Dim MyFile As New PersonWriter(st)
Dim Turki As New Person()
Turki.Name = ""
Turki.Age = 99
MyFile.Write(Turki)
MyFile.Close()
:
Dim st As FileStream = File.Open("C:\test.dat", FileMode.OpenOrCreate)
Dim MyFile As New PersonReader(st)
Dim Turki As Person
w w.pdf actory.com
316
: .NET Framework
Turki = MyFile.ReadPerson
'
' 99
)ArabicConsole.WriteLine(Turki.Name
)ArabicConsole.WriteLine(Turki.Age
)(MyFile.Close
Person
PersonWriter
.PersonReader
Object Serialization
.
Path
Path Paths
.
)
:(Windows
' /
)ArabicConsole.WriteLine(Path.AltDirectorySeparatorChar
\ '
)ArabicConsole.WriteLine(Path.DirectorySeparatorChar
|><" '
)ArabicConsole.WriteLine(Path.InvalidPathChars
; '
)ArabicConsole.WriteLine(Path.PathSeparator
' :
)ArabicConsole.WriteLine(Path.VolumeSeparatorChar
w w.pdf actory.com
:
317
FileInfo DirectoryInfo
FileInfo DirectoryInfo
:
'
Dim folder As New DirectoryInfo("C:\Windows")
'
Dim file As New FileInfo("C:\Autoexec.bat")
FileSystemInfo
' Windows
ArabicConsole.WriteLine(folder.Name)
' Autoexec.bat
ArabicConsole.WriteLine(file.Name)
' C:\Windows
ArabicConsole.WriteLine(folder.FullName)
' C:\Autoexec.bat
ArabicConsole.WriteLine(file.FullName)
w w.pdf actory.com
318
: .NET Framework
DirectoryInfo
Parent )( Create
. )( GetDirectories
) (DirectoryInfo
:
FileInfo
Length
.
)() GetFiles (DirectoryInfo :FileInfo
subfolder .subfile
w w.pdf actory.com
:
319
Streams
Streams
Object Serialization .
w w.pdf actory.com
w w.pdf actory.com
Object
Serialization
Instance
. Object Instance
.Serialization
Object Serialization
.NET
Framework
.
:
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
:
Imports System.IO
w w.pdf actory.com
322
: .NET Framework
.NET
Attributes
.
.Object Instance
Turki
Dim
Dim
Dim
= X
:1- 9 .Person
w w.pdf actory.com
...(
.Deserializing
Scope
.
.NET Framework
Web Services
.ASP.NET
)
Custom Streams(.
Binary Serialization
.NET Framework
) Primitive Types Double Integer String
... Boolean( .Formatter
Formatter ) IFormatter
(System.Runtime.Serialization
.NET Framework
) BinaryFormatter
(System.Runtime.Serialization.Formatters.Binary
.Binary Format
w w.pdf actory.com
324
: .NET Framework
.
BinaryFormatter )( Serialize
) Stream FileStream
( :
' Stream
)(st.Close
BinaryFormatter
)( Deserialize
Stream ) Object
CType :(Option Strict On
))ArabicConsole.WriteLine(data(0
))ArabicConsole.WriteLine(data(1
))ArabicConsole.WriteLine(data(2
)(st.Close
Object Instance
data )( Serialize
w w.pdf actory.com
data
)( Deserialize ) .(2- 9
:2- 9/ .
Class End Class .
) (
Serializable
Attribute :
_ >)(<Serializable
Class Person
End Class
w w.pdf actory.com
326
.NET Framework :
(Private )
Static Variables
:Class End Class
<Serializable()> _
Class Person
Public Name As String
' Public
GetValue()
w w.pdf actory.com
New )(
) Turki (:
)Dim st As FileStream = File.Open("C:\test.dat", FileMode.OpenOrCreate
)(Dim SerialObj As New BinaryFormatter
Dim Turki As Person
)Turki = CType(SerialObj.Deserialize(st), Person
'
' 99
' 4
)ArabicConsole.WriteLine(Turki.Name
)ArabicConsole.WriteLine(Turki.Age
)ArabicConsole.WriteLine(Turki.GetValue
)(st.Close
.Reference
:Serializable Attributes
-
)
:NonSerialized Attributes
_ >)(<Serializable
Class Person
Public Name As String
'
<NonSerialized()> Private MotherName As String
Private m_Age As Integer
End Class
w w.pdf actory.com
328
: .NET Framework
Object Graph
Object
Hierarchies Containment -
-OOP Has a
.NET Framework Object
_ >)(<Serializable
Class CarEngine
Public Cylinder As String
Public Volume As String
End Class
_ >)(<Serializable
Class Car
Public Name As String
Public Model As String
)(Public Engine As New CarEngine
End Class
_ >)(<Serializable
Class Person
Public Name As String
)(Public Car As New Car
End Class
Object Graph ) 3- 9
( . Containment
.Inheritance
w w.pdf actory.com
:3- 9 .
Object Graph
Reference Type Value Type
.Has a
Object Graph
:
w w.pdf actory.com
330
: .NET Framework
'
Dim Test As Person
'
)st.Seek(0, SeekOrigin.Begin
'
)Test = CType(SerialObj.Deserialize(st), Person
'
' BMW
' 12 V
'
)ArabicConsole.WriteLine(Test.Name
)ArabicConsole.WriteLine(Test.Car.Name
)ArabicConsole.WriteLine(Test.Car.Engine.Cylinder
)(st.Close
:Circular Reference
Person :
_ >)(<Serializable
Class Person
Public Name As String
Public Brother As Person
End Class
:
)(Dim Abbas As New Person
)(Dim Burey As New Person
"" = Abbas.Name
"" = Burey.Name
Abbas.Brother = Burey
Burey.Brother = Abbas
Abbas Object
Graph
Brother Burey
w w.pdf actory.com
Brother
Abbas Burey .
.NET Abbas Burey
Dim
Dim
Dim
Dim
"" = Abbas.Name
"" = Burey.Name
Abbas.Brother = Burey
Burey.Brother = Abbas
'
)SerialObj.Serialize(st, Abbas
ICloneable
)( MemberwiseClone .Object
) (
:
Class Car
Public Name As String
Public Model As String
End Class
w w.pdf actory.com
332
: .NET Framework
Class Person
Implements ICloneable
:
)(Dim Turki As New Person
Dim Turki2 As Person
" " = Turki.Name
"Turki.Car.Name = "BMW
"Turki.Car.Model = "Class 7
Turki2 = Turki.Clone
'
' BMW
)ArabicConsole.WriteLine(Turki2.Name
)ArabicConsole.WriteLine(Turki2.Car.Name
Car
" ".
Car
Turki2 Is
Turki.Car Turki2.Car
) :(4- 9
w w.pdf actory.com
:4- 9 Car.
.NET Shallow Copying
Object Graph .
.Deep Copying
)( Clone Person ) Serializable
_ >)(<Serializable
Class Car
End Class
_ >)(<Serializable
Class Person
Implements ICloneable
w w.pdf actory.com
334
.NET Framework :
:
Dim Turki As New Person()
Dim Turki2 As Person
Turki.Name = ""
Turki.Car.Name = "BMW"
Turki.Car.Model = "Class 7"
Turki2 = Turki.Clone
ArabicConsole.WriteLine(Turki2.Name)
ArabicConsole.WriteLine(Turki2.Car.Name)
'
' BMW
w w.pdf actory.com
)( Serialize BinaryFormatter
Stream
. )( Clone
Person FileStream
MemoryStream .
Custom Serialization
Serializable Attributes
NonSerialized Attributes
.
Custom Serializations .
w w.pdf actory.com
336
: .NET Framework
ISerializable
ISerializable
)( GetObjectData:
End Sub
info
)(:AddValue
)info.AddValue("Age", Me.Age
ISerializable :
_ Private Sub New(ByVal info As SerializationInfo,
)ByVal context As StreamingContext
End Sub
info
)(:GetXXX
)"Me.Age = info.GetInt32("Age
Private Constructer
Overloads
w w.pdf actory.com
TestClass
Integer ) Integer
ISerializable (
: New()
<Serializable()> _
Class TestClass
Implements ISerializable
Public
Public
Public
Public
X
Y
Z
W
As
As
As
As
Integer
Integer
Integer
Integer
w w.pdf actory.com
338
.NET Framework :
) /
:(
=
=
=
=
1
-1
-5
5
SerialObj.Serialize(st, TestObject)
Dim tmp As TestClass
st.Seek(0, SeekOrigin.Begin)
tmp = CType(SerialObj.Deserialize(st), TestClass)
ArabicConsole.WriteLine(tmp.X)
ArabicConsole.WriteLine(tmp.Y)
ArabicConsole.WriteLine(tmp.Z)
ArabicConsole.WriteLine(tmp.W)
'
'
'
'
1
0
0
5
XML
Web Services
XML XML
..NET Framework XmlSerializer
:Public :
w w.pdf actory.com
XML '
Public Class Person
End Class
'
Class Car
End Class
: Public :
'
'
'
End Class
Object Graph
Circular Reference
.Binary
XML
XML
Web Services
. .XML
:
Imports System.Xml.Serialization
w w.pdf actory.com
340
: .NET Framework
XmlSerializer
XML
XML ) XmlSerializer
(System.XML.Serialization
BinaryFormatter :
C:\Test.XML
:XML
>? "<?xml version="1.0
"<Person xmlns:xsd="http://www.w3.org/2001/XMLSchema
>"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
></FullName ><FullName
><Age>99</Age
></Person
XML :
XML .
w w.pdf actory.com
- BinaryFormatter
'
' 99
st.Close()
Attributes .NET
: .XML
:XmlRoot Attributes
<XmlRoot("PersonRecord", namespace:="http://www.dev4arabs.com")> _
Public Class Person
Public Name As String
Public Age As Integer
End Class
:Person PersonRecord
w w.pdf actory.com
342
.NET Framework :
:XmlElement Attributes
XML Tags XML
.
Name
: FullName
:XmlAttributeAttribute Attributes
XmlAttributeAttribute Attributes
: ID Element XML Documents
End Class
:
<?xml version="1.0" ?>
<Person xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
PersonID="1">
<Name>< /Name>
<Age>99</Age>
</Person>
w w.pdf actory.com
:XmlText Attributes
XML XmlText Attributes
:Tags
End Class
XML Tags
: " = "
<?xml version="1.0" ?>
<Person xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>< /Name>
<Age>99</Age>
</Person>
w w.pdf actory.com
344
.NET Framework :
Customer
) XML
XmlArray and XmlArrayItem Attributes Bold
:(
:XmlIgnore Attributes
XmlIgnore Attributes
: MotherName .
End Class
w w.pdf actory.com
XmlSerializer
.XML
- - XML
.
.
UnknownElement
XML
.
.
XML
. Person:
XML
w w.pdf actory.com
346
.NET Framework :
<Age>99</Age>
</Person>
Age
XML . Name
UnknowXMLElemntEvent
e.ObjectBeingDeserialized
XML
e.Element.Name
FirstName . e.Element.InnerXml
.Name LastName
WithEvents UnknownElement
: AddHandler
w w.pdf actory.com
'
' 99
Object
Serialization
MSDN .
-
.Threading
w w.pdf actory.com
w w.pdf actory.com
10
Threading
Windows API
Multithreading
.NET Framework
Threading
!
:
Imports System.Threading
Thread . Thread
Process )
.(Process
.Multi-Threaded Process
Single
Threaded Process )
.NET Framework
Garbage Collection(.
w w.pdf actory.com
350
: .NET Framework
.
(1 (2 (3
.Three Threads
.
- .
Server
Client
.
.
.
!
: Free Threading
.Apartment Threading
Global Variable
w w.pdf actory.com
: Threading
351
. Two Threads
.
.
- X
A B :
10 If X < 0 Then
20
)" X "( ArabicConsole.WriteLine
30 End If
A X
10 - X
20 ) (B X
A 20
X .
Apartment Threading
. - X -
A B
. Visual Basic .NET
Synchronization
.
Processor
w w.pdf actory.com
352
: .NET Framework
.
:
: 10
Single Thread 10
10 20
) 15 = 2 ( 10 + 20 .
20 = 10 + 10
) (10
.
: 10
. 1
11 ) 6 = 2 ( 1 + 11 .
1 2
1.5 .
.
. .
Background .
Auto Spell-Checker Microsoft Word
w w.pdf actory.com
: Threading
353
:
.
(Parameters :
)(Sub Main
Dim counter As Integer
)Dim newThread As New Thread(AddressOf DoSomething
)(newThread.Start
For counter = 1 To 1000
)Console.Write("$"c
Next
End Sub
)(Sub DoSomething
Dim counter As Integer
For counter = 1 To 1000
)Console.Write("*"c
Next
End Sub
:
*********************************$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
******************************************************$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$************************$$$$$$$$$$$$
Console
ArabicConsole .
w w.pdf actory.com
354
: .NET Framework
newThread
)( Start )
)( (DoSomething
)( newThread.Start .
)( Start )( Abort .
Thread.CurrentThread Thread
)(Sub DoSomething
Dim counter As Integer
For counter = 1 To 1000
If counter = 100 Then
' )(Thread.CurrentThread.Abort
End If
)Console.Write("*"c
Next
End Sub
)( Abort
)( Suspend
)( Resume :
'
)(newThread.Start
'
)(newThread.Suspend
w w.pdf actory.com
: Threading
355
) ( '
)(newThread.Resume
'
)(newThread.Abort
)( Sleep ) (
0.001:
' )Thread.CurrentThread.Sleep(500
)( Join
'
)(newThread.Start
'
)( newThread.Join
'
'
IsAlive - )(:Join
'
)(newThread.Start
w w.pdf actory.com
356
: .NET Framework
'
IsAlive :
If Thread.CurrentThread.IsAlive Then
True .
Name String
Debugging Debug location
) :(1- 10
w w.pdf actory.com
: Threading
357
ThreadState
ThreadState.Aborted
ThreadState.AbortRequested
ThreadState.BackGround
BackGround
ThreadState.Running
.Thread
ThreadState.Suspended
ThreadState.SuspendedRequested
.
.
ThreadState.UnStarted
Join
ThreadState.WaitSleepJoin
:Priority
Windows Multitasking
. ) Windows
Processes
. 10
- )
w w.pdf actory.com
358
: .NET Framework
(
) Active Process (.
Windows
Priority Windows NT
.
Windows
Programs
Processing
) Control Panel -> System -> Advanced -> Performance -> Settings - 10
.(2
:2- 10 .
w w.pdf actory.com
: Threading
359
- BelowNormal Low :
Threads
Process
Priority
ThreadPriority.BelowNormal :
.ThreadPriority.Highest
w w.pdf actory.com
360
: .NET Framework
:3- 10 .
Priority ThreadPriority.Normal (:
)(Sub Main
Dim counter As Long
)Dim newThread As New Thread(AddressOf DoSomething
)(newThread.Start
'
'
For counter = 1 To 200000000
Next
)"Console.WriteLine("THREAD A HAS FINISHED
End Sub
w w.pdf actory.com
Threading :
361
Sub DoSomething()
Dim counter As Integer
For counter = 1 To 100
Next
Console.WriteLine("THREAD B HAS FINISHED")
End Sub
100
:
Sub Main()
Dim counter As Long
Dim newThread As New Thread(AddressOf DoSomething)
'
Thread.CurrentThread.Priority = ThreadPriority.Highest
newThread.Priority = ThreadPriority.Lowest
newThread.Start()
'
'
For counter = 1 To 200000000
Next
Console.WriteLine("THREAD A HAS FINISHED")
End Sub
Sub DoSomething()
Dim counter As Integer
For counter = 1 To 100
Next
Console.WriteLine("THREAD B HAS FINISHED")
End Sub
w w.pdf actory.com
362
: .NET Framework
) 200 (
ThreadPriority.Highest
ThreadPriority.Lowest :
Pentium 800 MHz
.
:IsBackground
Background Threads
.
Background Thread
) IsBackground (:
newThread.IsBackground = True
If newThread.IsBackground Then
)(newThread.Abort
End If
. )
(:
w w.pdf actory.com
Threading :
363
Module Module1
Sub main()
Dim newThread As New Thread(AddressOf DoSomething)
newThread.Start()
End Sub
Sub DoSomething()
Dim counter As Integer
'
For counter = 1 To 1000
Console.WriteLine(counter)
Next
Console.Read()
End Sub
End Module
Background Thread
:
Module Module1
Sub main()
Dim newThread As New Thread(AddressOf DoSomething)
'
newThread.IsBackground = True
newThread.Start()
End Sub
Sub DoSomething()
Dim counter As Integer
'
For counter = 1 To 1000
Console.WriteLine(counter)
Next
Console.Read()
End Sub
End Module
w w.pdf actory.com
364
: .NET Framework
ArabicConsole
ArabicConsole
.
Exception
:
Module Module1
)(Sub main
)Dim newThread As New Thread(AddressOf DoSomething
)(newThread.Start
'
'
End Sub
)(Sub DoSomething
Dim counter As Integer
)(Throw New Exception
End Sub
End Module
Throw Exception
. Catch Exception
w w.pdf actory.com
: Threading
365
:
)Dim newThread As New Thread(AddressOf DoSomething
Try
)(newThread.Start
Catch
End Try
Try End Try
.
Regional Settings
CurrentCulture
CultureInfo :
Imports System.Globalization
Module Module1
)(Sub main
)Dim newThread As New Thread(AddressOf DoSomething
_ Thread.CurrentThread.CurrentCulture = New
)"CultureInfo("ar-SA
_ newThread.CurrentCulture = New
)"Globalization.CultureInfo("ar-EG
)(newThread.Start
100.00 ' ))"MsgBox(100.ToString("C
End Sub
)(Sub DoSomething
100.000 ' ))"MsgBox(100.ToString("C
End Sub
End Module
w w.pdf actory.com
366
: .NET Framework
)( Abort
)( Suspend Safe
Point - Safe Points -.NET Documentation
Garbage Collection .
) .NET Documentation Safe
Points (.
. -
.
MSDN .
: )(Abort
) (
Exit Sub .
w w.pdf actory.com
: Threading
367
Background Threads
-
.
)( Abort ) (
Module Module1
)(Sub main
)Dim newThread As New Thread(AddressOf DoSomething
)(newThread.Start
)(Thread.CurrentThread.Abort
End Sub
)(Sub DoSomething
End Sub
End Module
)(:Abort
Module Module1
)(Sub main
)Dim newThread As New Thread(AddressOf DoSomething
)(Thread.CurrentThread.Abort
End Sub
)(Sub DoSomething
End Sub
End Module
.
Visual Studio .NET
!
w w.pdf actory.com
368
: .NET Framework
) ( )( .
Thread Free Threading
.... . Synchronization
.
w w.pdf actory.com
: Threading
369
) Visibility (Lifetime
-
. Local
Dynamic Variables
:
)(Sub Main
)Dim newThread As New Thread(AddressOf DoSomething
)Dim newThread2 As New Thread(AddressOf DoSomething
)(newThread.Start
)(newThread2.Start
End Sub
)(Sub DoSomething
'
Dim X As Integer
'
Dim counter As Integer
Do
counter += 1
X += 1
Loop Until counter >= 100
)Console.WriteLine(X
End Sub
:
100
100
counter 100 .
w w.pdf actory.com
370
: .NET Framework
)(Sub DoSomething
'
Dim X As Integer
'
Static counter As Integer
Do
counter += 1
X += 1
Loop Until counter >= 100
)Console.WriteLine(X
End Sub
) X (
:
100
1
Stack
- -
.
ThreadStatic Attribute
ThreadStatic Attributes
Module Module1
Dim X As Integer
<ThreadStatic()> Dim Y As Integer
)(Sub Main
)Dim newThread As New Thread(AddressOf DoSomething
X = 100
Y = 100
)(newThread.Start
)(newThread.Join
w w.pdf actory.com
Threading :
371
ThreadStatic Attribute
ThreadStatic Attribute
Modules )
(Shared Classes
:X
Class TestClass
'
<ThreadStatic()> Public X As Integer
' Shared
<ThreadStatic()> Public Shared Y As Integer
End Class
Module Module1
Dim TestObject As New TestClass()
Sub Main()
Dim newThread As New Thread(AddressOf DoSomething)
TestObject.X = 100
TestObject.Y = 100
newThread.Start()
newThread.Join()
Console.WriteLine(TestObject.X) ' 200
Console.WriteLine(TestObject.Y) ' 100
End Sub
Sub DoSomething()
TestObject.X = 200
TestObject.Y = 200
End Sub
End Module
w w.pdf actory.com
372
: .NET Framework
TLS
Thread Local
(TLS) Storage
. TLS Data
) Slot .(10- 4
String
.
)(:AllocateNamedDataSlot
'
)"Thread.AllocateNamedDataSlot("Name
w w.pdf actory.com
: Threading
373
LocalDataStoreSlot
:
Name
)(:SetData
)( GetData :
' ))Console.WriteLine(Thread.GetData(namedDataSlot
nameDataSlot
Name )(:GetNamedDataSlot
)(:FreeNamedDataSlot
)"Thread.FreeNamedDataSlot("Name
TLS
)( GetNamedDataSlot
.
w w.pdf actory.com
374
: .NET Framework
Unnamed data
Global Variables
TLS ) TLS
(.
Class ThreadData
Public ThreadName As String
Public Data As Integer
)(Sub DoSomething
)Console.WriteLine(Me.ThreadName & " Data = " & Data
End Sub
End Class
ThreadData
)(:DoSomthing
w w.pdf actory.com
: Threading
375
Module Module1
)(Sub Main
)(Dim One As New ThreadData
)(Dim Two As New ThreadData
"One.ThreadName = "THREAD B
One.Data = 10
"Two.ThreadName = "THREAD C
Two.Data = 20
))With New Thread((AddressOf One.DoSomething
)(.Start
End With
))With New Thread((AddressOf Two.DoSomething
)(.Start
End With
)"Console.WriteLine("Waiting...
End Sub
End Module
:
Waiting
THREAD B Data = 10
THREAD C Data = 20
THREAD C Data = 20
Waiting
THREAD B Data = 10
ThreadData
Events
:ThreadData
w w.pdf actory.com
376
: .NET Framework
Class ThreadData
)(Event ThreadFinish
)(Sub DoSomething
)(RaiseEvent ThreadFinish
End Sub
End Class
:
Module Module1
)(Sub Main
End Sub
)(Sub ThreadHasBeenFinished
End Sub
End Module
)( ThreadHasBeenFinished
)
AddHandler ( .
.
w w.pdf actory.com
: Threading
377
Thread Synchronization
.
- :
If X = 10 Then
X = 0
Else
X = 10
End If
SyncLock y
If X = 10 Then
X = 0
Else
X = 10
End If
End SyncLock
w w.pdf actory.com
378
: .NET Framework
:
Module Module1
)(Sub main
Dim counter As Integer
For counter = 1 To 9
)With New Thread(AddressOf DoSomething
).Name = CStr(counter
)(.Start
End With
Next
)(Console.Read
End Sub
)(Sub DoSomething
Dim counter As Integer
_ & " Console.WriteLine("From Thread
)Thread.CurrentThread.Name
For counter = 1 To 1000
)Console.Write(Thread.CurrentThread.Name
Next
)(Console.WriteLine
End Sub
End Module
From Thread 1
111111111111111111111111111111111111111 From Thread 2
222222222222222222222222222221111111111111111111 From Thread 7
77711111222222222221111111
)( DoSomething SyncLock
:End SyncLock
w w.pdf actory.com
: Threading
379
'
"Public ThreadLocker As String = "Lock1
)(Sub DoSomething
Dim counter As Integer
SyncLock ThreadLocker
_ & " Console.WriteLine("From Thread
)Thread.CurrentThread.Name
For counter = 1 To 1000
)Console.Write(Thread.CurrentThread.Name
Next
)(Console.WriteLine
End SyncLock
End Sub
From Thread 1
111111111111111111111111111111111111111111111111111
From Thread 5
555555555555555555555555555555555555555555555555555
From Thread 3
333333333333333333333333333333333333333333333333333
From Thread 2
222222222222222222222222222222222222222222222222222
Synchronization
SyncLock End SyncLock
Synchronization
_ >)(<System.Runtime.Remoting.Contexts.Synchronization
Class Test
' ContextBoundObject
Inherits ContextBoundObject
End Class
w w.pdf actory.com
380
: .NET Framework
Synchronization
ContextBoundObject .
Synchronization Shared Members
. .MethodImpl
MethodImpl
Synchronization
MethodImpl
.Shared Members
'
Imports System.Runtime.CompilerServices
Class Test1
_ >)<MethodImpl(MethodImplOptions.Synchronized
)Sub AA(ByVal x As Char
End Sub
_ >)<MethodImpl(MethodImplOptions.Synchronized
)Shared Sub BB(ByVal x As Char
End Sub
End Class
w w.pdf actory.com
: Threading
381
Class Test2
_ >)<MethodImpl(MethodImplOptions.Synchronized
)Sub AA(ByVal x As Char
End Sub
_ >)<MethodImpl(MethodImplOptions.Synchronized
)Sub BB(ByVal x As Char
End Sub
End Class
-
)( AA
)(.BB
) Test1(
) Instance Members
(.
.NET Documentation
Monitor
SyncLock End SyncLock .
-
. Monitor
SyncLock End SyncLock .
w w.pdf actory.com
382
: .NET Framework
Monitor
SyncLock X
'
End SyncLock
Monitor :
"Public X As String = "Lock1
)Monitor.Enter(X
'
)Monitor.Exit(X
Monitor :
"Public X As String = "Lock1
'
)Monitor.Exit(X
)( Exit )( Enter
.
:
)If Y = 0 Then Monitor.Exit (X
w w.pdf actory.com
: Threading
383
)( Enter )( Exit
)(:TryEnter
'
'
)Monitor.TryEnter(X, 500
'
'
)Monitor.Exit(X
ThreadPool
-
) (Thread
- .
Thread Pool
- .
)( QueueUserWorkItem
:Object
)ThreadPool.QueueUserWorkItem(AddressOf DoSomething
' Object
)Sub DoSomething(ByVal x As Object
End Sub
ThreadPool
:Thread
w w.pdf actory.com
384
: .NET Framework
)( QueueUserWorkItem
- 25 Priority
)( GetMaxThreads
)( GetAvailableThreads
:ByRef
Dim x, y, z As Integer
)ThreadPool.GetMaxThreads(x, z
)ThreadPool.GetAvailableThreads(y, z
Console.WriteLine(x) ' 25
Console.WriteLine(y) ' 23
)( GetMaxThreads
)( GetAvailableThreads
.IO MSDN
.
w w.pdf actory.com
Threading :
385
Module Module1
Dim x As Integer
Sub main()
x = 100
ThreadPool.QueueUserWorkItem(AddressOf DoSomething, Nothing)
Thread.Sleep(1000)
Console.WriteLine(x) ' 100
Console.Read()
End Sub
Sub DoSomething(ByVal x As Object)
x = 1000
Console.WriteLine(x) ' 1000
End Sub
End Module
:Managed Heap
Class TestClass
Public x As Integer
End Class
Module Module1
Public TestObject As New TestClass()
Sub main()
TestObject.x = 100
ThreadPool.QueueUserWorkItem(AddressOf DoSomething, Nothing)
Thread.Sleep(1000)
Console.WriteLine(TestObject.x) ' 1000
Console.Read()
End Sub
Sub DoSomething(ByVal x As Object)
TestObject.x = 1000
End Sub
End Module
:IsThreadPoolThread
If Thread.CurrentThread.IsThreadPoolThread Then
End If
w w.pdf actory.com
386
: .NET Framework
:
Module Module1
)(Sub main
Dim counter As Integer
)ThreadPool.QueueUserWorkItem(AddressOf DoSomething, 1
)ThreadPool.QueueUserWorkItem(AddressOf DoSomething, 2
)ThreadPool.QueueUserWorkItem(AddressOf DoSomething, 4
)(Console.Read
End Sub
)Sub DoSomething(ByVal x As Object
Dim counter As Integer
For counter = 1 To 100000
)Console.Write(x
Next
End Sub
End Module
Thread
ThreadPool - -
Thread
(IsBackground )( .Abort
Thread
Timers
.System
.Controls
w w.pdf actory.com
Threading :
387
System.Timers.Timer
)Elapsed Timers.Timer
( AddHandler WithEvents
: Interval
'
Dim Timer1 As New Timers.Timer (1000)
'
Dim Timer2 As New Timers.Timer ()
Timer2.Interval = 500
Start()
.Stop()
:System.Timers.Timer
Module Module1
Sub main()
Dim MyTimer As New System.Timers.Timer()
AddHandler MyTimer.Elapsed, AddressOf DoSomething
MyTimer.AutoReset = True
MyTimer.Interval = 1000
MyTimer.Start()
Console.Read()
End Sub
Sub DoSomething(ByVal sender As Object, ByVal e As
Timers.ElapsedEventArgs)
Console.WriteLine(Now.ToString("hh:mm:ss"))
End Sub
End Module
w w.pdf actory.com
388
: .NET Framework
Elapsed
System.Timers.Timer
:
Console.WriteLine(Thread.CurrentThread.IsThreadPoolThread) ' True
System.Threading.Timer
Threading.Timer Timers.Timer
Threading.Timer ) Delegate
(Event .
Threading.Timer
:Object
End Sub
:
' 100
) Dim MyTimer As New Threading.Timer( , 100,
)Sub DoSomething(ByVal x As Object
Console.WriteLine(x) ' 100
End Sub
w w.pdf actory.com
: Threading
389
5 '
)Dim MyTimer As New Threading.Timer( , , 5000, 0
10 '
)Dim MyTimer As New Threading.Timer( , , 10000, 500
)( Change
.
)(.Dispose
:Threading.Timer
Module Module1
)(Sub main
_ Dim MyTimer As New Threading.Timer(AddressOf DoSomething,
)Nothing, 1, 2000
)(Console.Read
End Sub
)Sub DoSomething(ByVal x As Object
))"Console.WriteLine(Now.ToString("hh:mm:ss
End Sub
End Module
System.Threading.Timer
.
w w.pdf actory.com
390
: .NET Framework
Threading
Multi-
Threading
w w.pdf actory.com
11
Assemblies
Windows Class Libraries
.Assembly
.NET .
.Managed Modules
Managed Modules
) Visual Basic .NET .NET(
.
:
(1
Windows Microsoft
.Windows
(2
.NET Framework
w w.pdf actory.com
392
: .NET Framework
Metadata...
(3
:Metadata
) Classes Modules
Reflection
Classes .
(4
.NET JIT
Assembly Microsoft
Metadata
Reflection Classes
Visual Basic .NET -
Assemblies
Assembly .NET
-
. Nonexecutable
w w.pdf actory.com
: Assemblies
393
... Pictures.
.NET
) .(1- 11
:1- 11
EXE
Visual Studio .NET
] .[F5
AL.EXE .
- EXE DLL
- .
w w.pdf actory.com
394
: .NET Framework
) ( -
Libraries DLL
Reference
.NET.
.Entry Point )
)( Sub Main (Visual Basic .NET
.
Console
.
:2- 11 .
w w.pdf actory.com
: Assemblies
395
Private Assemblies
.Shared Assemblies
.
. :
C:\Folder\AAA.DLL
C:\BBB.EXE
C:\Folder\CCC.EXE
C:\Folder\SubFolder\DDD.EXE
) Probing MSDN
.
Add References Visual Studio .NET
- .
-
!
.NET
X:\Windows\assembly
) X:\Windows\assembly 3- 11 (.
w w.pdf actory.com
396
: .NET Framework
:3- 11 .GAC
Windows Explorer
Delete GAC
GACUTIL.EXE .
GAC Administrator
.
w w.pdf actory.com
: Assemblies
397
Strong Names
Private Assemblies
Shared Assemblies
GAC
AAA
GAC :
X:\Windows\assembly\GAC\AAA\1.2.3432423
X:\Windows\assembly\GAC\AAA\2.4.12334
Public Key )
128(
!
... Assembly's
.Strong Name
Assembly
Assembly
... :
Imports System.Reflection
Imports System.Runtime.InteropServices
w w.pdf actory.com
398
: .NET Framework
>)" "(AssemblyTitle
"(AssemblyDescription
>)" "(AssemblyCompany
>)" "(AssemblyCopyright
>)"AssemblyVersion("1.0.2321432
<Assembly:
<Assembly:
>)"
<Assembly:
<Assembly:
<Assembly:
*
:
>)"*<Assembly: AssemblyVersion("1.0.
AssemblyInfo.vb .
Configuration Files
.Configuration Files
XML Notepad
.
Windows ) 3.x (
*.ini .
w w.pdf actory.com
: Assemblies
399
.NET
.NET : Application Configuration File
.File :
.config .
:
C:\MyProg\application.exe
:
C:\MyProg\application.exe.config
Shared Assemblies
.
- ) (
- .
w w.pdf actory.com
400
: .NET Framework
\) C:\WINDOWS\Microsoft.NET\Framework\vxxx\CONFIG xxx
.NET Framework (
:
C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\CONFIG\machine.config
></configuration
> <configuration .
machine.config
.
.NET
:Documantation
w w.pdf actory.com
: Assemblies
401
>:<requiredRuntime
.NET Framework
XML ) case-
.sensitive .
> <requiredRuntime
) (
Windows Registry
safemode
True
>:<requiredRuntime
>:<gcConcurrent
Garbage Collection
. MSDN
w w.pdf actory.com
402
: .NET Framework
Garbage Collection
.
>:<add
> <appSettings )
... (
System.Configuration.ConfigurationSettings.AppSettings
w w.pdf actory.com
Assemblies :
403
Imports System.Configuration.ConfigurationSettings
Module Module1
Sub main()
' www.dev4arabs.com
ArabicConsole.WriteLine(AppSettings("Site"))
' C:\Folder\Data.MDB
ArabicConsole.WriteLine(AppSettings("DBPath"))
' False
ArabicConsole.WriteLine(AppSettings("Show Startup Window"))
End Sub
End Module
.Control Panel
w w.pdf actory.com
404
: .NET Framework
> <gcConcurrent
Garbage Collection
machine.config My Computer
w w.pdf actory.com
: Assemblies
405
Application
.
.Configured Assemblies
(
.Command Prompt
Command
.NET .
(.NET\FrameworkSDK\Bin Paths
w w.pdf actory.com
406
: .NET Framework
Microsoft
Visual Studio .NET
Visual Programming !
.NET Documentation
.
VBC.EXE
test.vb :
' test.vb
Imports System
Module Module1
Sub Main
)"Console.WrilteLine ("Welcome
End Sub
End Module
VBC.EXE
:
C:\>vbc test.vb
w w.pdf actory.com
: Assemblies
407
:
C:\>vbc test.vb test2.vb test3.vb
test.exe
) /out * (:
myprog.exe
Console
) ( winprog.exe
C:\>vbc winprog.vb /target:winexe
) ( mylib.exe
C:\>vbc mylib.vb /t:library
VBC.EXE
AL.EXE module :/target
test.netmodule )
(
:/addmodule
.AL.EXE
w w.pdf actory.com
408
: .NET Framework
AL.EXE
AL.EXE Assembly Linker
.Multiple File Assemblies
.NET .
AL.EXE
file1.netmodule
.myass.dll
:7- 11 .
.NET Documentation
myass.dll
.Assembly's Manifest
Library
w w.pdf actory.com
: Assemblies
409
) ( Console Application
C:\>al file.netmodule /t:exe /out:myprog.exe
) ( Windows Application
C:\>al file.netmodule /t:win /out:myprog.exe
Entry Point
Console Application Windows Application
. )( Sub Main
:/main
C:\test>al file.netmodule /t:exe /out:myprog.exe /main:Module1.main
4
.NET Documentation
/main
case-sensitive Visual Basic .NET
.case insensitive
Visual C# .NET .Visual Basic .NET
file1.vb file2.vb :
' file.vb
Public Module MainModule
)( Public Sub Main
)(Sub2
End Sub
End Module
' file2.vb
Module mdlFile2
)( Sub Sub2
)"System.Console.WriteLine ("VB code works.
)(file3.clsfile3.Sub3
End Sub
End Module
w w.pdf actory.com
410
: .NET Framework
C# ) .cs (C Sharp
.CSC.EXE
C:\Test (CSC.EXE) C#
w w.pdf actory.com
: Assemblies
411
.file3.netmodule file.vb
file2.vb VBC.EXE
/addmodule file2.vb
)( Sub3 :
AL.EXE
(/t:exe) Console Application )(Main
) (/main:MainModule.Main ):(/out:myprog.exe
/t:exe /out:myprog.exe
MS-DOS :
C:\test>myprog
VB code works.
C# code works.
_ >C:\test
) (8- 11 .
w w.pdf actory.com
412
: .NET Framework
SN.EXE
) Public Key
Private Key (.
VBC.EXE AL.EXE
/keyfile :
:AssemblyInfo.vb
)"<Assembly: AssemblyKeyFile("mykey.snk
w w.pdf actory.com
: Assemblies
413
GACUTIL.EXE
Shared Assembly
GACUTIL.EXE
GAC :/i
C:\>gacutil /i mylib.dll
GAC :/l
C:\>gacutil /l
GAC
:/u
C:\>gacutil /u mylib
/u mylib
) u :(/u
w w.pdf actory.com
414
: .NET Framework
MSDN
Reflection Classes
.
w w.pdf actory.com
12
Reflection
Classes
Reflection Classes
System.Reflection Assemblies
(.
" ".
IntelliSense Visual
Studio .NET .
System.Reflection
:
Imports System.Reflection
Assembly : .Module
.NET
Documentation .
w w.pdf actory.com
416
: .NET Framework
Assembly
Assembly - .
New
)(:GetExecutingAssembly
)(:LoadFrom
]Dim ass As [Assembly
)"ass = [Assembly].LoadFrom("C:\myLib.dll
.MSDN
) (Public Key
FullName
GAC GlobalAssemblyCache Location
w w.pdf actory.com
: Reflection Classes
417
EntryPoint
Refelection.MethodInfo :
EntryPoint Nothing
Library .
Assemblies
Entry Point MethodInfo
.
)( GetTypes Type
) ... ( :
)( GetTypes )
Friend (Private
)( GetExportedTypes Public
w w.pdf actory.com
418
: .NET Framework
Late Binding
)( CreateInstance
:
Module
)( GetModule Assembly
)( GetModules :
w w.pdf actory.com
: Reflection Classes
419
.
System.Type .
System.Type
- System. Reflection
Type .System System.Type
Primitive
New
Type - )( GetTypes
Assembly:
)( GetType Visual
:Basic .NET
Dim t As Type
)t = GetType(Integer
ArabicConsole.WriteLine(t.FullName) ' System.Int32
w w.pdf actory.com
420
: .NET Framework
)( GetType Type
:Late Binding
Dim t As Type
)(Dim obj As Object = New TestClass
)(t = obj.GetType
ArabicConsole.WriteLine(t.FullName) ' MyNamespace.TestClass
)( GetType Overloads
System.Type :Sring
Dim t As Type
)"t = Type.GetType("System.Double
)Console.WriteLine(t.FullName
Case-
)( GetType )( GetTypeArray
:COM
COM
Type COM
)( GetTypeFromProgID ) ProgID
COM (:
w w.pdf actory.com
: Reflection Classes
421
Type Name
FullName
)ArabicConsole.WriteLine(t.Name
)ArabicConsole.WriteLine(t.FullName
)ArabicConsole.WriteLine(t.Module
BooleanIsInterface IsClass :
)ArabicConsole.WriteLine(t.IsClass
)ArabicConsole.WriteLine(t.IsValueType
.Friend
w w.pdf actory.com
422
: .NET Framework
MSDN .
) (
. ) (
MSDN .
MemberInfo
MemberInfo Member ) (
PropertyInfo FieldInfo :
:1- 12 MemberInfo
w w.pdf actory.com
: Reflection Classes
423
MemberInfo MemberInfo
New
)( GetMembers :
:Integer
MaxValue
MinValue
ToString
GetTypeCode
ToString
CompareTo
GetHashCode
Equals
ToString
ToString
Parse
Parse
Parse
Parse
GetType
Overrides
)( GetMembers
Enum BindingFlags :
BindingFlags.Public
BindingFlags.NonPublic .
w w.pdf actory.com
424
: .NET Framework
BindingFlags.DeclaredOnly
.
Instance Members
Public :
:
ToString
GetTypeCode
ToString
CompareTo
GetHashCode
Equals
ToString
ToString
Overloads .
:
MemberInfo
Name
w w.pdf actory.com
: Reflection Classes
425
Shared
.IsStatic
FieldInfo Field FieldInfo
.MemberInfo
FieldInfo New
)( GetFields
) Person (:
Class Person
Public Name As String
Public BirthDate As Date
Public Salary As Decimal
Public Address As String
End Class
:
Name
BirthDate
Salary
Address
w w.pdf actory.com
426
: .NET Framework
)( GetFields BindingFlags
)(.GetMembers
:
FieldInfo IsNotSerialized False
FieldInfo )( SetValue
)( GetValue
Late
.Binding
.MemberInfo
PropertyInfo New
)( GetProperties
w w.pdf actory.com
: Reflection Classes
427
:
Chars
Length
)( GetProperties BindingFlags
)(.GetMembers
CanWrite
PropertyType Type :
FieldInfo )( SetValue
)( GetValue
Late
) (Property Set :
Property xxxx() As yyyy
Get
'
End Get
)Set(ByVal Value As yyyy
'
End Set
End Property
w w.pdf actory.com
428
: .NET Framework
MethodInfo Method
.MemberInfo
MethodInfo New
)( GetMethods
:
ToString
GetTypeCode
ToString
CompareTo
GetHashCode
Equals
ToString
IsInfinity
IsPositiveInfinity
IsNegativeInfinity
IsNaN
ToString
Parse
Parse
Parse
Parse
TryParse
GetType
)( GetMethods BindingFlags
)(.GetMembers
w w.pdf actory.com
: Reflection Classes
429
:
MethodInfo ReturnType
Type ) Function (
IsAbstract True MustOverride
MethodInfo )( Invoke
.Late Binding
MethodInfo
PropertyInfo .
EventInfo Event EventInfo
.MemberInfo
EventInfo New
)( GetEvents
) TestClass (:
Class TestClass
)(Event XXX
)(Event YYY
)(Event ZZZ
End Class
w w.pdf actory.com
430
: .NET Framework
:
XXX
YYY
ZZZ
)( GetEvents BindingFlags
)(.GetMembers
EventInfo
.MemberInfo
EventInfo )(GetAddMethod
MethodInfo
)( AddHandler )( GetRemoveMethod
)( .RemoveHandler )( GetRaiseMethod
MethodInfo )
(.
Parameters
MethodInfo PropertyInfo GetParameters
ParameterInfo Parameter .
ParameterInfo
Name ParameterType
IsOptional True
Optional
.DefaultValue
w w.pdf actory.com
: Reflection Classes
431
)( MySub
:TestClass
Module MainModule
Class TestClass
)Sub MySub(ByVal x As Integer, ByRef y As String
End Sub
End Class
)(Sub main
)Dim T As Type = GetType(TestClass
Dim P As ParameterInfo
)(For Each P In T.GetMethod("MySub").GetParameters
_ & " ArabicConsole.WriteLine(P.Name & " As
)P.ParameterType.ToString
Next
End Sub
End Module
:
x As System.Int32
y As System.String
... TestClass .
Reflection -
.
ReflectionExample
ReflectionExample :
w w.pdf actory.com
432
.NET Framework :
Class ReflectionExample
Public ExampleField As String
Private m_ExampleProperty As Integer
Public Property ExampleProperty() As Integer
Get
Return m_ExampleProperty
End Get
Set(ByVal Value As Integer)
m_ExampleProperty = Value
End Set
End Property
Public Sub ExampleMethod(ByVal x As Integer, ByVal y As Integer)
ArabicConsole.WriteLine(-x)
ArabicConsole.WriteLine(-y)
End Sub
Public Sub ExampleMethod2(Optional ByVal y As Integer = -1)
ArabicConsole.WriteLine(y)
End Sub
End Class
(... )
GetField() GetFields()
GetValue() FieldInfo
:
w w.pdf actory.com
: Reflection Classes
433
)( SetValue
)( GetProperties )(GetProperty
PropertyInfo
)( GetValue Nothing
:
ExampleProperty1 )(SetValue
) Nothing (:
MethodInfo
)( Invoke
w w.pdf actory.com
434
: .NET Framework
Nothing Object
:
5
-5
Optional Parameters
Type.Missing
)( ExampleMethod2
:10
Dim
Dim
Dim
Dim
)M.Invoke(obj, params
)M.Invoke(obj, params2
:
-1
10
w w.pdf actory.com
: Reflection Classes
435
)
Late Binding .
Reflection
.AssemblyName.TypeName )(CreateInstance
System.Activator Type :
Constructor
)( CreateInstance :Object
System.Activator
) ConstructorInfo :(MemberInfo
)"Dim T As Type = Type.GetType("MyAssembly.MyClass
} )Dim types() As Type = { GetType(Integer), GetType(Integer
)Dim con As ConstructorInfo = T.GetConstructor (types
}Dim params() As Object = {-5, 5
' )Dim obj As Object = con.Invoke(params
w w.pdf actory.com
436
: .NET Framework
StackTrace
Exception
System.Diagnostics
Reflection.
StackTrace
StackTrace New
)( GetFrame StackFrame
StackFrame )( GetMethod
) MethodBase System.Collection
)( CallerSub )(:CalleeSub
Imports System.Reflection
Imports System.Diagnostics
Module Module1
)(Sub main
)(CallerSub
End Sub
)(Sub CallerSub
)(Dim ST As New StackTrace
Dim counter As Integer
)"********* ArabicConsole.WriteLine("** CallerSub
w w.pdf actory.com
Reflection Classes :
437
Main()
** CallerSub *********
CallerSub ()
main ()
** CalleeSub *********
CalleeSub ()
CallerSub ()
main ()
String GetStack()
w w.pdf actory.com
438
: .NET Framework
)( GetStack
)( GetStack .
Reflection
.NET
Framework )
Object
- Windows .
w w.pdf actory.com
Windows
w w.pdf actory.com
w w.pdf actory.com
13
Windows Forms
Windows
ArabicConsole
.System.Windows.Forms
Windows
.Windows Application
Windows .
Console Application
:
Imports System.Windows.Forms
Windows Application
Imports Project Property
) Pages .(7-2
w w.pdf actory.com
442
: Windows
Windows Forms
Visual Basic .NET
System.Windows.Forms.Form
End Class
)( Show :
Dim myForm As New Form1
)( myForm.Show
Form Designer
Code Generator
) .(1- 13
Form Class
.
w w.pdf actory.com
: Windows Forms
443
.Module
Private
.
Windows Application
Code Editor
) (:
w w.pdf actory.com
444
Windows :
.
:MsgBox Click formWasClicked
w w.pdf actory.com
: Windows Forms
445
)
( ) :(2- 13
:2- 13 .
components
w w.pdf actory.com
446
: Windows
Form1
- System.Windows.Forms.Form :
End Class
)( InitializeComponent
End Class
Destructor )
(:
End Class
w w.pdf actory.com
: Windows Forms
447
)( InitializeComponent
)
( .
'
'
'
_ >)(<System.Diagnostics.DebuggerStepThrough
)(Private Sub InitializeComponent
'
'Form1
'
)Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13
)Me.ClientSize = New System.Drawing.Size(292, 269
"Me.Name = "Form1
"Me.Text = "Form1
End Sub
End Class
InitializeComponent
.
) (:
w w.pdf actory.com
448
: Windows
Windows Application
)( .Show
.
:3- 13 .
)( Application.Run
)( Run )( Sub Main
:
w w.pdf actory.com
: Windows Forms
449
Module MainModule
)(Sub main
)(Dim frmMain As New Form1
)Application.Run(frmMain
End Sub
End Module
Form
Form System.Windows.Forms
) (4- 13 Form
.System.Windows.Forms
:4- 13 Form .
Control Control ToolBox
) 1- 14 ( . ScrollableControl
Control
w w.pdf actory.com
450
: Windows
) (4- 13
Controls
Form )
( .Form
Form
.
Form MSDN
) Properties (5- 13
] [F4 Properties Windows .View
:5- 13 .Properties
w w.pdf actory.com
: Windows Forms
451
Text
.String
False .ControlBox
Icon )( BackgroundImage
) Tile Wall
.(Paper
Opacity 1 0
1 0 0.5
TransparencyKey
.
.
ShowInTaskBar
Task Bar .
w w.pdf actory.com
452
: Windows
7 :FormBorderStyle Sizable
FixedSingle Fixed3D
None .
Hide SizeGripStyle
Size Grip ) (.
:
DesktopBounds DesktopLocation
SetDesktopBounds SetDesktopLocation
CenterScreen
.StartPosition
MaximumSize MinimumSize
True TopMost
.Windows
:Scrolling
True AutoScroll
Scroll Bars
.
HScroll .VScroll
AutoScrollMargin
. ).(0; 0
w w.pdf actory.com
: Windows Forms
453
AutoScrollPosition .Point
Point
) (20 10 '
'
)Me.AutoScrollPosition = New Point(10, 20
Point
.Controls
AutoScrollPosition )(ScrollControlIntoView
)Me.ScrollControlIntoView (TextBox1
) (
) Overrides (Form
Overrides
) 6- 13 (:
w w.pdf actory.com
454
: Windows
:6- 13 .
- )( Show
)( Show
)( Show
Windows )( Show
) Dialog Boxes (
:
w w.pdf actory.com
: Windows Forms
455
)(.Activate
)( Hide
)( Show . )( Close
)( SetDesktopLocation
x y
) (0 0
.
)( SetDesktopBounds :
Dim MyForm As New Form2
)MyForm.SetDesktopBounds(0, 0, 200, 100
)( AddOwnedForm )(:RemoveOwnedForm
.Owned Windows
. Minimize
.Task Bar
)(:AddOwnedForm
)(Dim x As New ownedForm
)(Dim y As New ownedForm
w w.pdf actory.com
456
: Windows
)Me.AddOwnedForm(x
)Me.AddOwnedForm(y
)(x.Show
)(y.Show
OwnedForms
Owner
If Me.Owner Is Nothing
'
Else
'
End If
)(RemoveOwnedForm
.
.NET Framework
Control
w w.pdf actory.com
: Windows Forms
457
:7- 13 .
) ... GotFocus LostFocus Move Resize(
Control
.Form
)( New )(:Dispose
Base Class
w w.pdf actory.com
458
: Windows
End Sub
_ Protected Overloads Overrides Sub Dispose(ByVal
)disposing As Boolean
If disposing Then
End If
)MyBase.Dispose(disposing
End Sub
)( .Dispose
Protected Overloadding
Overriding .
:Load
.
)( Show
:Load
)( Show .
w w.pdf actory.com
: Windows Forms
459
:Paint
Paint
Paint .
Paint.
Scrollbars Paint
Paint
Paint
:
Paint
)( Refresh
:
Activated :Deactivated
Active Window
Activated .Deactivated
w w.pdf actory.com
460
: Windows
Closing :Closed
Closing )( Close
.
True Cancel :
Closed
)(.Me.Show
:
MinimumSizeChange
MinimumSize MaximumSizeChange
MaximumSize MaximizedBoundsChange
.MaximizedBounds
MDI Forms
- MDI
.
.
Windows MDI MDI.
w w.pdf actory.com
: Windows Forms
461
Child Windows
- MDI
) MDI (Child
MDI MdiParent ) :(8- 13
)(Sub main
)(Dim frmMain As New Form1
)(Dim frmChild As New Form1
"frmMain.Text = "MDI Form
frmMain.IsMdiContainer = True
frmChild.MdiParent = frmMain
"frmChild.Text = "Child Form
)(frmChild.Show
)Application.Run(frmMain
End Sub
MdiParent
w w.pdf actory.com
462
: Windows
)( ,AddOwnedForm
MdiParent
.
Menus
) MDI ( )(AddOwnedForm
.
Maximize MDI
MDI
.
True :
If Me.IsMdiChild Then
End If
MdiParent MDI
- True
:
End If
MDI
MidiChildren :
w w.pdf actory.com
: Windows Forms
463
ActiveMdiChild
:
" "= Me.ActiveMdiChild.Text
)( ActivateMdiChild
))Me.ActivateMdiChild(Me.MdiChildren(0
MDI
MdiChildActivate
:
)( LayoutMdi
TileHorizontal :TileVertical
)Me.LayoutMdi(MdiLayout.ArrangeIcons
)Me.LayoutMdi(MdiLayout.Cascade
)Me.LayoutMdi(MdiLayout.TileHorizontal
)Me.LayoutMdi(MdiLayout.TileVertical
Menus
) (4- 15 MainMenu
MainMenu
w w.pdf actory.com
464
: Windows
) Visulally .(9- 13
:9- 13 .
- Delete
Properties Window
.
MainMenu
Menu :
w w.pdf actory.com
: Windows Forms
465
Me.Menu = MainMenu2
MainMenu .Menu
MainMenu
.MenuItem
MenuItem .
Text
& Underline
] [Alt
Checked True
RadioCheck
MenuItems
MenuItem
.Parent
)(GetMainMenu
MainMenu )(PerformClick
Click
Select
) (.
w w.pdf actory.com
466
: Windows
Popup-Menu
Popup-Menus
ContextMenu MainMenu
.
ContextMenu ) (:
Button1.ContextMenu = ContextMenu1
)( Show :
Point
.Controls
DefaultItem True
Default Item
Bold.
ContextMenu
.Popup
MDI
MDI Child
MDI MergeType
MainMenu .MenuItem
w w.pdf actory.com
: Windows Forms
467
MergeType :Add :
MDI
:Remove .MergeOrder :Replace .MDI
MDI
:MergeItems .MergeOrder
MDI .MergeOrder
MergeType MergeOrder .
MDI :
MergeType
MergeItems
MergeItems
Remove
Remove
MergeItems
Add
Add
MergeItems
MergeItems
MergeItems
...
MergeOrder
Child :
w w.pdf actory.com
468
: Windows
MergeType
MergeOrder
MergeItems
Remove
Replace
Replace
Add
Add
Add
MergeItems
9
1
Add
MDI :
) (MDI
) (Child
) (
) (Child
) (Child
) (MDI
) (Child
) (MDI
) (MDI
...
) (MDI
) (Child
) (MDI
) (
) (Child
w w.pdf actory.com
: Windows Forms
469
ContextMenu
AddHandler )(:MenuClicked
Windows Forms
: Modal Form Inheritance
.Localized Forms
Modeless
)( Show
:Modeless
w w.pdf actory.com
470
: Windows
. :
) Closing ( :Modeless
)( Sub ShowForm
)(Dim mdless As New Form1
AddHandler mdless.Closing, AddressOf FormHasBeenClosed
)(mdless.Show
End Sub
_
Form Inheritance
Inheritance
. Base
) Form (
w w.pdf actory.com
: Windows Forms
471
.
:
Controls
Field
TextBox :
Class Form1
Inherits System.Windows.Forms.Form
End Class
Private
Protected
Modifier
.
Private :
w w.pdf actory.com
472
: Windows
Private
Class Form1
Inherits System.Windows.Forms.Form
End Class
) (10- 13
.PasswordForm
:10- 13 .
) Build xxx xxx (
Build
PasswordForm :
w w.pdf actory.com
: Windows Forms
473
Class TestForm
Inherits PasswordForm
End Class
Build xxx
.
Visual
w w.pdf actory.com
474
: Windows
OK
) (12- 13
:12- 13 .
Private
Localized Forms
Visual Studio .NET .
) (13- 13
w w.pdf actory.com
: Windows Forms
475
:13- 13 .
.Localized Form
True Localizable
) ( True
Resource File
.
) Language (14- 13 )
(.
w w.pdf actory.com
476
: Windows
) (13- 13
) .(15- 13
w w.pdf actory.com
: Windows Forms
477
) (13- 13
) Language ).((Default
:
Internationalization Forms
Visual Studio
.NET
.resx
.
Solution Explorer
) XML 17- 13 ( . XML
XML .
w w.pdf actory.com
478
: Windows
:17- 13 .XML
.Resources
Controls
.Control
w w.pdf actory.com
14
Controls
Windows
Controls
.Windows Forms
Windows Forms
) Control 4- 13 (449
Control
- ) (Control
.
Form
Form .Control
)( InitializeComponent .
w w.pdf actory.com
480
: Windows
)
( .Shared Members
Common Members
.Control
Name
Name
Name
)(.InitializeComponent
-
)( InitializeComponent.
) (
Enabled
w w.pdf actory.com
: Controls
481
Text
Font . RightToLeft
RightToLeft.Yes
.Right-To-Left
RightToLeft.Inherit
. TextAlign
) .(1- 14
:1- 14 .TextAlign
RightToLeft
xxxLeft xxxRight .TextAlign
TopRight
.
ContentAlignment Label
Font System.Drawing.Font
GDI+
Font
:System.Drawing.Font
w w.pdf actory.com
482
: Windows
Font
Font ReadOnly
:New
'
With TextBox1
).Font = New Font(Font.Name, .Font.Size * 2, .Font.Style
End With
Font Overloads
.
3 .
Font
Font
.
) Font (
)(:Clone
)(TextBox1.Font = Form1.Font.Clone
System.Drawing.Point ReadOnly
) X ( ) Y
( System.Drawing.Size
Width Height .
w w.pdf actory.com
: Controls
483
Pixel
.
Point Location
Size Size
) (:
'
)TextBox1.Location = New Point(0, 0
400 ' 100
)TextBox1.Size = New Size(400, 100
System.Drawing.Rectangle
Bounds ) (
ClientRectangle ) ( .
:
TextBox1.Bounds = Form1.ClientRectangle
w w.pdf actory.com
484
: Windows
:Anchor
Anchor
AnchorStyles.Bottom AnchorStyles.Top
AnchorStyles.Right .AnchorStyles.Left
.AnchorStyles.None
) (
) Tree .(Windows Explorer
) 2- 14 (:
w w.pdf actory.com
: Controls
485
:2- 14 .Anchor
TextBox1 : Right Top : Left TextBox2Bottom Top :
w w.pdf actory.com
486
: Windows
:Dock
Dock
DockStyle.Top ToolBars
DockStyle.Bottom ) StatusBar (3- 14
DockStyle.Right DockStyle.Left
.DockStyle.Fill
:3- 14 .Dock
DockPadding
Form1.DockPadding.Top = 10
Form1.DockPadding.Top = 10
Form1.DockPadding.Bottom = 10
Form1.DockPadding.Left = 10
Form1.DockPadding.Right = 10
'
'
'
'
'
Form1.DockPadding.All = 10
w w.pdf actory.com
: Controls
487
DockPadding
) ContainerControl 4-13
.(449
)( FindForm Parent
)() FindForm )( FindForm Method (
.Parent Parent
) !(:
) Form1.TextBox1
WithEvents (
(.
)( FindForm Parent
Panel GroupBox
) ContainerControl 4- 13 (449
Controls
.
Controls Collection
w w.pdf actory.com
488
: Windows
Form1
GroupBox1
TextBox1
TextBox2
TextBox3
GroupBox2
TextBox4
TextBox5
.GroupBox2.Controls
ForeColor BackColor
- .
Windows .NET :
System Colors .Custom Colors
:System.Drawing.SystemColors
TextBox1.BackColor = SystemColors.Window
TextBox2.BackColor = SystemColors.ActiveBorder
System.Drawing.Color :
w w.pdf actory.com
: Controls
489
TextBox1.BackColor = Color.Black
TextBox1.ForeColor = Color.White
)( FromArgb
BackColor ForeColor
) .(Font
.
Focus Active Control
Focus ) TextBox ( .
CanFocus
.ReadOnly
Focused .
(
ActiveControl ) (.
Windows ] [TAB
Focus
] [TAB
TabIndex .
w w.pdf actory.com
490
: Windows
False TabStop
.
Disposing Created
Disposed True -
Menu ContextMenu
.Pop-up menu
Custom Controls
) Locked (
) (
MSDN .
)( SetSize
)( SetBounds
.
)( BringToFront )( SendToBack
) False .(Visible
w w.pdf actory.com
: Controls
491
ForeColor (BackColor
)( ResetBackGround )(.ResetForeColor
) ( )( Focus
TabIndex ][TAB
)( GetNextControl .
MSDN .
.
.
) .(4- 14
:4- 14 .
w w.pdf actory.com
492
: Windows
Click DblClick
MouseDown
(
Button :
End If
End Sub
) X Y
( ) :(Control.MousePosition
MouseDown
Click Delta
.Mouse Wheel
w w.pdf actory.com
: Controls
493
MouseDown MouseEventArgs
.(MouseMove
KeyUp KeyDown :
.KeyPress
KeyChar Handled
True
.NET
True ) .
TextBox (.
KeyDown KeyUp
KeyDown
.
KeyEventArgs Alt
. KeyCode
KeyPress ][Enter
w w.pdf actory.com
494
: Windows
KeyPress HelpRequested
].[F1
GotFocus
.LostFocus
Leave ) (GotFocus
) .(LostFocus
LostFocus
:
Validating Validated
TextBox TextBox
.
- Paint
Windows
-Forms Resize
Move )
(.
w w.pdf actory.com
: Controls
495
ControlAdded
ControlRemoved
.
PropertyChanged
PropertyName
Visual Studio .NET
View
Form Desinger .
:5- 14 .ToolBox
w w.pdf actory.com
496
: Windows
Customize ToolBox Customize Toolbox
) .(6- 14
COM ..NET
Custom Controls .
. .NET
Documentation
w w.pdf actory.com
: Controls
497
Label
TextAlignment 6 ) (1- 14
PreferredWidth PreferredHeight
.
FlatStyle
Image
.ImageAlign
True UseMnemonic
& Text
& . &
&&.
LinkLabel
LinkLabel Label
HTML .
" 13 19 Start
Length .LinkArea
Links :Collection
" " = LinkLabel1.Text
)"LinkLabel1.Links.Add(12, 3, "Link1
)"LinkLabel1.Links.Add(25, 3, "Link2
LinkClicked
w w.pdf actory.com
498
: Windows
TextBox
TextBox
Text
.TextChanged True
ReadOnly .
SelectionStart SelectionLength
TextBox1.SelectionStart = 0
TextBox1.SelectionLength = TextBox1.Text.Length
)( SelectAll
.SelectedText
AppendText
AutoSize .
)( Undo
CanUndo True
.Modified
w w.pdf actory.com
: Controls
499
MaxLength PasswordChar
) * (.
PasswordChar TextBox
Copy Cut
.
.
Upper
) :
...( ) (
.
True Multiline
Multi-Line
Textbox .
.TabIndex
w w.pdf actory.com
500
: Windows
Default Button
] [Enter
.Button
.AcceptsReturn
ScrollBars
H ScrollBar
WordWrap . False
Lines
)( ScrollToCaret
.
:
: X Y
CausesValidation False
True Validating X
True Cancel :Validating
X Validated )
LostFocus( Cancel
Validated .Y
w w.pdf actory.com
: Controls
501
Button
Windows
.
AcceptButton CancelButton
] [Enter
] [Esc
:
Me.AcceptButton = Button1
Me.CancelButton = Button2
CheckBox
Windows
Checked
False AutoCheck
.Checked
Checked ...
w w.pdf actory.com
502
: Windows
ThreeState AutoCheck
.True
CheckBox CheckedChanged
Checked .CheckState
RadioButton
) CheckBox (Button
ButtonBase FlatStyle
3D Appearance Button
CheckBox .RadioButton
True Checked
) (
False ,Checked
ListBox
ListBox
Items
Collection .ListBox
Item Collection
ICollection )
'
Dim counter As Integer
For counter = 1 To 10
)ListBox1.Items.Add(counter
Next
'
)(ListBox1.Items.Clear
w w.pdf actory.com
: Controls
503
'
Dim item As Object
For Each item In ListBox1.Items
Next
.ICollection
) Primitave Types
Class Person
Public Name As String
Public Age As Integer
)Sub New(ByVal name As String, ByVal age As Integer
Me.Name = name
Me.Age = age
End Sub
End Class
With ListBox1.Items
))", 99"(.Add(New Person
))", 3000"(.Add(New Person
End With
ListBox
)( ToString .
:Overriding
Class Person
w w.pdf actory.com
504
: Windows
ListBox
Dim x As String
For Each x In ListBox1.SelectedItems
Next
)ListBox1.SetSelected(0, True
)ListBox1.SetSelected(1, False
)( BeginUpdate )( EndUpdate
:
CheckedListBox
CheckedListBox ListBox
SelectionMode
ListBox
CheckBox
SelectedItems .SelectedItems
w w.pdf actory.com
: Controls
505
ComboBox
ComboBox ListBox
TextBox ListBox
TextBox ComboBox.
ComboBox DropDownStyle
True .DroppedDown
ImageList
Image
ImageList
) TreeView (ListView
ImageList .
ImageList
Images
w w.pdf actory.com
506
: Windows
:7- 14 ImageList
Item Collection
ICollection
) )(()Count Clear() Insert() Add
...( .
TreeView
TreeView
Windows Explorer ImageList
ImageList TreeView
ImageList .TreeView
Nodes
Nodes Collection
w w.pdf actory.com
: Controls
507
Items (ListBox
TreeView ShowLines
ShowPlusMinus )(+
) (- Indent
.
w w.pdf actory.com
508
: Windows
RightToLeft
Nodes
.
Mirroring .
ListView
ListView
Desktop Windows Explorer View
Details List SmallIcon :
) LargeIcon .(9- 14
:9- 14 .View
ListView ImageList
) ImageList ( SmallImageList
ImageList View
w w.pdf actory.com
: Controls
509
.(View
ListView TreeView
TreeView Nodes
ListView Items .
Columns
SubItems Items
)( .
ToolBar StatusBar
ToolBar StatusBar
Buttons
.Panels
ImageList
) ListBox (ListView
.
Panels
StatusBar True .ShowPanels
w w.pdf actory.com
510
: Windows
Splitter
Splitter
Windows
(Explorer
) .(10- 14
:10- 14 .Splitter
Splitter Dock
Splitter X Right
) Dock ( Splitter
.Dock
) .(10- 14
Windows
... . .
w w.pdf actory.com
: Controls
511
:OpenFileDialog
Open Filter
True MultiSelect
ShowReadOnly CheckBox
) ReadOnly
(ReadOnlyChecked CheckFileExists
InitialDirectory
.
)( ShowDialog
DialogResult.OK Open
DialogResult.Cancel :Cancel
With OpenFileDialog1
.CheckFileExists = True
_ & "|*|*. " = .Filter
"|*.BMP;*.GIF;*.JPG ||*.EXE "
.FilterIndex = 2
"\.InitialDirectory = "C:
If .ShowDialog = DialogResult.OK Then
Else
End If
End With
:SaveFileDialog
Save
OpenFileDialog
) .(ShowReadOnly True
OverwritePrompt .
w w.pdf actory.com
512
: Windows
:ColorDialog
:Color
With ColorDialog1
If .ShowDialog = DialogResult.OK Then
Me.BackColor = .Color
End If
End With
:FontDialog
FontDialog Fonts
ShowColor )
.(Color :
With FontDialog1
.ShowColor = True
If .ShowDialog = DialogResult.OK Then
TextBox1.Font = .Font
TextBox1.ForeColor = .Color
End If
End With
Apply OK
True ShowApply
:Apply
_ Private Sub FontDialog1_Apply(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles FontDialog1.Apply
TextBox1.Font = FontDialog1.Font
TextBox1.ForeColor = FontDialog1.Color
End Sub
w w.pdf actory.com
Controls :
513
:PrintDialog
PrinterSettings PrinterSettings
)
:(System.Drawing.Printing PrinterSettings
With PrintDialog1
.AllowSomePages = True
.PrinterSettings = New System.Drawing.Printing.PrinterSettings()
If .ShowDialog = DialogResult.OK Then
With .PrinterSettings
MsgBox(.PrinterName)
MsgBox(.FromPage)
MsgBox(.ToPage)
End With
End If
End With
:PageSetupDialog
PrintDialog
PageSettings (...
:System.Drawing.Printing.PageSettings
With PageSetupDialog1
.AllowPaper = True
.PageSettings = New System.Drawing.Printing.PageSettings()
If .ShowDialog = DialogResult.OK Then
With .PageSettings
MsgBox(.PaperSize.Height & "x" & .PaperSize.Width)
End With
End If
End With
w w.pdf actory.com
514
: Windows
Provider Controls
.
.
:ToolTip
ToolTip ) (11- 14
ToolTip
ToolTip on ToolTip1
:11- 14 .ToolTip
Provider Controls
" on ".
w w.pdf actory.com
: Controls
515
:HelpProvider
HelpProvider Help
] [F1
HelpProvider HelpNamespace
MyHelpFile.CHM
HelpKeyword HelpNavigator :
.HelpString
Windows Forms
.
PictureBox Image
.SizeMode
AutoScroll
w w.pdf actory.com
516
: Windows
.Text
HScrollBar VScrollBar
Custom Controls
- .
Maximum Minimum Scroll
.Value
Windows ) .(12- 14
Icon ToolTip
.Visible
.ContextMenu
) Windows (13- 14
TabPage .Container
TabPages ICollection
ImageList .
w w.pdf actory.com
: Controls
517
:13- 14 .TabControl
TextBox
RichTextBox
.NET Documantation
TextBox
NumericUpDown
DateTimePicker .MonthCalendar
.ProgressBar
Timer Tick
) Interval 0.001(
True Enabled False ) 0
Interval Exception (.
w w.pdf actory.com
518
: Windows
MS-DOS Nafitha
Arabic Helper .
RightToLeft
Control RightToLeft
- )
Enum :(RightToLeft
Yes
) (.
) (.
No
Inherit
TextAlign Right
Left
.
ScrollBars
- -
RightToLeft
RightToLeftChanged Control .
w w.pdf actory.com
: Controls
519
. Buttons
Label ... TextBox
Label
TextBox
:MirrorLocations
MirrorLocations
:RightToLeftChanged
TextAlign
RightToLeft MirrorLocation
Windows Forms .
TextAlign
Right Left
:MirrorLocation
w w.pdf actory.com
520
Windows :
RightToLeft
RightToLeft
Form
(14- 14 )RightToLeft
.
. RightToLeft :14- 14
w w.pdf actory.com
: Controls
521
Mirroring )
(Right to Left Layout
) ... ( .
Windows 98 Enabled
Local Windows 2000
.
) .(15- 14
:15- 14 .
w w.pdf actory.com
522
: Windows
GDI+ .
RightToLeft
!
:
Button PictureBox ) TabControl .(16- 14
w w.pdf actory.com
: Controls
523
WS_EX_LAYOUTRTL
Extended Style
)( SetWindowLong API -
.API
Overrides .CreateParams
CreateParams CreateParams
ExStyle
) :(17- 14
w w.pdf actory.com
524
: Windows
:17- 14 Button
.PictureBox
) (17- 14
Button
.PictureBox WS_EX_NOINHERITLAYOUT
:WS_EX_NOINHERITLAYOUT
w w.pdf actory.com
: Controls
525
:18- 14 .
) (17-14 TabControl
Context Device
TabControl )Button Labe
... RadioButton CheckBox(
) GM_ADVANCED MSDN (
ListView TreeView ToolBar
.Textual
:WS_EX_NOINHERITLAYOUT
WS_EX_NOINHERITLAYOUT
) WS_EX_NOINHERITLAYOUT :(MSDN
w w.pdf actory.com
526
Windows :
WS_EX_NOINHERITLAYOUT
.
.
.
.
.
.
.
Form
ListView
Panel
StatusBar
TabControl
TabPage
ToolBar
TreeView
TreeView
. WS_EX_NOINHERITLAYOUT
TreeView CreateParams
:TreeView
w w.pdf actory.com
: Controls
527
) TreeView
:19- 14 ToolBar
) NotInheritable
(Imagelist CreateParams
WS_EX_NOINHERITLAYOUT
) .(17- 14
)SaveFileDialog OpenFileDialog
.Local
w w.pdf actory.com
528
: Windows
MsgBox
MsgBoxRight MsgBoxRtlReading :
API .MSDN
MessageBox MsgBox
.
w w.pdf actory.com
: Controls
529
.Windows Forms
.
.NET Framework
. GDI+
.
w w.pdf actory.com
w w.pdf actory.com
15
GDI+
) (
GDI+ GDI+
.GDI+
GDI+
:
System.Drawing
System.Drawing.Drawing2D
System.Drawing.Imaging
System.Drawing.Text
Imports
Imports
Imports
Imports
.NET
System.Drawing.Drawing2D
. .
w w.pdf actory.com
532
: Windows
Graphics
.Device Context
Graphics New
:
- Paint :
_ Private Sub Form1_Paint(ByVal sender As Object,
ByVal e As PaintEventArgs) Handles MyBase.Paint
Dim gr As Graphics = e.Graphics
End Sub
)( CreateGraphics :
Dim MainForm As New frmMain
) (
)( CreateGraphics
:
)(gr.Dispose
gr = Nothing
Graphics
.
w w.pdf actory.com
: GDI+
533
Graphics )
( . Overloads
) Pen
(Pen
.Rectangle )( DrawLine
)( DrawRectangle )( DrawEllipse -
) (:
Rectangle
Controls
.
)( DrawArc
)( DrawEllipse
) (:
) 1- 15 ( .
w w.pdf actory.com
534
: Windows
)( DrawLines )( DrawRectangles
Point Rectangle :
)( DrawCurve )( DrawBezier
MSDN
)( DrawBezier ) :(2- 15
w w.pdf actory.com
: GDI+
535
:2- 15 )(.DrawBezier
Pen
.NET
.(SystemPens.ControlDark
... . Pen
.
Pen
4:
myPen Graphics
:
w w.pdf actory.com
536
: Windows
)(myPen.Dispose
myPen = Nothing
) (2- 15 . . . . . .
- - - - - - DashStyle
:DashStyle
:2- 15 .DashStyle
Single DashPattern )
1 (:
w w.pdf actory.com
: GDI+
537
Pen -
StartCap :EndCap
) :(3- 15
) (0, 0 ) (0, 0
1 .
Alignment :
Alignment
) .(4- 15
w w.pdf actory.com
538
: Windows
:4- 15 Alignment 1.
GraphicsPath
) )(AddLine
GraphicsPath
:New
:
)myPath.AddLine(10, 10, 30, 60
)myPath.AddLine(30, 60, 60, 10
)myPath.AddLine(60, 10, 10, 10
) (10, 10 )(StartFigure
)(myPath.StartFigure
)myPath.AddLine(110, 60, 130, 10
)myPath.AddLine(130, 10, 160, 60
w w.pdf actory.com
: GDI+
539
)( CloseFigure :
)(myPath.CloseFigure
)gr.DrawPath(Pens.Black, myPath
)(myPath.Dispose
:6- 16 GraphicsPath .
)( Dispose
.
Graphics Overloads
w w.pdf actory.com
540
: Windows
Brush
Brushes
)( FillPath )
(GraphicsPath )( FillRegoin
) Region (.
Brush
Brushes
.SystemBrushes
- .Brush
SolidBrush :
)( Dispose
.
w w.pdf actory.com
: GDI+
541
HatchBrush
56 ) HatchStyle
!( :
HashStyle
.
LinearGradientBrush
Tile
TextureBrush
:
w w.pdf actory.com
542
: Windows
GraphicsPath MSDN
.PathGradientBrush
Coordinate system
Graphics
)/(.
:
Coordinate system
Graphics ) (0, 0
)( TranslateTransform
:
Dim gr As Graphics = e.Graphics
'
_ gr.TranslateTransform(Picture1.ClientRectangle.Width \ 2,
)Picture1.ClientRectangle.Height \ 2
)( TranslateTransform
)( ResetTransform:
w w.pdf actory.com
: GDI+
543
)( DrawRectangle
)(TranslateTransform
) - 15
:(7
:7- 15 )( TranslateTransform .
:
)( TranslateTransform
Graphics
.
) :(8- 15
w w.pdf actory.com
544
Windows :
w w.pdf actory.com
: GDI+
545
Graphics Pixel
PageUnitInch :
Gr.PageUnit = GraphicsUnit.Inch
GDI+ .
Imports
System.Drawing.Imaging .
Image Bitmap
w w.pdf actory.com
546
: Windows
)( LoadFromFile
Stream )( LoadFromStream :
Streams
.
:
)"Dim JPG As New Bitmap("C:\Ibrahim.JPG
Bitmap Image
)( Save :
)( Save
....
Bitmap Image
)( DrawImage :
w w.pdf actory.com
: GDI+
547
Paint
.
.
)( DrawImage Overloads
30 .
)
:(Rectangle
:
Dim gr As Graphics = e.Graphics
)"Dim JPG As New Bitmap("C:\Ibrahim.JPG
)gr.DrawImage(JPG, 0, 0, 200, 300
)
:(Rectangle
w w.pdf actory.com
548
: Windows
gr As Graphics = e.Graphics
)destRect As New Rectangle(0, 0, 200, 200
)sourceRect As New Rectangle(30, 30, 50, 50
)"JPG As New Bitmap("C:\Ibrahim.JPG
Dim
Dim
Dim
Dim
..NET Documentation
) (10- 15 )(.DrawImage
:10- 15 .
w w.pdf actory.com
: GDI+
549
)( DrawImage Point
) (x0, y0
) (x1, y1 ) (x2, y2
" " ) .(11- 15
:11- 15 .
Point
)( DrawImage H Flipping
) ) (x0, y0 ):((0, 0
w w.pdf actory.com
550
: Windows
V Flipping )
Skewing
L / )
) (x0, y0 ) (0, 0(:
Rotating
Angle
) ) (x0, y0 ) (0, 0
:(points
gr As Graphics = e.Graphics
)"JPG As New Bitmap("C:\Eiffl.JPG
Angle As Integer = 90
))AngleInRad As Single = CSng(Angle / (180 / Math.PI
w w.pdf actory.com
Dim
Dim
Dim
Dim
: GDI+
551
PointF Point
X Y Single .Integer
:12- 15 50 90.
w w.pdf actory.com
552
: Windows
Transparent Color
)() MakeTransparent :(13- 15
:13- 15 .
)
Opacity ( ImageAttribute
Array SetColorMatrix
.NET Documentation .
Icons
Icon Windows
Icons Image
w w.pdf actory.com
: GDI+
553
) Icon
Stream(:
SystemIcons :Windows
Icon
Graphics :
)(:Dispose
)(Icon.Dispose
Icon
Image
Bitmap )(:ToBitmap
w w.pdf actory.com
554
: Windows
Graphics )(DrawIconUnstretched
Icon Rectangle
.
GDI+
Fonts .
.System.Drawing.Text
Font Family
Families
InstalledFontCollection
:FontFamily
Next
w w.pdf actory.com
: GDI+
555
Families TrueType
OpenType.
)( FontFamily.GetFamilies :Graphics
Families
Graphics )
(.
FontFamily
:
)"Dim fontFamily As New FontFamily("Tahoma
FontFamily
)( IsAvailable
True :
End If
w w.pdf actory.com
556
: Windows
Graphics
. Font
13 Overloads :
Style:
)Dim font2 As New Font("Tahoma", 20, FontStyle.Bold
Dim font3 As New Font("Tahoma", 20, FontStyle.Bold Or
)FontStyle.Italic
:FontFamily
)"Dim fontFamily As New FontFamily("Arial
)Dim font4 As New Font(fontFamily, 20, FontStyle.Bold
Font ReadOnly
.
.
) (
Enum :GraphicsUnit
)( DrawString
String Font
Brush :
w w.pdf actory.com
: GDI+
557
)( MeasureString SizeF
:Font
Width :Wrap
)gr.MeasureString(myText, myFont, 200
)( DrawString RectangleF
w w.pdf actory.com
558
: Windows
:14- 15 .RectangleF
RectangleF Rectangle
Single
.Integer
) (14- 15
Right-to-Left
StringFormat .
StringFormat
StringFormat )( DrawString
Alignment ) Near(
) Center( ) Far(:
w w.pdf actory.com
GDI+ :
559
Dim
Dim
Dim
Dim
gr As Graphics = e.Graphics
myFont As New Font("Tahoma", 14)
sf As New StringFormat()
text As String = "_ & "
" "
sf.Alignment = StringAlignment.Far
gr.DrawString(text, myFont, Brushes.Black, _
New RectangleF(10, 10, 200, 200) , sf)
'
gr.DrawRectangle(Pens.Black, New Rectangle(10, 10, 200, 200))
Alignment
Dim
Dim
Dim
Dim
gr As Graphics = e.Graphics
myFont As New Font("Tahoma", 14)
sf As New StringFormat()
text As String = "_ & "
" "
sf.FormatFlags = StringFormatFlags.DirectionRightToLeft
gr.DrawString(text, myFont, Brushes.Black, _
New RectangleF(10, 10, 200, 200) , sf)
'
gr.DrawRectangle(Pens.Black, New Rectangle(10, 10, 200, 200))
FormatFlags
Alignment
. Far Near
w w.pdf actory.com
560
: Windows
:15- 15 .
) (15- 15
Text
) - 15
.(16
:16- 15 .
w w.pdf actory.com
: GDI+
561
Windows
] [Ctrl] + [Shift.
Rectangle
Justify
MSDN
- Web Forms HTML
. ArJustify ) - 15
.(17
:17- 15 .ArJustify
w w.pdf actory.com
562
Windows :
: ArJustify
True Font
JustifiedText .
:
JustifiedText()
AddKashidas()
:
Class ArJustify
w w.pdf actory.com
GDI+ :
563
w w.pdf actory.com
564
Windows :
< Me.width
If allowedAfterLetters.IndexOf(Me.textLines(index). _
Chars(counter)) <> -1 AndAlso _
allowedBeforeLetters.IndexOf(Me.textLines(index). _
Chars(counter + 1)) <> -1 Then
canAddKashida = True
If gr.MeasureString(Me.textLines(index).Insert( _
counter + 1, ""c), Me.font).Width > Me.width Then
Exit Do
Else
Me.textLines(index) = Me.textLines(index).Insert(
_
counter + 1, ""c)
Dim counter2 As Integer
For counter2 = counter To 0 Step -1
If Me.textLines(index).Chars(counter2) = " "c
Then
counter = counter2 - 1
Exit For
End If
Next
If counter2 <= 0 Then counter = _
Me.textLines(index).Length - 2
End If
Else
counter -= 1
If counter <= 0 Then
If canAddKashida Then
counter = Me.textLines(index).Length - 2
Else
Exit Do
End If
End If
End If
Loop
End Sub
End Class
String ArJustify
StringBuilder
.
w w.pdf actory.com
: GDI+
565
.StringBuilder
ArJustify
) .(18- 15
:18- 15 ArJustify .
ArJustify
.
w w.pdf actory.com
566
: Windows
.Windows
)( SetDigitSubstitution
LCID
) ( ) :(19- 15
gr As Graphics = e.Graphics
)(sf As New StringFormat
)myFont As New Font("Tahoma", 13
"myText As String = "1234567890
Dim
Dim
Dim
Dim
:19- 15 )
(.
w w.pdf actory.com
: GDI+
567
LCID
.245
Controls
) ListBox (MenuBox
Device Context
ListBox
) .(20- 15
:20- 15 .
ListBox
Load :
w w.pdf actory.com
568
Windows :
DrawMode ListBox
OwnerDrawFixed
. ItemHeight
DrawItem
Index Bounds
(... ) State
w w.pdf actory.com
GDI+ :
569
DrawItem
:(20- 15 )
w w.pdf actory.com
570
: Windows
GDI+
w w.pdf actory.com
16
Windows Forms
Custom Controls Windows Services
Windows
Windows
.Windows
: Author
Programmer
User .
Authoring Time
Run Time
.
.
:
w w.pdf actory.com
572
: Windows
Controls
) (TreeView Mirroring
) ProgressBar (ImageList
- ) TextBox Label
ListView Picture(
.
New->Project File
w w.pdf actory.com
:
573
TextBoxExProject
UserControl1 :TextBox
w w.pdf actory.com
574
Windows :
TextBox TextBoxEx
.TextBox
.
True AutoSelect
Enter
:
Private Sub TextBoxEx_Enter(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Enter
Me.SelectAll()
End Sub
:
Public Class TextBoxEx
Inherits System.Windows.Forms.TextBox
Sub New()
MyBase.New()
End Sub
Private m_autoSelect As Boolean
Public Property AutoSelect() As Boolean
Get
Return m_autoSelect
End Get
Set(ByVal Value As Boolean)
m_autoSelect = Value
End Set
End Property
w w.pdf actory.com
:
575
DLL .
:
w w.pdf actory.com
576
: Windows
New Solution
Windows Application
.
Debugging ) Visual
(Studio .NET
.
.
) Brows (
. Open
) Customize ToolBox .(3- 16
w w.pdf actory.com
:
577
:3- 16 TextBoxExProject .
OK Visual Studio
:4- 16 TextBoxEx .
TextBoxEx TextBox
) AutoSelect
( ) .(5- 16
w w.pdf actory.com
578
: Windows
:5- 16 AutoSelect .
TextBoxEx True
Base Control
Overrides Overloads .
.
Form
Visual
) WindowState
... MaximizeBox ShowInTaskBar(.
Button TextBox
.
w w.pdf actory.com
:
579
Custom Control :
:6- 16 .
Anchor ) TextBox : (
Click Button :
w w.pdf actory.com
580
: Windows
Assemblies
.NET Framework
Public
Friend
Modifiers .
Public
Subclassing
) . - TextBox
(.
Public
Public :
Public Property FileName() As String
Get
Return Me.TextBox1.Text
End Get
)Set(ByVal Value As String
Me.TextBox1.Text = Value
End Set
End Property
w w.pdf actory.com
:
581
GDI+ .
Microsoft
..NET Framework
Rotator
) (7- 16
Text Angle
Text Paint :
w w.pdf actory.com
582
: Windows
:7- 16 .Rotator
Rotator
) )( Math.Sin
)( Math.Cos (.
Windows Forms .
Enum
Enum Flight
Car
Plan
Train
End Enum
Property TravelJet() As Flight
End Property
w w.pdf actory.com
:
583
Enum
) .(8- 16
:8- 16 .
... Rectangle( ) 9- 16
(:
End Property
w w.pdf actory.com
584
: Windows
:9- 16 TextColor .
TypeConverter
MSDN .
w w.pdf actory.com
:
585
DesignMode
Authoring time
Design time .
System.ComponentModel
Attributes
Description ) :(10- 16
Imports System.ComponentModel
_ >)" "(<Description
Property TextColor() As Color
End Property
:10- 16 .
ReadOnly
False
Browsable :
w w.pdf actory.com
586
: Windows
_ >)<Browsable(False
ReadOnly Property IsSomething() As Boolean
Get
End Get
End Property
True Localizable
Localized Forms :
_ >)<Localizable(True
Property TitleName() As String
End Property
DefaultProperty DefaultEvent
) (
) :
_ >)"<DefaultProperty("Text"), DefaultEvent("Click
Public Class MyUserControl
Inherits System.Windows.Forms.UserControl
End Class
ToolboxBitmap
) ToolBox 16 x 16(:
_ >)"<ToolboxBitmap ("C:\MyIcon.ico
Public Class MyUserControl
Inherits System.Windows.Forms.UserControl
End Class
w w.pdf actory.com
:
587
Windows
.Windows Services
:
Imports System.ServiceProcess
) (Windows Application
Add References .System.ServiceProcess.dll
Windows Services .
Windows
Windows Service EXE
System Booting .
Windows
Interaction Windows
... Watching .
Windows
w w.pdf actory.com
588
: Windows
:11- 16 Windows .
(.
Windows Service
New->Project File Windows
w w.pdf actory.com
:
589
) (
WindowsService1 .FolderWatcher
Windows
.System.ServiceProcess.ServiceBase
Windows
) Control Panel (
w w.pdf actory.com
590
Windows :
. :13- 16
: DirWatcher
Imports System.ServiceProcess
Public Class DirWatcher
Inherits System.ServiceProcess.ServiceBase
#Region " Component Designer generated code "
Public Sub New()
MyBase.New()
' This call is required by the Component Designer.
InitializeComponent()
w w.pdf actory.com
:
591
<MTAThread()> _
Shared Sub Main()
Dim ServicesToRun() As System.ServiceProcess.ServiceBase
' More than one NT Service may run within the same process. To
add
' another service to this process, change the following line
to
' create a second service object. For example,
'
'
ServicesToRun = New System.ServiceProcess.ServiceBase ()
{New Service1, New MySecondUserService}
'
ServicesToRun = New System.ServiceProcess.ServiceBase() {New
Service1()}
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
End Sub
'Required by the Component Designer
Private components As System.ComponentModel.IContainer
' NOTE: The following procedure is required by the Component
Designer
' It can be modified using the Component Designer.
' Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'DirWatcher
'
Me.CanPauseAndContinue = True
Me.ServiceName = "DirWatcher"
End Sub
#End Region
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set
things
' in motion so your service can do its work.
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop
your service.
End Sub
End Class
w w.pdf actory.com
592
: Windows
Bold )
.FileSystemWatcher
System.IO. FileSystemWatcher
FileSystemWatcher
Windows
FolderWatcher .
FileSystemWatcher
Path :
) (
FileSystemEventArgs
FullPath :
w w.pdf actory.com
:
593
True
EnableRaisingEvents True
IncludeSubdirectories :
FW.IncludeSubdirectories = True
FW.EnableRaisingEvents = True
System.IO.FileSystemWatcher
Windows
.MSDN
System.ServiceProcess.ServiceBase
)( OnStart )( OnStop
Overrides
)( OnPause )( OnContinue
Pause :Resume
w w.pdf actory.com
594
Windows :
FileSystemWatcher
.Windows
Windows ) Test.TXT
:(Server
Streams
.
w w.pdf actory.com
:
595
) ] ([F5
:14- 16 .
(590 ProjectInstaller.vb
ServiceProcessInstaller1 ) ServiceInstaller1 .(15- 16
:15- 16 .
ServiceInstaller
.NET Documentation
w w.pdf actory.com
596
: Windows
DisplayName ServiceName
StartType )
(DirWatcher ) " -
( "DirWatcher Automatic
) System Booting (.
ServiceProcessInstaller1 Account
User Account
LocalSystem
) . MSDN
(.
EXE
InstallUtil.EXE
.System Registry
InstallUtil.EXE
Visual Studio .NET Command Prompt
( ) .(6 - 11
DirWatcher EXE
:InstallUtil
C:\>InstallUtil FolderWatcher.EXE
Restart Service
w w.pdf actory.com
:
597
:16- 16 DirWatcher .
InstallUtil.EXE :/u
C:\>InstallUtil FolderWatcher.EXE /u
Stop .
DirWatcher ) (16-16
Stop
.
w w.pdf actory.com
598
: Windows
Windows
Windows
.Custom Controls
Application
Application
New Application .
Application Shared Members ReadOnly
ExecutablePath StartupPath
: CompanyName
CurrentCulture
ProductVersion ProductName
DoEvents
)( Exit )(ExitThread
MSDN Application
) Idle
(.
w w.pdf actory.com
:
599
Cursor
Cursor
Cursor .
Cursor Cursor
28
:Cursor
Button1.Cursor = Cursors.No
Cursor
)(:Dispose
)(myCur.Dispose
Current Cursor
Cursor.Current = Cursors.Hand
Cursor Default
.Cursor
Cursor
) Clip
(Rectangle :
w w.pdf actory.com
600
: Windows
)Cursor.Clip = Me.RectangleToScreen(Me.ClientRectangle
Nothing Clip.
)(- RectangleToScreen
-
.
Position
:
)Cursor.Position = New Point(0, 0
SendKeys
SendKeys Keyboard
)( .Send
]:[Enter
)"~"(SendKeys.Send
% ] [Alt ] [Shift -
:Capital
)")SendKeys.Send("+(turki
} { }{TAB
w w.pdf actory.com
:
601
)( Send
API
FindWindow .SetForegroundWindows
Registry RegistryKey
Registry RegistryKey Windows
Registry .
) .(17- 16
Data .Value
Registry RegistryKey
Registry :RegistryKey
w w.pdf actory.com
602
: Windows
Registry.ClassesRoot
Registry.CurrentConfig
Registry.CurrentUser
Registry.DynData
Registry.LocalMachine
Registry.PerformanceData
Registry.Users
=
=
=
=
=
=
=
RegistryKey
RegistryKey
RegistryKey
RegistryKey
RegistryKey
RegistryKey
RegistryKey
root1
root2
root3
root4
root5
root6
root7
As
As
As
As
As
As
As
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Registry RegistryKey
Microsoft.Win32
:
Imports Microsoft.Win32
RegistryKey Name :
SubKeyCount
.
)( GetSubKeyNames
Next
)( OpenSubKey RegistryKey:
Dim IE As RegistryKey
)"IE = root1.OpenSubKey("Internet Explorer.Main
:
)(IE.Close
w w.pdf actory.com
:
603
)( OpenSubKey
True )( SetValue
:
Dim IE As RegistryKey
)"IE = root1.OpenSubKey("Internet Explorer.Main
Dim IE As RegistryKey
)IE = root2.OpenSubKey("Internet Explorer.Main", True
)"IE.SetValue("Search Page", "http://www.dev4arabs.com
)( GetValue .
Help
Help Files
) Help
(.
Shared Methods
)( ShowHelpIndex ) Index
(:
)"Help.ShowHelpIndex(Me, "C:\helpfile.chm
)( ShowHelp Overloads
:Contents
)"Help.ShowHelp(Me, "C:\helpfile.chm
:Search
)Help.ShowHelp(Me, "C:\helpfile.chm", HelpNavigator.Find
w w.pdf actory.com
604
: Windows
HelpNavigator.Topic
)(:ShowHelp
)Help.ShowHelp(Me, "C:\helpfile.chm",HelpNavigator.Topic ,3
keyword
.NET Framework
Windows
..NET Documentation
.NET Framework .
w w.pdf actory.com
w w.pdf actory.com
w w.pdf actory.com
17
ADO.NET
ADO.NET
ADO.NET
:
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Project Property Pages
.
w w.pdf actory.com
608
:
ADO.NET
ADO.NET System.Data
Data Sources
ADO.NET
: Connected Mode
.Disconnected Mode
Inbox
. ADO.NET
- .
SQL
- Data Structure Table
Relationships .
Servers Clients
w w.pdf actory.com
: ADO.NET
609
ADO.NET .
Microsoft Access
... .
ADO.NET
ADO.NET
ADO.NET Microsoft
w w.pdf actory.com
610
:
ADO.NET
.NET Framework:
OLE DB .COM
Microsoft .NET
.NET
.NET COM COM ) .NET
Microsoft Access(.
:SQL Server .NET Data Provider
- - Microsoft
SQL Server
OLE DB .NET Data Provider.
:ODBC .NET Data Provider
.NET ODBC
ODBC Drivers
) ( .
w w.pdf actory.com
: ADO.NET
611
(.
ADO.NET
ADO.NET
DataAdapter DataReader Command Connection : DataSet
) (2- 17
.
:2- 17 .ADO.NET
- -
. Connection
...( .
w w.pdf actory.com
612
:
Command
Records DataReader
.
Connected Mode
DataSet .
DataSet DataAdapter
/ .Connection
.Connection
Connection
ADO.NET
.Connection )
.(Disconnected Mode
.
Connection Connection
OLE DB .NET
Data Provider :OleDbConnection
w w.pdf actory.com
: ADO.NET
613
IDbConnection
Polymorphism -
:
)Sub ConnectionDB(ByVal dbCon As IDbConnection
End Sub
Connection String
) (String
...
:Microsoft Access
_ ";Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0
";& "Data Source=C:\Folder\Data.MDB
10
) 15(:
ConnectionString
:
'
)(Dim msAccessCn As New OleDbConnection
msAccessCn.ConnectionString = connString
w w.pdf actory.com
614
:
'
)Dim msAccessCn As New OleDbConnection(connString
project.exe.config
.
ReadOnly:
SqlConnection
SqlConnection
ConnectionString
)(:Open
w w.pdf actory.com
: ADO.NET
615
)(:Close
)( msAccessCn.Close
)( msSQLCn.Close
State
Executing Fetching
:
Open ) Closed (
StateChange :
w w.pdf actory.com
616
:
Catch ex As Exception
)MsgBox(ex.Message
End Try
)( Close
) Garbage
Collection(
Catch ex As Exception
)MsgBox(ex.Message
Finally
)(cn.Close
End Try
w w.pdf actory.com
: ADO.NET
617
OleDbException SqlException
Try
Catch ex As OleDbException
Catch ex As Exception
End Try
Exceptions
.
Command
SQL
Connection .Command
-
SQL SQL
SQL
.
w w.pdf actory.com
618
:
Command Command
Connection
OLE DB .NET Data Provider :OleDbCommand
)( Dim msAccessCmd As New OleDbCommand
IDbCommand
Polymorphism -
:
End Sub
Command
Connection :Connection
)Dim cn As New OleDbConnection(connString
)(Dim cmd As New OleDbCommand
)(cn.Open
cmd.Connection = cn
SQL .NET Data Provider SqlConnection
w w.pdf actory.com
: ADO.NET
619
SqlCommand OLEDbCommand
:
Command
Connection - )( Close
SQL :
) .(3- 17
w w.pdf actory.com
620
:
SQL
Command SQL
SQL SELECT
Command
)(.ExecuteXXX
SQL
)( ExecuteNonQuery .
-
)( ExecuteNonQuery
Connection CommandText
:Command
w w.pdf actory.com
: ADO.NET
621
Try
)( cmd.ExecuteNonQuery
Catch ex As Exception
End Try
SELECT
Command ExecuteScalar() ExecuteReader() :
.ExecuteXMLReader
)(:ExecuteReader
)( ExecuteReader DataReader
) Command DataReader
DataReader (:
)(:ExecuteScalar
)( ExecuteScalar Field
:
_ " ] FROM [ Dim cmd As New OleDbCommand("SELECT
)] = 1", cn[ ] WHERE [ " &
)(Dim Name As String = cmd.ExecuteScalar
w w.pdf actory.com
622
:
)( ExecuteScalar
-
Field
.
)( ExecuteScalar
)(:ExecuteXMLReader
SQL Server .NET Data Provider
.XML
)( ExecuteReader DataReader
)( ExecuteXMLReader System.XML.XmlReader
- :DataReader
w w.pdf actory.com
: ADO.NET
623
)( ExecuteXmlReader
XmlReader ADO.NET .XML
DataReader
Command )(ExecuteReader
DataReader
.
DataReader New
)( ExecuteReader Command
Command OLE DB .NET Data Provider
:OleDbDataReader
IDataReader OleDbDataReader
SqlDataReader :
w w.pdf actory.com
624
:
End Sub
DataReader
)( Read Item
:
:
) ))MsgBox ( dr(0) & " " & CInt(dr(1
)( Read
False
Do Loop :
w w.pdf actory.com
: ADO.NET
625
Item DataReader
:
) ))""(") & " " & CInt(dr"(MsgBox ( dr
Item Object
)( Getxxx :
DataReader )(Close
DataReader Connection
Command )( Close
.
DataReader
GetName ) (
FieldCounter IsDBNull
True ) Null
(.
w w.pdf actory.com
626
:
)( GetSqlxxx :Item
.NET Documantation
) (Narrowing
)( GetSqlxxx
System.Data.SqlTypes .System
System.Data.SqlTypes
w w.pdf actory.com
: ADO.NET
627
)(GetSqlBoolean
)(GetSqlByte
)(GetSqlInt16
)(GetSqlInt32
)(GetSqlInt64
)(GetSqlSingle
)(GetSqlDouble
)(GetSqlDecimal
)(GetSqlDateTime
SqlBoolean
SqlByte
SqlInt16
SqlInt32
SqlInt64
SqlSingle
SqlDouble
SqlDecimal
SqlDateTime
)(GetSqlMoney
SqlMoney
)(GetSqlString
SqlString
)(GetSqlBinary
SqlBinary
)(GetSqlObject
SqlObject
SQL
Server
bit
tinyint
smallint
int
bigint
real
float
decimal
datetime
smalldatetime
money
smallmoney
char
nchar
ntext
nvarchar
sysname
text
varchar
binary
varbinary
image
timestamp
sql_variant
)( NextResult
False :
w w.pdf actory.com
628
:
ADO.NET
Disconnected Mode .
w w.pdf actory.com
18
ADO.NET
/ Client-
Server Applications
.
ADO.NET
DataSet DataAdpater
DataSet
DataSet DataReader
. DataSet
.NET Documantation ) 1- 18
) (1- 18 Containment
Item .
.
w w.pdf actory.com
630
:
:1- 18 .DataSet
w w.pdf actory.com
ADO.NET :
631
) (1- 18
DataTableCollection DataRelationCollection
Tables :Relations
)MsgBox(ds.Tables.Count
)MsgBox(ds.Relations.Count
Item :
)(Dim ds As New DataSet
Dim dt As DataTable
)" "(dt = ds.Tables.Item
)ds.Tables.Add(dt
DataSet
w w.pdf actory.com
632
:
) Collection (ICollection
.DataTable
DataTable
DataTable
) Rows (DataRowCollection
) Columns (DataColumnsCollection
)( .
TableName
:
Primary key
DataColumns PrimaryKey
PrimaryKey
:
w w.pdf actory.com
ADO.NET :
633
ColumnChanging
ColumnChanged
RowChanged
RowChanging
RowDeleting RowDeleted .
DataRow
DataRow New
DataRow )(NewRaw
Object
Rows :DataTable
Item
w w.pdf actory.com
634
:
Item DataRow
:
" " = )""(dr
") = 40"(dr
") = True"( dr
DataColumn
DataColumn
ColumnName :
AutoIncrement
True
AutoIncrementSeed
AllowDBNull Unique
DataRelation
Relationships DataRelation
ParentColumns
ChildColumns : RelationNames
w w.pdf actory.com
ADO.NET :
635
:
_ ",Dim rel As New DataRelation("1
_ "), "(Table1.Columns
))" "(Table2.Columns
DataSet
.
DataSet
DataSet
.DataAdapter
DataSet .
) (2- 18 - 1
:2- 18 DataSet .
w w.pdf actory.com
636
:
:DataSet
)(Dim myDataSet As New DataSet
:
)""(Dim myDataSetAs New DataSet
DataTable
DataColumn
)( Add Columns :
Primary Key DataColumn
:PrimaryKey
w w.pdf actory.com
ADO.NET :
637
Primary keys
-1
DataRelation :
DataSet :
)myDataSet.Tables.Add(Employees
)myDataSet.Tables.Add(Sales
)myDataSet.Relations.Add(rel
:
DataSet
:
)}" " Employees.Rows.Add(New Object() {2,
)}" " Employees.Rows.Add(New Object() {3,
)}Sales.Rows.Add(New Object() {1, True, 200
)}Sales.Rows.Add(New Object() {3, False, 150
)}Sales.Rows.Add(New Object() {2, True, 120
w w.pdf actory.com
638
:
DataAdapter
DataSet
MSDN
DataSet
!
DataSet
.Connection
:3- 18 DataAdapter
.DataSet
w w.pdf actory.com
ADO.NET :
639
DataSet
Client
.Server
-DataSet
DataAdapter
DataSet .
DataSet DataSet
- DataAdapter
DataSet
DataSet -
Microsoft Access
DataAdapter
DataAdapter
w w.pdf actory.com
640
:
OleDbDataAdapter SqlDataAdapter
) DbDataAdapter
(System.Data.Common
:DataAdapter
End Sub
) (
DataAdapter
Connection DataAdapter
:
w w.pdf actory.com
ADO.NET :
641
SQL .NET Data Provider SqlConnection
SqlDataAdapter OleDbDataAdapter
:
DataAdapter
Connection )( Close
) Command (.
ADO.NET
)( Close .DataSet
Connection
Connection DataAdapter
DataAdapter.
w w.pdf actory.com
642
:
)(cn.Close
)( Fill
TableName DataTable
) DataSet .(1-18
DataAdapter DataSet
DataSet
DataRow :
Dim x As DataRow
").Rows "(For Each x In ds.Tables
))""(ListBox1.Items.Add(x
Next
TryEnd Try :On Error
Try
)" " da.Fill(ds,
Catch ex As Exception
w w.pdf actory.com
ADO.NET :
643
End Try
) DataSet .NET Framework
( DataSet
FillError DataAdapter
) DataSet )( (Fill
FillErrorEventArgs Errors
True Continue
:
)(Sub LoadDataSet
End Sub
)Sub FillError(ByVal sender As Object, ByVal e As FillErrorEventArgs
If TypeOf e.Errors Is Exception Then
e.Continue = True
End If
End Sub
w w.pdf actory.com
644
:
DataSet
)( Update DataAdapter :
)"" da.Update(ds,
DateSet DataAdapter
Primary Key
.
)( Update )
(
DataAdapter UpdateCommand InsertCommand
.DeleteCommand
DataAdapter :
)( Update DataAdapter
RowState DataRow
DataSource Modified
UpdateCommand Deleted
w w.pdf actory.com
ADO.NET :
645
SQL InsertCommand
) DataAdapter .(4- 18
:4- 18 .
UpdateCommand InsertCommand DeleteCommand
) Command
( .NET Framework
CommandBuilder .
:CommandBuilder
CommandBuilder SQL
INSERT SELECT
UPDATE OleDbDataAdapter
:DataAdapter
w w.pdf actory.com
646
:
Commandbuilder
DataAdapter
)( GetxxxCommand
:xxxCommand
da.UpdateCommand = cmd.GetUpdateCommand
da.DeleteCommand = cmd.GetDeleteCommand
da.InsertCommand = cmd.GetInsertCommand
:
Microsoft Access
)( Fill
DataAdapter :DataSet
:DataSet
)""(With ds.Tables
" " = )""().Rows(0
") = 99"().Rows(0
End With
)(").Rows(1).Delete"(ds.Tables
)}", 55 " ").Rows.Add(New Object() {Nothing,"(ds.Tables
w w.pdf actory.com
ADO.NET :
647
)( Update xxxCommand
:CommandBuilder
CommandBuilder
] [ :
] = 4 [ ] WHERE [ SELECT * FROM
QuotePrefix
QuoteSuffix :
w w.pdf actory.com
648
:
xxxCommand
CommandBuilder
SQL xxxCommand
CommandBuilder
) SELECT (
.
Primary Key
SELECT
.DataAdapter
xxxCommand DataAdapter
Parameters .SQL
(InsertCommand CommandBuilder
) UpdateCommand (DeleteCommand
:Command
Command Parameters
) ? ( Parameters Collection
:
w w.pdf actory.com
ADO.NET :
649
)Dim da As New OleDbDataAdapter(" ", cn
da.DeleteCommand = cmdDel
da.UpdateCommand = cmdUpd
Primary key .
)( Update
Try
: End Try
Try
)"" da.Update(ds,
Catch
End Try
w w.pdf actory.com
650
:
) (DataSet
True ContinueUpdateOnError
:
da.ContinueUpdateOnError = True
)"" da.Update(ds,
HasChanges
DataSet :DataAdapter
If ds.HasChanges() Then
End If
RowUpdated DataAdapter
- - RowError DataRow
)( RejectChanges
DataTable :DataSet
Dim da As OleDbDataAdapter
Dim ds As DataSet
da.ContinueUpdateOnError = True
)"" da.Update(ds,
w w.pdf actory.com
ADO.NET :
651
If ds.HasChanges Then
Dim dr As DataRow
").Rows"(For Each dr In ds.Tables
If dr.RowState = DataRowState.Added Then
" " = dr.RowError
ElseIf dr.RowState = DataRowState.Modified Then
" " = dr.RowError
ElseIf dr.RowState = DataRowState.Deleted Then
" " = dr.RowError
'
'
' DataSet
)(dr.RejectChanges
End If
Next
End If
RowUpdated
.
RowUpdated :
End Sub
RowUpdated
) (
StatementType
. Select .
w w.pdf actory.com
652
:
Command Row
Command
DeleteCommand UpdateCommand .InsertCommand
Row DataRow .
RecordsAffected
. Errors Exception
DBConcurrencyException
RowUpdated Status
Continue ErrorsOccurred
SkipCurrentRow
SkipAllRemainingRows
.
ADO.NET
Windows Forms
w w.pdf actory.com
19
XML
. ADO.NET
XML
.Web Services
Windows
Forms XML
.ADO.NET
Windows Forms
) Next Back
... ( ) .(1- 19
w w.pdf actory.com
654
:
:1- 19 .
.binding
ReadOnly
.
.
-
Text TextBox .
) (
- Items ListBox
.
IList
Array ADO.NET -
. .
w w.pdf actory.com
: XML
655
Visual Studio .NET
) .(2- 19
) (
BindingContext
BindingManagerBase
- Position
.
.ControlBindingCollection
Binding
.
w w.pdf actory.com
656
:
Binding
.
Binding ControlBindingCollection
Text CarName Backcolor
CarColor ) .(3- 19
:3- 19 .
ADO.NET
Class Person
Private m_name As String
Property Name() As String
Get
Return m_name
End Get
)Set(ByVal Value As String
m_name = Value
End Set
End Property
w w.pdf actory.com
XML :
657
:
Public Class Form1
Inherits System.Windows.Forms.Form
w w.pdf actory.com
658
:
Button
BindingManagerBase Position
:BindingContext
w w.pdf actory.com
: XML
659
ADO.NET
ADO.NET Persons
:DataSet
DataSet ADO.NET
Disconnected Mode
)( Update DataAdapter
ADO.NET .
w w.pdf actory.com
660
:
) BindingManagerBase (2- 19
)( AddNew
)( CancelCurrentEdit )( RemoveAt
PositionChanged :
)Bmb = Me.BindingContext(ds
End Sub
_ Private Sub Bmb_PositionChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles Bmb.PositionChanged
'
End Sub
Complex Binding
Simple
Binding
.
Complex Binding
Relationships
Simple Binding
w w.pdf actory.com
: XML
661
) .(A 4- 19
ComboBox
) .(B 4- 19
:4- 19 ComboBox .
ComboBox
ComboBox1
) ( " "
:SelectedValue
ds '
_ ComboBox1.DataBindings.Add("SelectedValue", ds,
)"] []. ["
w w.pdf actory.com
662
:
DataGrid
DataSet
DataSource ) DataMember :(5- 19
)]", cn[ Dim da As New OleDbDataAdapter("SELECT * FROM
)(Dim ds As New DataSet
)"" da.Fill(ds,
DataGrid1.DataSource = ds
"" = DataGrid1.DataMember
:5- 19 .DataGrid
XML
XML
XML ADO.NET
w w.pdf actory.com
: XML
663
XML :
Imports System.XML
: XML
XML
.
XmlTextReader
- StreamReader
BinaryReader
XmlTextReader .XML
XmlTextReader
StreamReader BinaryReader
.ADO.NET
DataReader Command
XmlTextReader :
XML
Loop
w w.pdf actory.com
664
:
XML
Case XmlNodeType.Attribute
Case XmlNodeType.Element
Case XmlNodeType.Entity
End Select
Loop
:Name
Do While xmlData.Read
If xmlData.NodeType = XmlNodeType.Element Then
)">" & MsgBox ("<" & xmlData.Name
End If
Loop
)(:Close
)(xmlData.Close
XmlTextWriter
XmlTextWriter XML
Encoding
:
w w.pdf actory.com
: XML
665
WriteStartDocument :
)(xmlData.WriteStartDocument
)( WriteStartxxx )( WriteEndxxx
:XML Elemnts
)"xmlData.WriteStartElement("Table
)"xmlData.WriteStartElement("Name
)" "(xmlData.WriteString
)(xmlData.WriteEndElement
)"xmlData.WriteStartElement("Name
)" "(xmlData.WriteString
)(xmlData.WriteEndElement
)(xmlData.WriteEndElement
)(xmlData.Close
:
>? "<?xml version="1.0" encoding="utf-8
><Table
></Name ><Name
></Name ><Name
></Table
MSDN .
ADO.NET XML
ADO.NET XML
XML
XML .
w w.pdf actory.com
666
:
XML
XML
:DataSet WriteXml()
DataSet
: xml
<Departments>
<ID>1</ID>
<Name>< /Name>
</Departments>
<Departments>
<ID>2</ID>
w w.pdf actory.com
: XML
667
></Name ><Name
></Departments
></NewDataSet
XML Employees
Departments
Nested
DataSet True Nested
").Nested = True"(ds.Relations
)"ds.WriteXml("C:\test.xml
:
>? "<?xml version="1.0" encoding="utf-8
><NewDataSet
><Departments
><ID>1</ID
></Name ><Name
><Employees
></Name ><Name
><Age>99</Age
><DepartmentID>1</DepartmentID
></Employees
></Departments
><Departments
><ID>2</ID
></Name ><Name
><Employees
></Name ><Name
><Age>88</Age
><DepartmentID>2</DepartmentID
></Employees
><Employees
></Name ><Name
><Age>77</Age
><DepartmentID>2</DepartmentID
></Employees
w w.pdf actory.com
668
:
></Departments
></NewDataSet
XML
)( WriteXml
DataSet test.xml
.DataAdapter
ADO.NET
ADO.NET
w w.pdf actory.com
w w.pdf actory.com
w w.pdf actory.com
20
(1) ASP.NET
ASP.NET
Web Forms
ASP.NET
ASP.NET .
HTML
)
!(.
IIS
Visual Basic .NET
IIS -
ASP.NET .
w w.pdf actory.com
672
:
IIS
- IIS
.ASP.NET
.Windows
:1- 20 .IIS
w w.pdf actory.com
: (1) ASP.NET
673
IIS
Web Server
.
Internet Explorer
http://localhost
IIS
.Web Server
Microsoft .
.URL
Virtual
Directory .
Folder
w w.pdf actory.com
674
:
:2- 20 .
Alias
URL test
http://localhost/test
test.html
:
http://localhost/test/test.html
w w.pdf actory.com
: (1) ASP.NET
675
IIS
... Index.html Default.html.
IP Address :
http://999.999.999.999/test/test.html
IIS Internet
w w.pdf actory.com
676
:
:3- 20 .IIS
Properties IIS
) (4- 20
IIS .
w w.pdf actory.com
: (1) ASP.NET
677
:4- 20 .
Web Forms
ASP.NET
Windows
Windows Forms
.NET Framework
w w.pdf actory.com
678
:
.aspx Web
Notepad ASP.NET
)Console Windows Applications
.NET
.NET .
New->Project File
:5- 20 .
w w.pdf actory.com
: (1) ASP.NET
679
Internet Explorer
Work Offline
Internet Explorer Work Offline
.File
) (6- 20
AssemblyInfo.vb
Windows Application Styles.css
w w.pdf actory.com
680
:
Web
HTML
) - 20
.(7
w w.pdf actory.com
: (1) ASP.NET
681
Target Page Layout
:8- 20 .
HTML
HTML
Grid Windows
Forms Web
.Forms
w w.pdf actory.com
682
:
Target Schema
Navigator 3
Internet Explorer
5 .
) Client
( JScript
Internet Explorer ) (
Web Form
Windows Form Label
Button TextBox
:Click
! ASP.NET
] [F5
Internet
Request
.Label
w w.pdf actory.com
: (1) ASP.NET
683
:9- 20 Button
.Label
w w.pdf actory.com
684
:
: Server
!Client
Q315158 :
Microsoft ) Q315158
(MSDN
ASP.NET IIS ) (10- 20
ASP.NET .
:10- 20 .ASP.NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q315158
.
w w.pdf actory.com
: (1) ASP.NET
685
Machine.config processModel
:userName Attribute
"<processModel enable="true
>/
machine :SYSTEM
"userName="SYSTEM" password="AutoGenerate" logLevel="Errors
.ASP.NET
Configuration Files
.Assemblies
- )
.(11- 20
w w.pdf actory.com
686
:
:11- 20 .
HTML Web Forms
Visual Basic .NET Requests
HTML Browser :
HTML :
Web Form
:
></HEAD
>"<body MS_POSITIONING="GridLayout
>"<form id="Form1" method="post" runat="server
w w.pdf actory.com
: (1) ASP.NET
687
HTML
ID runat
" "server
Server .Client
:Visual Basic .NET
_ Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
" & TextBox1.Text " = Label1.Text
End Sub
TextBox Label
- -
Message Box
w w.pdf actory.com
688
:
HTML:
Request HTML
Browser :
>"<HTML dir="rtl
><HEAD
><title>WebForm1</title
></HEAD
>"<body MS_POSITIONING="GridLayout
"<form name="Form1" method="post" action="WebForm1.aspx
>"id="Form1
></form
></body
></HTML
aspx
ASP.NET
@Page
:aspx
:Code-Behind Classes
Visual Studio .NET
w w.pdf actory.com
: (1) ASP.NET
689
DLL src
@Page :
_
aspx src
DLL
. *.aspx.vb
ASP
>"<SCRIPT RUNAT="server
_ Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
" & TextBox1.Text " = Label1.Text
End Sub
></SCRIPT
w w.pdf actory.com
690
:
ASP.NET
. ) Server side script ASP
Page
System.Windows.Forms.Form Windows Form
End Class
Windows
Forms
.
Page
.
.@Page
dir
rtl Culture
Regional Settings .
w w.pdf actory.com
: (1) ASP.NET
691
Exception
ASP.NET
:ErrorPage
"me.ErrorPage = "http://www.dev4arabs.com/error.aspx
IsPostBack
Submit
True .
Controls
Next
HttpResponse HttpRequest
(Application Session
EnableViewState :ViewState
TextBox
Submit
TextBox
w w.pdf actory.com
692
:
) (Submit
EnableViewState True
Me.EnableViewState = True
EnableViewState True
False
Listbox1.EnableViewState = False
True EnableViewState
ViewState
-
:
ViewState Dictionary
Collection
)(... Insert() Add .
Dictionary
MSDN .
w w.pdf actory.com
: (1) ASP.NET
693
:SmartNavigation
Submit
ScrollBars
True SmartNavigation .
SmartNavigation
InternetExplorer .
)( MapPath Virtual
Directory )( :
- )( HasControls True
Init
Load
.IsPostBack
Unload
w w.pdf actory.com
694
:
ErrorPage
.Error
@Page
SmartNavigation @Page
:
@Page aspx
.
@Import ) Imports
aspx
aspx.vb Visual Basic .NET
Visual
!Basic .NET
w w.pdf actory.com
: (1) ASP.NET
695
Reference
)
:(Reference
><%@ Reference page="WebForm2.aspx" %
Web Forms
Windows Forms
Web Forms
! -
Web Forms
) (ID ) (Name
HTML BorderStyle
BorderWidth .
CSS . Font
CheckBox
RadioButton
w w.pdf actory.com
696
:
RadioButton !
RadioButton .GroupName
HTML
HTML .
Server HTML Forms Controls
) ( .
.NET
J Script VBScript .Java Script
HTML Toolbox
).(10- 20
w w.pdf actory.com
: (1) ASP.NET
697
Validation
Jscript VBScript .
RequiredFieldValidator
) ( RangeValidator
CompareValidator
CustomValidator Validation )
(.
w w.pdf actory.com
698
:
) (RequiredFieldValidator
Empty
. Script
Scripts
.
BaseValidator
ControlToValidate
ErrorMessage .
Submit ) .(13- 20
w w.pdf actory.com
: (1) ASP.NET
699
:13- 20 .RequiredFieldValidator
w w.pdf actory.com
700
:
ASP.NET Applications
Web Forms .
Web Forms
ASP.NET .
w w.pdf actory.com
21
(2) ASP.NET
ASP.NET
ASP.NET
HttpApplicationState HttpSessionState
.NET Documentation
HttpRequest
-ReadOnly
.
w w.pdf actory.com
702
:
POST Submit
GET URL :
http://www.dev4arabs.com/test.asp?id=1&site=vb
GET
:QueryString
) POST (GET
:RequestType
"Me.Request.RequestType = "POST
:ContentLength
)Label1.Text = CInt(Me.Request.ContentLength
IP Address
UserHostAddress DNS
:UserHostName
Label1.Text = Me.Request.UserHostAddress
Label2.Text = Me.Request.UserHostName
Browser Browser
HttpBrowserCapabilities 25
VBScript ...:
IE
6
WinNt
True
'
'
'
'
Me.Request.Browser.Browser
Me.Request.Browser.MajorVersion
Me.Request.Browser.Platform
Me.Request.Browser.VBScript
w w.pdf actory.com
=
=
=
=
Label1.Text
Label2.Text
Label3.Text
Label4.Text
: (2) ASP.NET
703
Upload
Files
HttpPosttedFile :
Dim uploadedFile As HttpPostedFile
For Each uploadedFile In Me.Request.Files
)uploadedFile.SaveAs(uploadedFile.FileName
Next
HttpResponse
HttpResponse
HTML )( Write
)( WriteFile :
)( Redirect
End :
)"Me.Response.Redirect("http://www.dev4arabs.com/accessDenied.aspx
)(Me.Response.End
Cookies HttpCookie
w w.pdf actory.com
704
:
Request :Response
'
' 1234
Label1.Text = Me.Request.Cookies("NAME").Value
Label2.Text = Me.Request.Cookies("PASSWORD").Value
HttpServerUtility
HttpServreUtility Server
MachineName
ScriptTimeout Timeout
TextBox1.Text = Me.Server.MachineName
Me.Server.ScriptTimeout = 20
)( Execute
aspx .
HttpApplicationState
IIS
Hosting
Server .
-ASP.NET
IIS HttpApplicationState
) .(1- 21
w w.pdf actory.com
: (2) ASP.NET
705
IIS
http://localhost/sitename
HttpApplicationState.
:
" " = )" "(Me.Application
)" "(Label1.Text = Me.Application
)( Lock )( Unlock
)(Me.Application.Lock
)") + 1 "(") = CInt(Me.Application "(Me.Application
)(Me.Application.Unlock
w w.pdf actory.com
706
:
)( Item
HttpSessionState
HttpApplicationState HttpSessionState
HttpSessionState
) .(1- 21
:2- 21 HttpSessionState .
HttpSessionState
HttpApplicationState
HttpSessionState
:
w w.pdf actory.com
: (2) ASP.NET
707
IsNewSession True
HttpSessionState
:
If Me.Session.IsNewSession Then
Me.Application("Counter") = Me.Application("Counter") + 1
End If
Global.asax
ASP.NET Visual Studio
.NET Global.asax
ASP.NET - Global.asax
ASP.NET Global.asax
aspx .
Global Global.asax
) ( .
)( xxxStart )(xxxEnd
Global
:
Imports System.Web
Imports System.Web.SessionState
Public Class Global
Inherits System.Web.HttpApplication
_ Sub Application_Start(ByVal sender As Object,
)ByVal e As EventArgs
End Sub
End Class
w w.pdf actory.com
708
:
Application_Start()
Session_Start() Application_End()
HttpSessionState Session_End()
-
: -
Global_Error()
w w.pdf actory.com
: (2) ASP.NET
709
)( Global_Error
GetLastError
Server HttpUnhandledException
InnerException :
Security
ASP.NET
IIS Windows
Visual
Basic .NET
- .ASP.NET
Authentication
.Authorization
) ( User
.Anonymous Requests
w w.pdf actory.com
710
:
IIS .
Authentication
Authorization
aspx
.
Windows IIS
Administrator
.
ASP.NET
IIS Windows
Authentication
Configuration Files .
ASP.NET
Authentication Authorization
IIS .Windows
-Windows Authentication
IIS .Authorization
) (
.Windows
w w.pdf actory.com
: (2) ASP.NET
711
Forms -
Authentication Authorization
.
Passport Authentication
Forms
.ASP.NET
Assemblies
Configuration Files
Application .config
ASP.NET
web.config web.config
.
Forms
Forms Authentication
- Login Page
.
Forms : aspx
Authenticated ASP.NET
- Authentication Ticket
w w.pdf actory.com
712
:
Cookies
.
Authentication
web.config authentication
:authorization
><configuration
><system.web
><authentication mode="Windows" /
><authorization
><allow users="*" /
></authorization
></system.web
></configuration
><configuration
><system.web
>"<authentication mode="Forms
><forms loginUrl="/login.aspx" name="dev4arabs" timeout="10"/
></authentication
></system.web
name
Cookie
timeout -
Session .
w w.pdf actory.com
: (2) ASP.NET
713
>"<authentication mode="Forms
></authentication
><authorization
><deny users="?" /
></authorization
></system.web
><credentials
> <credentials
> <forms
>:<authentication
><configuration
><system.web
>"<authentication mode="Forms
> <forms
>"<credentials passwordFormat="Clear
>" password="123" / "=<user name
>" password="456" / "=<user name
></credentials
></forms
></authentication
></system.web
w w.pdf actory.com
714
:
passwordFormat
" "Clear.
Login
) (3- 21
!
:3- 21 .
> <credentials
)( Authenticate
System.Web.Security.FormsAuthentication
True :
w w.pdf actory.com
: (2) ASP.NET
715
Imports System.Web.Security
)( RedirectFromLoginPage True
Cookie .
: Caching
.Http Modules
Caching
ASP.NET HTML
Caching
.Server
@OutputCache
aspx -
Refresh
:VaryByParam
w w.pdf actory.com
716
:
10 Label Button :
) 4- 21 ( @OutputCache
) 4- 21(.
VaryByParam
:
http://www.dev4arabs.com/testcache.aspx?id=1
http://www.dev4arabs.com/testcache.aspx?id=1
http://www.dev4arabs.com/testcache.aspx?id=1
http://www.dev4arabs.com/testcache.aspx?id=2
http://www.dev4arabs.com/testcache.aspx?id=2
http://www.dev4arabs.com/testcache.aspx?id=3
10 id
GET
.POST
w w.pdf actory.com
: (2) ASP.NET
717
:4- 21 Cached .
w w.pdf actory.com
718
:
Client Server
- -Server Downstream
) .(Proxy
Location :Any
>Location="Downstream"%
>Location="Server"%
>Location="Client"%
>Location="Any"%
OutputCache
OutputCache
OutputCache
OutputCache
@<%
@<%
@<%
@<%
Application
)Application("Counter") = CInt(Application("Counter") + 1
Module :
Module MainModule
Public Counter As Integer
End Module
:
Counter += 1
Bandwidth -
Response ContentType
aspx HTML
:JPG
w w.pdf actory.com
: (2) ASP.NET
719
:5- 21 .
) (5- 21 aspx .JPG
URL
w w.pdf actory.com
720
:
! GDI+
) :(6- 21
:6- 21 .
-
:GDI+
w w.pdf actory.com
: (2) ASP.NET
721
"Response.ContentType = "image/jpeg
)bmp.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg
'
)(Font.Dispose
)(gr.Dispose
)(bmp.Dispose
ASP.NET
.NET Framework Web Services
.
w w.pdf actory.com
w w.pdf actory.com
22
Web Services
ASP.NET
Web Services
:
Imports System.Web.Services
Visual Basic .NET )
w w.pdf actory.com
724
:
DLL
.
- - VBNETBook )(GetUpdates
Visual Basic .NET :
.NET
HTTP
) XML :(1- 22
:1- 22 .
w w.pdf actory.com
: Web Services
725
.NET
HTTP .XML
ASP.NET
ASP.NET New-
w w.pdf actory.com
726
:
ASP.NET web.config
:3- 22 .
Service1.asmx
Class Library
.HTTP
Service1.asmx
SaudiRiyals.asmx.
w w.pdf actory.com
: Web Services
727
aspx asmx
ToolBox
.
) FileSystemWatcher
System.IO.
FileSystemWatcher
.(Windows
SaudiRiyals.asmx Service1
System.Web.Services.WebService .
) (Name SaudiRiyals
)(FromEG
)(:FromBRN
Imports System.Web.Services
_ >)"<System.Web.Services.WebService(Namespace:="http://tempuri.org/
Public Class SaudiRiyals
Inherits System.Web.Services.WebService
" #Region " Web Services Designer Generated Code
#End Region
>)" "=<WebMethod(Description:
Function FromEG(ByVal amount As Decimal) As Decimal
Return amount * 0.9
End Function
_ " "=<WebMethod(Description:
>)"" &
Function FromBRN(ByVal amount As Decimal) As Decimal
Return amount * 10
End Function
End Class
w w.pdf actory.com
728
:
)( FromEG )( FromBRN
.Decimal
WebService WebMethod
- Web Service
Class .
SaudiRiyals
Internet Explorer
]) [F5 .(4- 22
w w.pdf actory.com
: Web Services
729
ASP.NET
Reflection Classes
.Internet Explorer
w w.pdf actory.com
730
:
.NET Framework
.
FromBRN
) .(5- 22
:5- 22 )(.FromBRN
Object Classes
Primitive
6- 22 (.
w w.pdf actory.com
: Web Services
731
:6- 22 300 .
)( FromEG XML
-
.XML
HTTP HTTP
.NET
Windows Macintosh
Visual Basic
w w.pdf actory.com
732
:
.Windows Application
Windows Application
Soulution Explorer - Add Web Refrence Add
) Reference .(7- 22
:7- 22 .
Add Web Reference
)
asmx
http://localhost/Exchanger/SaudiRiyals.asmx (
] [Enter
) .(8- 22
w w.pdf actory.com
: Web Services
733
Web References
w w.pdf actory.com
734
:
:9- 22 .SaudiRiyals
) (9-22
Show All files .Solution Explorer
w w.pdf actory.com
: Web Services
735
TextBox
Button
) .(10- 22
) Windows Application (
.
) 9- 22 ( Update Web
Reference .
w w.pdf actory.com
w w.pdf actory.com
XML
eXtensible Markup Language
.NET Framework
XML .
XML XML
.
HTML
HTML
HTML Tags
HTML Formating
.
HTML :
></p ><p
><p>99</p
HTML
w w.pdf actory.com
2-
:
></p >: </b></p> <p><p><b
>: </b></p> <p>99</p><p><b
HTML
:
></p ><p
:
></font></p >"<p><font face="Tahoma" size="4
:
></font >"<font face="Tahoma" size="4
!
:
w w.pdf actory.com
XML :
3-
!!! Browser
XML
XML
99
88
77
w w.pdf actory.com
4-
1 :
3 :
2 :
99 :
88 :
77 :
XML
:
XML
test.xml
XML )
(.
w w.pdf actory.com
: XML
5-
Elements
XML
> <xxx
.XML Elements
Capital .Small
XML :/
><test
></test
:
><test /
:
><aa
><bb
><cc /
></bb
></aa
Attributes
Attributes
X Y 10 ) 20 (:
PrimaryKey :
w w.pdf actory.com
6-
Comments
Comments XML
> -- :<!--
><test
<!-
>--
></test
XML
.XML
w w.pdf actory.com
SQL
.
SQL -MSDN
SQL SQL
SQL
.SQL
SQL
(DDF) Data Definition Language Data
Tables Fields
DML Records
DML
DDF
.DDF
SELECT
SELECT SQL
. "
" :
w w.pdf actory.com
8-
] [ SELECT * FROM
WHERE
"":
] [ SELECT * FROM
WHERE
'' = ][
:BETWEEN
] [ SELECT * FROM
WHERE
] BETWEEN 2000 AND 10000[
:IN
] [ SELECT * FROM
WHERE
)'' ',' ','( ] IN[
:BY
)( ORDER
][ ] ORDER BY [ SELECT * FROM
w w.pdf actory.com
: SQL
9-
:DESC
] DESC[ ] ORDER BY [ SELECT * FROM
INSERT INTO
INSERT INTO :
] [ INSERT INTO
) ][ ],[ (
VALUES
) '' ', ' (
UPDATE
UPDATE WHERE
10000 :32421
] SET [ UPDATE
] = 10000[
WHERE
] = 123[
WHERE "" :
] SET [ UPDATE
] * 2[ = ][
WHERE
'' = ][
WHERE :
] SET [ UPDATE
] = 0[
w w.pdf actory.com
10 -
DELETE
DELETE :
] [ DELETE FROM
:WHERE
] [ DELETE FROM
WHERE
] < 18[
SQL
ANSI-92 .NET Data
w w.pdf actory.com
w w.pdf actory.com