You are on page 1of 781

PDF created with pdfFactory Pro trial version

.NET

Visual Basic .NET

--

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

))
((

w w.pdf actory.com

PDF created with pdfFactory Pro trial version



...

...

...

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

.NET
Visual Basic .NET
2003
- .NET Visual Basic .NET


. .

- ) ADO .NET Visual Basic .NET

.... Microsoft(

- - 3876 :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

..................................................................
..................................................................

.............................................................

.................................................................

...............................................
Visual Basic 16 .....................

................................

.......................................

................................... CD-ROM
...................................

) ( .............................................
....................................................
: 1 .............................................................
: 3 .............................. Visual Basic .NET

3 ....................................................... .NET
4 .......................................... DOS

4 ....................................... Windows

7 ................................. COM

8 ...............................................
10 ..............................

10 ..................................................... .NET

11 ................................

.NET 11 ............................ COM


13 .........................................
13 ...........................
14 ....................................

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

15 .......................... .NET Framework

16 ...................................... JIT
17 ..................................... Assemblies

17 ................................. Visual Studio .NET

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

PDF created with pdfFactory Pro trial version

72 ................................

73 ......................... Windows API


74 .......................................................
74 ............................... If Then
77 .............................. Select Case
79 ............................................

81 ......................................................
82 ..........................................

84 ..........................

85 ..................... Imports
87 ................ Imports

: 89 ................................................
89 .................................................

94 ....................................................

94 .............................................. Fields
96 ........................................... Methods

105 .................................... Properties


110 ............................................ Event

116 .....................................................

116 ........................................

119 ....................................
123 ...................................................

126 ........................................
137 .............................

138 ...................................................

138 ......................... Shared Fields


140 ...................... Shared Methods
141 ................ Shared Properties

142 ....................... Shared Events

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 147 ........................................................
147 ....................................................
147 .................................................

149 ................. Visual Basic .NET

152 ..................................
152 .............................................

154 .................................. Constructors

157 .........................................

159 ........................................... Overriding


161 .............................

166 ......................................... MyBase


168 ........................................ MyClass
169 ...................................... Shadowing

173 .................. Shared Members

174 ..............................................
174 ........................ NotInheritable
174 ............................ MustInherit
176 ......................... MustOverride

177 ....................................................

177 .........................................

181 ................................

184 ......................

: 187 .........................
187 ............................................................

190 .................................................
192 .............................................

196 .......................................

197 ............................................

198 ...................... .NET Framework

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

199 ................................... IComparable


201 ...................................... ICloneable
IEnumerable 203 .............. IEnumerator

207 .............................................................

208 ........................................

211 .............................................
212 .............................................

214 .............................................

217 ..........................................................

217 ........ Visual Basic .NET

218 ..................... .NET Framework

218 ....................... Conditional Attribute

221 ........ DebuggerStepThrough Attribute

221 .......................... Obsolete Attribute

StructLayout 223 ...... FieldOffset

225 .......................................
: 229 .............................. .NET Framework
: 231 .............................................
231 .............................................. System.Object
232 ........................................ Object

234 ..........

236 ........................................

236 .......................................................
239 .........................................

242 .............................................

243 ........................................ CultureInfo


246 .........................................

247 ..................................... Char

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

248 .......................... StringBuilder

250 ........................................................
251 ........................................

252 ..............................................
254 ................................................ Math

255 ............. Random Numbers

256 ..........................................................

256 .......................................

263 ................................... Enum

265 .................................... Array

270 ............................... System.Collections

ICollection 270 .......................... IList

271 ................................................ Stack


272 ............................................... Queue

273 ........................................... ArrayList

: 275 ..............................................
275 ...........................................................
275 .......................................

276 ..........................................

278 ....................................................

279 .................................................. Exception


280 ............... Catching Exceptions
284 .............. Throwing Exceptions

287 ..... Custom Exceptions

288 .......................................................... Err

288 ..........................................
290 ...........................................

Exception 290 ........................... Err

292 ........................... Visual Studio .NET

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

292 ...............................................

294 .................................................
296 .............................. Configurations

: 299 ............................................
299 .................................................... Directory

301 ........................................

302 ...............................

303 ........................................................... File

305 ....................................................... Stream

306 ...............................

309 ..................................

312 ..................................

Custom Streams 314 .........................


316 ..........................................................
316 .................................................. Path

DirectoryInfo 317 ...................... FileInfo

: 321 ................. Object Serialization


322 ..........................................
322 .............................................

323 ......... Binary Serialization

) ( 325 ................

228 .......................... Object Graph

231 ...............................................

Custom Serialization 335 .............................


336 .................................... ISerializable
337 ................................................

338 .............................................. XML

340 ..................................... XmlSerializer

341 ...........................................

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

345 ..............................

: 349 ............................... Threading


349 ............................................
350 .......................................

351 .......................

353 ............................................

354 ........................................

364 ..................................

368 .....................................................

369 ...............................

370 ..................... ThreadStatic Attribute

372 ................................ TLS

374 ...........................
377 .............................. Thread Synchronization
377 ............... SyncLock End SyncLock

379 ............................. Synchronization


380 .................................. MethodImpl

381 .................................................

383 ................................................. ThreadPool


386 ................................................... Timers
387 ........................ System.Timers.Timer
388 .................... System.Threading.Timer

: 391 .............................. Assemblies


391 ............................ Managed Modules

392 ............................................ Assemblies

393 .......................
394 .....................................

395 ..............................

397 ........................... Strong Names

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

397 ..................................... Assembly

398 ............................... Configuration Files


399 .........................................

400 ............................................

400 ......................................

403 .... .NET Framework Configuration

405 ....................................

406 ...................................... VBC.EXE


408 .......................................... AL.EXE

412 ......................................... SN.EXE


413 ............................... GACUTIL.EXE

: 415 ................. Reflection Classes


415 .............................
416 ........................................... Assembly

418 ............................................. Module

419 ............................................
419 ....................................... System.Type

421 ...........................................

422 .................................................
422 .............................. MemberInfo
425 ..........................................

426 ......................................

428 ..........................................

429 .........................................

430 ............................................ Parameters

431 ..................................................
431 ............................... ReflectionExample

/ 432 ......................................

/ 433 ..................................

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

433 .............................................

435 ......................................................
435 ...................................
436 ................................

: 439 ................................... Windows


: 441 ............................ Windows Forms
442 .............................. Windows Forms
442 .......................... Form Designer

445 ..................................
448 .................................

Form 449 .............................

450 ......................................

450 ..........................................

453 ..............................................
456 .............................................

460 ............................................... MDI Forms

461 .......................... Child Windows

462 ...................................

463 ...................................................... Menus

465 ..............................

466 ............................ Popup-Menu

MDI 466 ....................................


469 ...................................

469 ......................................................

469 .............................. Modeless

470 ........................ Form Inheritance

474 .............................................

: 479 .................................... Controls

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

479 .................................................

480 .......................................... Name

480 ...........................................
482 ....................................

487 ........................................
488 ...........................................
489 ...........................................
489 ...........................................

490 ............................................

490 .....................................................
491 ...................................................
492 ................................................

493 ........................................

494 ..............................................
494 ...............................................

495 ...............................................
497 ............................................... Label
497 ......................................... LinkLabel

498 ........................................... TextBox


501 .............................................. Button
501 ......................................... CheckBox
502 ...................................... RadioButton

502 ............................................ ListBox

504 ................................. CheckedListBox


505 ........................................ ComboBox

505 ......................................... ImageList


506 .......................................... TreeView
508 ........................................... ListView

ToolBar 509 .......................... StatusBar

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

510 .............................................. Splitter


510 ..............................

514 ............................................

515 ...............................................

518 ..........................................................

518 ................................... RightToLeft

520 ........................... RightToLeft

521 .....................................

522 ............. Visual Basic .NET

527 ..............................................

527 ..............................

528 ............................................

: 531 ........................................ GDI+


531 ........................................................

532 .......................................... Graphics


533 .......................
534 ......................................

535 ............................................. Pen

538 ......................... GraphicsPath

537 ......................................................

540 ....................................... Brush

542 ...............................................

545 ...................................................
545 .......................................

546 ..............................................

549 ................................

552 ...............................................
552 ............................................. Icons

554 ...................................................

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

554 .............................................

556 .............................................

557 ................................................
558 ..................................... StringFormat

567 ....................................... Controls

: 571 .......................................

571 .................................................
572 ...................................................

578 ................................
581 ............................................

582 .........................................

587 .......................................... Windows

587 .............................. Windows

588 .............. Windows Service

590 .............................................
592 ................ System.IO.FileSystemWatcher

593 ..............................................

595 ..............................................

596 .................................. InstallUtil.EXE

598 ..........................................................

598 ........................................ Application

599 ............................................... Cursor


600 .......................................... SendKeys

Registry 601 ....................... RegistryKey


603 ................................................. Help

: 605 ...........................................
: 607 ................................. ADO.NET

608 ............................................ ADO.NET

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

608 ..........................

609 ........................ .NET Data Providers

611 ......................................... ADO.NET

612 ........................................ Connection

612 ..........................................

613 ...............................................

614 .....................................

617 .......................................... Command

618 ...........................................

618 ...........................................

620 ................................. SQL

621 .............................................

623 ........................................ DataReader

623 ..........................................

624 .............................................

626 .......... Microsoft SQL Server


627 ..........................................

ADO.NET : 629 .........................

629 ............................................. DataSet


632 .......................................... DataTable

633 ........................................... DataRow


634 ....................................... DataColumn

634 ...................................... DataRelation


DataSet 635 ....................

638 ....................................... DataAdapter


638 ...................................
639 ......................... DataAdapter

640 ...........................................

641 ...............................................

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

644 .............................................

648 ............. xxxCommand


649 .................................................
650 .........................................

651 .................................... RowUpdated

: 653 ...................... XML

653 .........................................................
654 .................................................

655 .............................................

656 .........................................

659 .............................. ADO.NET


660 ........................ Complex Binding

662 .............................................. XML


663 ................................... XmlTextReader

664 ................................... XmlTextWriter

ADO.NET 665 ...................................... XML

666 ............................... XML

668 ............................... XML


: 669 .....................................................
: 671 ................................. (1) ASP.NET
671 ........................................................... IIS
672 .......................................... IIS
673 ...............................................

675 .................................

677 .................................... Web Forms

678 .............................................
681 ....................................

682 ..............................................

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

685 ...............................................

688 .......................................

690 ...................................................

690 .......................................................... Page

690 ...................................

693 .......................................
693 ......................................

694 ...............................................

695 ............................................................

695 .......................... Web Forms Controls

696 ....................... HTML Forms Controls

697 ................................ Validation

: 701 ....................... (2) ASP.NET


ASP.NET 701 ..............................
701 ..................................... HttpRequest
703 .................................... HttpResponse

705 ............................... HttpServerUtility

705 .......................... HttpApplicationState

706 ................................ HttpSessionState

707 ............................................... Global.asax


)( xxxStart )(707 ..................... xxxEnd

)(708 ................................. Global_Error

709 .................................................... Security


709 .....................................

708 .......................... ASP.NET


709 ...............................................

Forms 709 ...................................


>713 .................................... <credentials

714 ............................. Login

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

715 ......................................................
715 ......................................... Caching
718 ............................................

718 ...............................................

720 ....................................

: 723 .................... Web Services


723 .............................................
724 ...................................

725 ......................................................
725 .............................................
727 ................................................

728 .................................

731 .............................................

735 ..............................................

: .......................................... XML 1
: ............................................... SQL 7

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

Visual Basic .NET


.NET

) (dev4arabs.com

! 2=1+1 ) (

Microsoft .NET
.

.NET


!
) (Microsoft


.NET

w w.pdf actory.com

PDF created with pdfFactory Pro trial version


.NET

Documentation

.NET Documentation .
" MSDN
" .NET
Documentation .

.(iawmd.com) IAWMD

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

.NET .Visual Basic .NET


.

) Visual C# .NET Visual


(Basic .NET
Visual Studio .NET

)(dev4arabs.com

) (
:

Visual Basic .NET ) Microsoft .NET


( . )(vb4arab.com

) (Visual Basic

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

. )
( .

.
.


.
--

w w.pdf actory.com

PDF created with pdfFactory Pro trial version



Visual Basic .NET Microsoft
..NET

Visual Basic .NET Visual C# .NET

.NET Framework

.NET -
.NET .Visual Basic .NET .NET

Visual Basic .NET

.NET Framework Visual Basic .NET


)

( .NET

.NET Framework

Microsoft .NET .
:

Windows ADO.NET

.

.NET

.Visual Basic .NET

w w.pdf actory.com

PDF created with pdfFactory Pro trial version



.

.

Tutorial
.

Step by Step .

Reference

.
.

Workshop

Comprehensive


.NET Framework
.NET Framework

Visual Basic 16

.Visual Basic

Visual Basic .NET Visual Basic 1->6


w w.pdf actory.com

PDF created with pdfFactory Pro trial version

.Microsoft Microsoft .NET


Visual C# .NET Visual Basic
.

- .

Microsoft Visual C# .NET

: C#

BASIC - if Then
";" .

Visual Basic .NET Visual C# .NET

) Microsoft

(.

Visual Basic .NET Visual Basic

1->6 Visual Basic .NET

-
.Visual Basic

- Visual Basic
Microsoft Visual Basic
..NET

Help

- "" ""

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

.Windows Overloading

" "
" " .


.NET Documentation

.NET Framework
MSDN

.Microsoft
.

700 :

Visual Basic .NET


. OOP Classes

Objects Inheritance

.Polymorphism

.NET Framework

.NET Framework

Exceptions File IO Object

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

Serialization Threading Assemblies

.Reflection Classes

Windows Application Windows

Forms Controls
Mirroring .

GDI+ .

Custom Controls Windows

.Services

ADO.NET Connected

Mode Disconnected Mode


ADO.NET .XML

ASP.NET ASP.NET

ASP.NET Web Services

CD-ROM

) (JPG
.

ArabicConsole.DLL Console -
.Visual Basic .NET

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

.

:

http://www.dev4arabs.com/lib/vbnetbook

) (


. ) (


.

. -

.Visual Basic .NET

w w.pdf actory.com

PDF created with pdfFactory Pro trial version


Source Codes .

-


.NET Documentation.

.NET Visual Basic .NET

.NET Framework

Visual Basic .NET

... !
--

2003
turki@dev4arabs.com

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

Visual Basic .NET


Visual Basic .NET 14

11 Visual Basic
..NET Framework
) Visual Basic for .NET Framework Visual Basic

.(.NET Framework

Visual Basic .NET

.
.NET

- .NET

.Framework


..NET

.NET

DOS
Microsoft .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

4
:

DOS
- - Input

Print
.

- - Devices )

...(

.Drivers
Assembly .

.

- -

. Lotus 123 MS-

DOS 200
.

) ( .

Windows

Windows

-
-

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Visual Basic .NET


5

Windows DOS


Messages

Click ... KeyDown .

- -
.

Print

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

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

: Visual Basic .NET


7

) !(.

Windows
Windows

Windows

Address Spaces Windows


.(DDE) - Dynamic Data Exchange

DDE

Microsoft

(OLE) - Object Linking & Embedding

DDE
- Microsoft Excel Microsoft

.Word

1993 Microsoft OLE

DDE OLE2
In-place Activation Excel

Word .Word

COM

Windows

(COM) - Component Object Model

- Object
.Oriented
(DCOM) - Distributed COM

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

8
:

COM Windows

) COM ActiveX Controls

.... ActiveX DLL(

Component Oriented Programming

.COM

COM

Interfaces
System Resources

COM Windows

Registry

Reinstall .

) (DCOM


Format .

Versioning .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Visual Basic .NET


9

.(ASP) - Active Server Pages

ASP

ASP

OOP VBScript .

ASP COM

nTied Applications ADO


COM ASP

ASP


)(

HTML ) Tags
(HTML
.

(SOAP) Simple Object Access Protocol

) XML

(HTML .TCP/IP

SOAP - -

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

10
:

Bugs SOAP
.

) VBScript
( ) ASP (

T-SQL
Optimization COM
Visual C++ Microsoft

Office VBA
Windows .Visual Basic

DAO ADO RDO Databases


DirectX GDI OpenGL

Microsoft .


.Microsoft .NET

.NET

.NET .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Visual Basic .NET


11


:
Notebooks Servers Mobiles

Digital TVs .Digital



) (
. ..NET

Hardware

Windows .NET Framework


Linux .Macintosh

) (

) ( .

.NET
Framework

.NET COM

.NET COM 2.0


,COM . COM

.NET -

.NET COM
.NET COM

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

12
:

System Registry

.NET
COM

....(.

DCOM Windows

.NET
.

Versioning

.NET COM

Inheritance COM
.NET

COM

) Visual

(Basic COM

) (Visual C++

) Visual Basic Pointers( .NET


.NET CRL

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Visual Basic .NET


13


.NET Visual Basic .NET
Visual C# .NET
Java Delphi .NET :

) Turki .NET Visual C++ .NET .NET (... Fortran .NET

CRL .

.NET

. .NET MSIL
Compiling .

Browser

Web Services
.

Web Service

) (XML Web Service

Requests Response HTTP

XML
.
XML
XML TCP/IP .NET

Framework .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

14
:

... Goggle Search.

.NET Framework
UNICODE


...

- -
.NET Documentation.

Mirroring

) Windows Forms (Windows


.NET Framework

HijriCalendarClass
.

HijriCalendarClass
.

Microsoft

-
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Visual Basic .NET


15

.NET Framework
.NET Framework
10 -

) :(1- 1

:1- 1 .NET Framework


) Base Class Library .NET Framework

(Class Library DLL


) (Integer String
I/O File Processing Threading Windows

Forms Web Forms ADO .NET .

(CLR) Common Language Runtime

.NET

Memory Management Garbage Collection

) Exception Handling
(.

.NET Framework

Windows ) (
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

16
:

JIT
- -

.NET (JIT) - Just In Time Compiling


)
(Optimization ) :(2- 1

:2- 1 .

Executable File

) Microsoft Intermediate Language IL .(MSIL

JIT
Compiler

Visual Basic .NET


Server 9504378250470592

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Visual Basic .NET


17

JIT


) (NGEN) Native Image Generator (Pre-JIT Compiler


) . .NET
Documentation .(NGEN

Assemblies
Assembly ) EXE (DLL

Compiling

Resource Files HTML .


.

Assemblies

- -
- .Assemblies


.NET

.Framework

Visual Studio .NET


) (
-

.

.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

18
:

) Visual Visual C#.NET Visual Basic .NET

C++ .NET( Microsoft Visual Studio. NET


.

Visual Studio .NET -


Microsoft Press

Visual Basic .NET


.


Visual Studio .NET ) Start Page - 1
(3
.NET Framework

Headlines Start Page .

:3- 1 .Visual Studio .NET

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Visual Basic .NET


19

: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

PDF created with pdfFactory Pro trial version

20
:

:5- 1 Class View


Cursor . Class View

View .

:Solution Explorer

) .(6- 1 Solution
Explorer View .

:6- 1 Solution Explorer

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Visual Basic .NET


21

References

Add Reference

) .(7- 1

:7- 1 .Reference
.
:Project Property Pages

) 6- 1 ( Properties

) 8- 1 ( . Assembly

.Name

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

22
:

:8- 1 .

xxx Property Pages


) xxx (
Project Property Pages
.

:Object Browser

Reference

View->Other

Windows->Object Browser ) 9- 1

(.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Visual Basic .NET


23

:9- 1 .
:Code Editor

) 10- 1 ( IntelliSense
" ".

.
" "+ .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

24
:

:10- 1 .
) ....(

Text Editor ) Option 4- 1 .(19

.
:File

. Printing
.
:Edit

Copy Cut Paste


.Bookmarks

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Visual Basic .NET


25

:View
.
:Project


Reference . Set As
Startup Project
Project .Solution

:Build

Compiling

Configuration

Manager .

:Debug

13 ) (
Debugging.


.

:Tools


.Externals Tools Add-

Ins .Add-In Manager

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

26
:

:Window
!
:Help

MSDN .NET Documentation


. Dynamic Help

.
.

Toolbars
Customize
.Microsoft Office

Visual Basic .NET


Visual Studio .NET .

Solution Projects


Project Files .Project Items

Solution Blank

Solution New File New

Project . OK

Visual Studio .NET - - .sln .suo


sln suo

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Visual Basic .NET


27

Project New File

Node Visual Basic Projects

Templates .

Add to solution ) OK :(11- 1

:11- 1 Templates .

) Solution Explorer 6- 1 .(27

Visual Basic .NET .vb

) UserControls Windows Forms


... Classes( .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

28
:


Visual Basic .NET User

Controls Windows Application Class Library


New Projects
:

:Windows Application

Windows ) .(Standard Application


Windows .
:Class Library

.DLL
:Windows Control Library

User Controls

.Windows Application

:ASP .NET Web Application

ASP .NET Server


Clients .Browsers

ASP .NET .
:ASP .NET Web Service

HTTP XML DCOM


.Web Services

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Visual Basic .NET


29

:Web Control Library


HTML
User Controls
.Browser

:Console Application

DOS .


.Visual Basic .NET

:Windows Services

Windows Background
.
.

:Empty Project

.
:Empty Web Project
.

Templates
Windows Service

Windows Application User Control


.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

30
:

Visual Basic .NET Notepad


- .Console Application

Visual Basic .NET


.

Console Application

Module Module1
)(Sub Main
End Sub
End Module

Module1 FirstProg Console


.

Module FirstProg
)(Sub Main
Console.WriteLine("In the name of Allah the most gracious
)"and the most merciful

End Sub
End Module

] [F5 Start Debug )

Compiling (


] [ENTER :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Visual Basic .NET


31

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

PDF created with pdfFactory Pro trial version

32
:

ArabicConsole

'
' ArabicConsole
Imports ArabicConsoleProject

)" "(

Module FirstProg
)(Sub Main
ArabicConsole.WriteLine
End Sub
End Module


Imports ArabicConsoleProject
.

)( Read

ArabicConsole .

Compiling
- - Compiler

Visual Studio .NET

.Configurations
Debug

) Visual Studio .NET :(13- 1

:13- 1 .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Visual Basic .NET


33

Release
.
Configuration Properties
.Project Property Pages

.NET

Framework microsoft.com

100 .

.NET Visual Studio .NET


.Visual Basic .NET Visual Basic
.NET .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

PDF created with pdfFactory Pro trial version

w w.pdf actory.com




.Windows

Visual Basic .NET Windows Forms

Visual Basic .NET

Windows Applications Web






Applications ... Windows Services Visual Basic .NET


Windows

ArabicConsole

Visual Basic
.NET . -

...(
.Visual Basic .NET

Modules

Module

FirstProg :Module

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
37

Identifiers ) ...( :

16383 -

"_"

"_" ) (.

Keyword .

] [ ) Dim [Dim] :

.( As Integer ] [

Visual Basic .NET


UNICODE

:
As New Dim
As Integer Dim
= 23 Then. If
= 0.2 =
End If
) (20,._.

Module

'
MyModule '

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
39

)" "(ArabicConsole.WriteLine
End Sub
End Module

)( Main
Startup Object Project

) Property Pages .(1- 2 Module


)( Main Sub Main

) ( )( Main
.

:1- 2 .

)(Sub New
New

Constructor .
)(New

)(:Main

Module Module1
)(Sub New

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
41

Visual Basic .NET

Dim As

' Integer
Dim Age As Integer
' String
Dim FirstName As String
Dim LastName As String

String
Visual Basic .NET :

Dim Age As Integer


Dim FirstName, LastName As String

:
'
'
Dim FirstName, LastName As String, Age As Integer

Object :

Dim X
' Integer
' String

w w.pdf actory.com

X = 10
"X = "10

PDF created with pdfFactory Pro trial version

42
:


.
:Option Explicit

Option Explicit Off


:Dim

Option Explicit Off


Module Module1
)(Sub Main
'
' Dim
" " = programmerName
) ArabicConsole.Writeline ( programmerName
End Sub
End Module

'
'
) ArabicConsole.Writeline ( programerName

Option Explicit Off


Object

Option Explicit Off

Off Option Explicit Build

) Project Property Pages 2- 2 (.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
43

:2- 2 Option Explicit On .Off


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

PDF created with pdfFactory Pro trial version

44
:

:
Dynamic Local Variables


. .

Dim .

Microsoft .NET smallCase

small
.Capital:

Dim programmerName As String


Dim userID as Integer
Dim employeeSalary As Decimal

Block level Variables ) Block For


Next If Then Do Loop( .


. y :For Next

Dim counter As Integer


For counter = 1 To 10
Dim y as integer

Next

- :

Dim x As Integer
If x = 0 Then
Dim y As Integer

End If
'

w w.pdf actory.com

x = y

PDF created with pdfFactory Pro trial version

:
45

Dim a As Integer
Do
'

Dim a as integer

Loop

Visual Basic .NET

'
Dim x As Integer

'

If x = 0 Then
Dim x As String

End If
Do

'

Dim x As Long

Loop

For counter2 :

Dim counter As Integer


Dim counter2 As Integer
For counter = 1 To 3
For counter2 = 1 To 3
' Dim x As Integer
x = x + 1
)ArabicConsole.WriteLine(x
Next
Next

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

46
:

:
1
2
3
4
5
6
7
8
9

:
Static Local Variables

) (
Static Dim :

Static staticVariable As Integer

)( 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

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

48
:

'

'
Module Module2
)(Sub Test
x = 1

End Sub
End Module

Friend
Public
. Friend
.

.NET PascalCase

smallCase :
'

Public ProgrammerName As String


Friend ClientAge As Integer

'

Dim programmerName As String


Private clientAge As Integer

) .... Date Long Integer String( -

Visual Basic .NET Classes Structures

) BCL .NET Framework


( : Object

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
49

.
Byte .

Visual Basic .NET -


)

Primitive Data Types :Visual Basic .NET

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

PDF created with pdfFactory Pro trial version

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 .String Unicode

Char
" "c Char
:String

Dim A As Char
'

"c" = A
"c" = A

Char

String

. Char

Value Type Variables String


.Reference Type Variables
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
51

:
-
-

Visual Basic .NET Object

. - Visual

Basic .NET :

Reference Type Variables .Value Type Variables

Value Type Variables

) System.ValueType

( .
) Stack
( .

Numbers Char Boolean Date


Structures Enums .Value Type

Reference Type

) Pointer
(

Managed Heap


Garbage Collection .NET :
'
'

" " = Dim Name As String


Dim Age As Integer = 99

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

52
:

:3- 2 .



.

String Arrays

Classes .Reference Type

"="

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

Visual Basic .NET

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

PDF created with pdfFactory Pro trial version

54
:

Value Type .Reference Type


) 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

PDF created with pdfFactory Pro trial version

:
55

) (Stack 4
.

:Option Strict

Widening Conversion )Short


( ) (Double :

Dim A As Single = 3.9999


Dim B As Double = A
' 3.9999
' 3.9999

)ArabicConsole.WriteLine(A
)ArabicConsole.WriteLine(B

Double

Single

Double :Single

Dim A As Double = 3.9999999


Dim B As Single = A
' 3.9999999
' 4

)ArabicConsole.WriteLine(A
)ArabicConsole.WriteLine(B

Visual Basic .NET


Single

.Double Narrowing

Conversion ) (Double )

.(Single : Long Integer Short ... Byte.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

56
:

) (Bugs

Option Strict On Visual Basic .NET


Option Strict On:

'
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

... Boolean Date String:

'
Option Strict Off '
Dim A As String
Dim B As Boolean
"A = "True
B = A

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

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 :

" " = Const PROGRAMMER_NAME


' )ArabicConsole.WriteLine(PROGRAMMER_NAME

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
59

Option

:Strict On

" " = Const PROGRAMMER_NAME As String

Hexadecimal

Octal &H &O - :


' 255

'
)ArabicConsole.WriteLine(&HFF

' 8

'
)ArabicConsole.WriteLine(&O10

- Integer
" "L :
' -1
' 4294967295

)ArabicConsole.WriteLine(&HFFFFFFFF
)ArabicConsole.WriteLine(&HFFFFFFFFL

Hexadecimal Octal

'
)ArabicConsole.WriteLine(&HFF.25

Visual Basic .NET .

Enums Structures .

Enums

.Enumeration Enum

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
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

Tuesday ... 22.

Integer

Visual Basic .NET Short Byte Long .NET

Enum Day As Long


Saturday
Sunday

End Enum

Private

Public

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

User Defined Types


) (UDT .
Structure :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

Dim Turki2 As Person


Turki2 = Turki
ArabicConsole.WriteLine(Turki2.Name) '
ArabicConsole.WriteLine(Turki2.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

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

64
:

Dim Turki As Person


" " = Turki.Name
Turki.Age = 99
"" = Turki.Address.City
" " = Turki.Address.Countrey

Structure Visual

Basic .NET ) (C++

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

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

66
:

Visual Basic .NET

)( Sub New ) ( .
New

'
)" "(Dim Turki As New Person

Dim
.

Private
:

Public Dim '

'
'

Structure Person
Public Name As String
Dim Age As Integer
Private MotherName As String
)(Sub Test
" !" = MotherName

End Sub
End Structure

Public Private Access


.Specifiers Friend
Public
) (.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
67

! Structure

.Enums
:

Private

) Public (

.
Friend.

Visual Basic .NET


32:

10 '
4 = 2 * 2 '

Dim OneDim (9) As Integer


Dim TwoDims (1, 1) As String

-
:0

OneDim (0) = 100


OneDim (1) = 200

OneDim (9) = 900


""
""
""
""

=
=
=
=

)0
)1
)0
)1

(0,
(0,
(1,
(1,

TwoDims
TwoDims
TwoDims
TwoDims

}Dim OneDim() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9


}}"" ","{ "}," ","{{ = Dim TwoDims(,) As String

Dynamics Arrays

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

68
:

ReDim
ReDim :

)ReDim OneDim (99


)ReDim TwoDims (10, 10
ArabicConsole.WriteLine ( OneDim(0) ) ' 0


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

PDF created with pdfFactory Pro trial version

:
69

} Dim X () As Integer = {1, 2, 3,


Dim Y () As Integer
X ' Y
)(Y = X.Clone

)( UBound

)( LBound :

)For counter = LBound(OneDim) To UBound(OneDim

Next

:
'
'
'

)UBound(OneDim
)UBound(OneDim, 1
)UBound(OneDim, 2

Visual Basic .NET Sub Function



:
'
)(Sub MySub
)" "( ArabicConsole.WriteLine
End Sub
'
' Long
Function Abs (ByVal X As Integer) As Long
If X < 0 Then
Return -X
Else
Return X
End If
End Function

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

70
:

Parameters
:

'
)( MySub
ArabicConsole.WriteLine (Abs (-5)) ' 5

Exit Sub

Sub Exit Function :Function

Function Abs (ByVal X As Integer) As Long


If X = 0 Then
Exit Function
End If

End Function

Exit Function
0 Nothing
.

Private Friend Public.



: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

PDF created with pdfFactory Pro trial version

:
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

.

. -

Reference Type Variables



.ByVal

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

72
:


Visual Basic .NET

Optional .ParamArray
:


Optional

)Sub MySub(Optional ByVal X As Integer = -1


If X = -1 Then
)" "( ArabicConsole.WriteLine
End If

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

PDF created with pdfFactory Pro trial version

:
73

Function Sum(ByVal ParamArray Nums() As Integer) As Integer


Dim counter As Integer
For counter = 0 To UBound(Nums)
Sum += Nums(counter)
Next
End Function

:
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

Declare ..NET Framework

Auto .Auto Unicode Ansi

Windows ME Windows 98 Unicode

: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

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

74
:

If Then Select Case


.Visual Basic .NET

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

PDF created with pdfFactory Pro trial version

:
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

Else Visual Basic


.NET :

If X = 0 Then
If Y = 0 Then
X = 100
Else
Y = 1
End If
End If

:
If Then End If

) ... Not Or And(


:Visual Basic .NET

If x > 0 And t < 1 Then

End If
If Not Y > 1 Then

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

76
:

:
If X <> 0 And 10 \ X = 2 Then

X
.

X Visual Basic .NET .

Visual Basic .NET

X ) False( . And
AndAlso
:
If X <> 0 AndAlso 10 \ X = 2 Then

X Visual Basic .NET

AndAlso OrElse

:True

'
' X
'
If X > 0 OrElse Y < 0 Then

AndAlso OrElse

) (Option Strict Off

True And Or
bit-wise operators :
x = 3
y = 12
If x <> 0 And y <> 0 Then ' True

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

78
:

Select Case

Dim Grade As Integer

Select Case Grade


Case Is < 60
ArabicConsole.WriteLine
Case 60 To 69
ArabicConsole.WriteLine
Case 70 To 79
ArabicConsole.WriteLine
Case 80 To 89
ArabicConsole.WriteLine
Case Is >= 90
ArabicConsole.WriteLine
End Select

(")"
(")"
(")"
(")"
(")"

:
Dim Letter As Char

Select Case Letter


Case "A"c To "Z"c, "a"c To "z"c
ArabicConsole.WriteLine (")"
Case "0"c To "9"c
ArabicConsole.WriteLine (")"
Case "."c, ":"c, " "c, ";"c, "?"c
ArabicConsole.WriteLine (")"
Case Else
ArabicConsole.WriteLine (")"
End Select

: Or
Select Case True
Case x > 0, Y < 0
'
' If (X > 0) Or (Y < 0)

End Select

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

:
79

Select Case False


Case x > 0, Y < 0
'
) )' If ( Not (X > 0) ) Or ( Not (Y < 0

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

For counter = 1 To 100


counter = 100

Next

:Exit For

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

80
:

For counter = 1 To 50

If y = 10 Then
Exit For
End If

Next

For Each Arrays

:Collections

Dim x(5) As Integer


Dim y As Integer

For Each y In x
)ArabicConsole.WriteLine(y
Next

For Each

.

Do Loop

)
( . Until

True While
:True

", MsgBoxStyle.YesNo) = MsgBoxResult.Yes "(Do Until MsgBox

Loop
", MsgBoxStyle.YesNo) = MsgBoxResult.No "(Do While MsgBox

Loop

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
81

.Exit Do
For Next :Do Loop

For Next Do Loop


For Next

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

) Classes Modules ... Structures(


Namespace

. :Mouse

Structure Mouse

End Structure

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

82
:

- - .Mouse
.

Project
- - .
Project Property Pages

) Root namespace .(5- 2

:5- 2 .

- - .

Namespace :End Namespace

Namespace Devices

End Namespace

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
87

:6- 2 .

Imports
)
(Imports
Imports ) Project Property Pages .(7- 2

:7- 2 .Imports

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

88
:

Imports .

.Visual Basic .NET

Inheritance Interfaces Attributes

Delegates .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version


OOP Visual Basic
Visual Basic .NET ! Visual
Basic .NET OOP OOP

) Multiple Inheritance .NET


Visual C++ (.

.NET Framework

- OOP
. !

Classes Visual Basic .NET Structures


:

Structure Person
Dim Name As String
Dim Age As Integer
End Structure

Class :Structure

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

90
:

Class Person
Dim Name As String
Dim Age As Integer
End Class

Reference Type .Value Type

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

)( Public Sub PublicMethod2

End Sub

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
91

' Friend

' Private

)( Friend Sub FriendMethod

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

PDF created with pdfFactory Pro trial version

92
:

New :

)(Dim BMW As New Car


"BMW.Model = "2003
BMW.CarEngine.Cylinder = 12
' 2003
' 12

)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

PDF created with pdfFactory Pro trial version

:
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

Reference Type Value Type

- .

.NET C )

( PascalCase

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

94
:

Public Friend camelCase

: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

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

96
:

)(Dim ArrayObject As New ArrayClass


'
ArrayObject.X(0) = 100
ArrayObject.X(1) = 200

'
)ReDim ArrayObject.Y(99
ArrayObject.Y(0) = 10
ArrayObject.Y(1) = 20

ReadOnly :

Class SimpleClass
)(Public ReadOnly CreatedDate As Date = Now

End Class

ReadOnly
:

)(Dim SimpleObject As New SimpleClass


'
)(SimpleObject.CreatedDate = Now
'
)ArabicConsole.WriteLine(SimpleObject.CreatedDate

Methods

Fields Methods

) Subs (Functions .

.NET Framework -

.Methods

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

98
:

.NET PascalCase

camelCase :

)Sub ShutDown (computerName As String

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
:

)Sub SameName(ByVal X As String

End Sub
'
)Sub SameName(ByVal Y As String

End Sub

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
99

) ByRef
(ByVal :

)Sub SameName(ByVal X As String

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

PDF created with pdfFactory Pro trial version

100
:

)Overloads Sub SameName(ByVal X As String

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

PDF created with pdfFactory Pro trial version

:
101

)(Dim TestObject As New TestClass


"Dim A As String = "100
'
'
))TestObject.SameName(CInt(A


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

) If Then .(Select Case

) ( :

)Sub OpenByID (ByVal id As Integer

End Sub
)Sub OpenByName (ByVal name As String

End Sub


) String (Integer

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

102
:

Open
:

)Overloads Sub Open (ByVal id As Integer

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

)
(:

'

)(Dim TestObject As New TestClass

'

Dim TestObject2 As TestClass

'

TestObject2 = TestObject

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

Sub New(Optional ByVal firstN As String = "",


)"" = Optional ByVal lastN As String
FirstName = firstN
LastName = lastN
End Sub
End Class

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

Visual Basic .NET

) 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

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

106
:

' Value
Date ' ByVal
)Set(ByVal Value As Date
m_BirthDate = Value
End Set
End Property

)(Dim Turki As New PersonClass


Turki.BirthDate = #1/1/1903#
)ArabicConsole.WriteLine(Turki.BirthDate

Get Set :

BirthDate Set
) Value (ByVal
BirthDate Get

- Return .Functions
Read Only

Property ReadOnly ) Set

( .

Age )
:(BirthDate

ReadOnly Property Age() As Integer


Get
)Return DateDiff(DateInterval.Year, BirthDate(), Now
End Get
End Property

WriteOnly Get

) (
:

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
107

WriteOnly Property Password() As String


Set(ByVal Value As String)
m_Password = Value
End Set
End Property

Parameters

Private m_Address(2) As String


Property Address(ByVal index As Integer) As String
Get
If index >= 0 And index <= UBound(m_Address) Then
Return m_Address(index)
End If
End Get
Set(ByVal Value As String)
If index >= 0 And index <= UBound(m_Address) Then
m_Address(index) = Value
End If
End Set
End Property

:
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

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

108
:

:Default Properties


Default :

Default Property Address(ByVal index As Integer) As String

End Property

) Address (
:

" " = )Turki(0


" " = )Turki(1
" -" = )Turki(2
For counter = 0 To 2
))ArabicConsole.WriteLine(Turki(counter
Next

Address
Parameters

Age BirthDate Password


Visual Basic .NET

.Parameters

Address

Turki
! Turki :

Dim Turki(5) As PersonClass


)(Set Turki(0) = New PersonClass

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
109

Address ) (


Address:

" " = )Turki(0)(0


" " = )Turki(0)(1
" -" = )Turki(0)(2
For counter = 0 To 2
))ArabicConsole.WriteLine(Turki(0)(counter
Next

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

PDF created with pdfFactory Pro trial version

110
:

) (Note


) NumOfFrogs

Action ) Smile (.

Events
) (


.Reusable

.Events

PersonClass Die
) - Fire

Event ( . :Event

Class PersonClass
)(Event Die

End Class

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

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

Sub TestEvents() Handles Turki.Die, Ali.Die, Apple.Stink

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

PDF created with pdfFactory Pro trial version

:
113


RaiseEvent
:
)RaiseEvent TestEvent(10

:AddHandler

WithEvents Visual Basic .NET

.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

RemoveHandler Turki.Die, AddressOf PersonHasDied

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

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:

Dim Turki As New PersonClass

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
117

Managed Heap .NET Turki


4 .

Class PersonClass

Public Age As Integer

End Class

)(Dim Turki As New PersonClass


)(Dim Ali As New PersonClass
Ali.Age = 25
'
Ali = Turki
Turki.Age = 99
ArabicConsole.WriteLine(Ali.Age) ' 99

Turki Ali

Age Turki

Ali ) 1- 3 (.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

118
:

:1- 3 Turki Ali .


String

Classes String
- :Reference Type

"" = Turki.FirstName

FirstName
) Managed Heap .(2- 3

:2- 3 FirstName .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

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

:With End With

With End With


:

)(Dim TestObject As New TestClass

TestObject.Field1 = 10
TestObject.Field2 = 20
)TestObject.Method1 (10
TestObject.Property1 (2, 2) = 10

With End With :


)(Dim TestObject As New TestClass

With TestObject
.Field1 = 10
.Field2 = 20
).Method1 (10
.Property1 (2, 2) = 10
End With

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
121

:Nothing
Nothing

)(Dim Turki As New PersonClass


" " = Turki.Name
Turki = Nothing
' Turki.Age = 99

: Nothing

.
:Is
Is :

)(Dim Turki As New PersonClass


)(Dim Khaled As New PersonClass
ArabicConsole.WriteLine(Turki Is Khaled) ' False
'
Khaled = Turki
ArabicConsole.WriteLine(Turki Is Khaled) ' True

Is ) (Boolean

If Not Turki Is Khaled Then


Turki = Khaled
End If

Is

:Nothing

Turki '
If Turki Is Nothing Then
)(Turki = New PersonClass
End If

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

122
:

:TypeOf Is
TypeOf Is Is

Turki PersonClass '


If TypeOf Turki Is PersonClass Then
" " = Turki.Name
End If

: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

PDF created with pdfFactory Pro trial version

:
123


"="
- :

Dim X As New ClassA


Dim Y As ClassA
Y = X

Dim X As New ClassA


Dim Y As ClassB
'
Y = X

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

PDF created with pdfFactory Pro trial version

124
:

'
X = Y
)( X.MethodInClassB

Object

Visual Basic .NET


.

Late Binding

Early Binding -
- :
'
)( Dim X As TestClass = New TestClass
'
)( Dim X As Object = New TestClass

Option Strict :

Option Strict On Visual Basic


.NET :Late Binding

'
' Option Strict On
Dim X As Object
'

)( X = New ClassA

'

)(X.MethodInClassA

)( MethodInClassA
X
Parameter )

(ArabicConsole

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
125

Dim X As Object
Dim Y As ClassA

)( X = New ClassA
' Y = X

Visual Basic .NET

X ) Object (ClassA
Y ClassA
CType :

Dim X As Object
Dim Y As ClassA

)( X = New ClassA
Y = CType (X, ClassA) ' CType
' )(Y.MethodInClassA

" "CType CType


Operator Function )(CLng() CInt
.... CType Visual Basic
..NET CType
CType :
)"Dim Y As Integer = CInt ("10
)Dim Y As Integer = CType ("10", Integer

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

:3- 3 Managed Heap


)( MySub

)
4- 3 (.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
127

:4- 3 Managed Heap .


!

.NET

Framework Managed Heap .

- .Garbage Collection
:Circular Reference

Garbage Collection

.Circular Reference

) (Counter
.

Circular Reference .

)
.NET (Garbage Collection

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

) (5- 3 .Circular Reference

:5- 3 .Circular Reference



Turki Abdullah
Brother
) (6- 3 .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
129

:6- 3 Circular Reference.


) (6- 3

)(Dim Turki As New PersonClass


)(Dim Abdullah As New PersonClass
" " = Turki.Name
" " = Abdullah.Name
Turki.Brother = Abdullah
Adbdullah.Brother = Turki
' Turki = Nothing
'
' )ArabicConsole.WriteLine(Abdullah.Brother.Name

'
Turki.Brother = Nothing
Abdullah.Brother = Nothing
'
Turki = Nothing
Abdullah = Nothing

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

130
:

:Garbage Collection

)

(J Windows API

Garbage

.Collection

.NET Framework Garbage Collection

) (6- 3
Brother Garbage

Collection .

Managed Heap
Garbage Collection

Garbage Collection

)( Collect :GC

)(GC.Collect
)(GC.WaitForPendingFinalizers

GC .NET Framework Garbage


Collection )( WaitForPendingFinalizers

)( GC.Collect

- -

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
131

.NET Framework

)( WaitForPendingFinalizers

Thread .
Threading .Threading


Garbage Collection
Managed Heap :

)( Sub Test
)(Dim TestObject As New TestClass

End Sub

TestObject
.Garbage Collection

Destructor . Visual Basic


.NET )( Finalize

Garbage

) Collection (:

Class TestClass

)(Protected Overrides Sub Finalize


'

End Sub
End Class

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
133


Implements Interfaces
.

)( Dispose

)
...(:

Dim TestObject As New TestClass

'
)(TestObject.Dispose
'
TestObject = Nothing

- )( Dispose
)( Finalize )( Dispose :

)(Protected Overrides Sub Finalize


)(Dispose
End Sub

)( Dispose
:

Public Sub Dispose() Implements System.IDisposable.Dispose


Static CancelDisposing As Boolean
If CancelDisposing Then
Exit Sub
End If

CancelDisposing = True
End Sub

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

134
:

)( Finalize )(:Dispose
)( Dispose
)

(:

Dim TestObject As New TestClass

'
)(TestObject.Dispose
'
'
)( TestObject.MethodInClass

)( Dispose

:Exit Sub

Class TestClass

Private CancelDisposing As Boolean


)( Sub MethodInClass
'
)(' Dispose
If CancelDisposing Then
Exit Sub
End If

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

PDF created with pdfFactory Pro trial version

:
135

Throw an Exception .NET:


Class TestClass

)( Sub MethodInClass
'
)(' Dispose
If CancelDisposing Then
)"Throw New ObjectDisposedException("TestClass
End If

End Sub

End Class


Throw an Exception
Run Time Error
.

)( Dispose )( Finalize

-
:

)(Protected Overrides Sub Finalize


)(Dispose
End Sub

- )( Finalize

Garbage Collection
)( Dispose Garbage
Collection

)( Finalize Garbage Collection )( Dispose

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

136
:

. )( GC.SuppressFinalize
)( Dispose Garbage Collection )(:Finalize

Class TestClass

Public Sub Dispose() Implements System.IDisposable.Dispose

' Garbage Collection


' Finalize
)GC.SuppressFinalize(Me
End Sub
End Class

)( Dispose

)( Finalize

) ( .
)( Dispose
.Garbage Collection

Overloads )( Dispose

)
( )() Finalize (
)( Finalize )() Dispose .NET

(Framework:

Class TestClass
Implements IDisposable

Private CancelDisposing As Boolean


Public Overloads Sub Dispose() Implements IDisposable.Dispose
)Dispose(True
)GC.SuppressFinalize(Me
End Sub

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
137

)Private Overloads Sub Dispose(ByVal disposing As Boolean


If CancelDisposing Then
Exit Sub
End If
If disposing Then
'
) ( '
End If
'
)( ' Finalize
) ( '
CancelDisposing = True
End Sub
)(Protected Overrides Sub Finalize
)Dispose(False
End Sub
End Class



. 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

PDF created with pdfFactory Pro trial version

138
:

ByRef


Visual Basic .NET ) (:

Dim TestObject As New TestClass


'
'
))ByRefSub ((TestObject

Shared Members
.

Shared Fields
Shared Fields
Shared .

Class TestShared
Public FirstName As String
Shared Public LastName As String
End Class

FirstName
:

)(Dim Meshari As New TestShared


)(Dim Turki As New TestShared
"" = Meshari.FirstName
"" = Turki.FirstName
'
'

)ArabicConsole.WriteLine(Meshari.FirstName
)ArabicConsole.WriteLine(Turki.FirstName

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

)(Dim ObjectOne As New TestShared


)(Dim ObjectTwo As New TestShared
' 2

)ArabicConsole.WriteLine(ObjectOne.NumOfObjects
)(Dim ObjectThree As New TestShared

' 3

)ArabicConsole.WriteLine(ObjectThree.NumOfObjects

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

140
:

)(Sub New
NumOfObjects += 1
If NumOfObjects > 10 Then
'
: '
'
)(Throw New Exception
End If
End Sub

Shared Methods

Shared Methods

Object Instance
:

Class TestShared

Public Shared Function CheckNumOfObjects() As Integer


Return NumOfObjects
End Function
End Class

)( CheckNumOfObjects :
Dim X As TestShared
If TestShared.CheckNumOfObjects < 10 Then
)(X = New TestShared
)ArabicConsole.WriteLine(X.NumOfObjects
End If

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

) Project Property Pages 1- 2 .(32

Shared Properties


:

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

142
:

Shared Property SharedProp() As Integer


Get

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

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

144
:

: .NET
Visual

Basic .NET .NET )

.NET
.

.NET Framework

.

.

sender :e

Class PersonClass
)Event Die(ByVal sender As Object, ByVal e As System.EventArgs

End Class

sender e Parameters
Die

System.EventArgs .NET Framework


:

Class PersonClass

)(Sub KillHim
))(RaiseEvent Die(Me, New System.EventArgs
End Sub
End Class

WithEvents :AddHandler

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

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

Visual Basic .NET


Classes Objects .

.NET Framework .
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

Visual Basic .NET

.NET Framework .

.NET Framework .

.Visual Basic .NET

Visual

Basic .NET

Inheritance ) (Derived Class


) (Base Class .

Person Name Age

Employee ) Name (Age

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

148
:

Dim Turki As New Empolyee


'
' Person
" " = Turki.Name
Turki.Age = 99
'
' Employee
" " = Turki.Job
Turki.Salary = 100

.
) Person( )(Employee

Employee Age Name


Person .

.NET Framework

)
:(1- 4

Class TestClass
'
End Class

:1- 4 .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
149

System.Object

.NET Framework
.

- -OOP Is a

Employee .Person

Visual Basic .NET

Class Person
Public Name As String
Public Age As Integer
End Class

Visual Basic .NET

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

PDF created with pdfFactory Pro trial version

150
:

'
'

)ArabicConsole.WriteLine(Turki.Name
)ArabicConsole.WriteLine(Turki.Job

End Sub

Employee Person

Person (:

)(Dim Turki As New Person


'
" " = Turki.Name
'
" " = Turki.Job

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

PDF created with pdfFactory Pro trial version

:
151

:2- 4 .
Driver Employee

:Person

)(Dim Abbas As New Driver


' Person
" " = Abbas.Name

' Employee
" " = Abbas.Job

' Driver
"Abbas.CarModel = "BMW - 7 Class

OOP ) -4
(2
Containment .

) Multiple Inheritance .NET Visual


:(C++

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
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 :
'
'

)(Dim Turki As New Person


)(Dim Abdullah As New Employee
'
"" = Turki.LastName

'
' )ArabicConsole.WriteLine(Abdullah.LastName

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

154
:

Public Friend Private


:

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

PDF created with pdfFactory Pro trial version

:
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

Visual Basic .NET

. Employee
:

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

156
:

)(Sub Main
'
)(Dim Turki As New Employee
" " = Turki.Job
)ArabicConsole.WriteLine(Turki.Name

End Sub

Class Person

)Sub New(ByVal Name As String


Me.Name = Name
End Sub
End Class
Class Employee
Inherits Person

)Sub New(ByVal Name As String, ByVal Job As String


'
)MyBase.New(Name
'
Me.Job = Job
End Sub
End Class
Module Module1
)( Sub Main
'
'
)" " ", "(Dim Turki As New Employee

End Sub
End Module

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
157

MyBase
:
)Sub New(ByVal Name As String, ByVal Job As String
'
'
Me.Job = Job
)MyBase.New(Name
End Sub



Object :

Dim Turki As Object


)(Turki = New Employee

:
- .NET ) Object
,(System.Object

)(Dim Turki As New Employee


Dim Turki2 As Person
" " = Turki.Name
' Turki2 = Turki
' )ArabicConsole.WriteLine(Turki2.Name

Person

Employee Visual Basic .NET Turki


.Turki2 Turki2
Employee :Turki

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

158
:

'
Turki2.Salary = 1

)Sub PrintInfo(ByVal personObject As Person


)ArabicConsole.WriteLine(personObject.Name
)ArabicConsole.WriteLine(personObject.Age
End Sub

Person
:Person

)(Dim Turki As New Person


)(Dim Ali As New Employee
Student Person ' )(Dim Umar As New Student

'
)PrintInfo(Turki
)PrintInfo(Ali
)PrintInfo(Umar

Visual Basic .NET

)(Dim Abood As New Person


Dim Abood2 As Employee
" " = Abood.Name
' Abood2 = Abood

Employee :Person

'
' Option Strict Off
Dim Abood As Person
Dim Abood2 As Employee

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
159

)(Abood = New Employee


" " = Abood.Name
' Abood2 = Abood
' )ArabicConsole.WriteLine(Abood2.Name

Option Strict Off

Option Strict On
) ( :CType

'
' Option Strict On

)Abood2 = CType(Abood, Employee


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

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
161


Overrides :

Class Employee
Inherits Person
'
)(Overrides Sub ShowName
)ArabicConsole.WriteLine(Me.LastName & ", " & Me.FirstName
End Sub
End Class

Person
Employee :

)(Dim Abbas As New Person


)(Dim Abbas2 As New 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

PDF created with pdfFactory Pro trial version

162
:

Overrides Overridable Overridable

.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

PDF created with pdfFactory Pro trial version

:
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
.

)(:

)(Dim Abbas As Person = New Employee


)(Dim Abbas2 As Employee = New Employee
'
'

)(Abbas.ShowName
)(Abbas2.ShowName

Abbas Person

.Employee

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

Visual Basic .NET )( TestMethod

! :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
165

)(Dim obj As New BaseClass


)(Dim obj2 As New DerivedClass
'
'

)(obj.TestMethod
)(obj2.TestMethod

Overriding Overloading


Overrides Overloads .
:

Class BaseClass

)(Overridable Sub TestMethod2


)" "(ArabicConsole.WriteLine
End Sub
End Class
Class DerivedClass
Inherits BaseClass

)(Overrides Sub TestMethod2


)" "(ArabicConsole.WriteLine
End Sub
End Class

Overrides

Overloads
:

)(Dim obj As BaseClass = New DerivedClass


)(Dim obj2 As DerivedClass = New DerivedClass

w w.pdf actory.com

'
'

)(obj.TestMethod
)(obj2.TestMethod

'
'

)(obj.TestMethod2
)(obj2.TestMethod2

PDF created with pdfFactory Pro trial version

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

)(Overridable Sub MyMethod

End Sub
End Class

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
167

Class DerivedClass
Inherits BaseClass

)(Overrides Sub MyMethod

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

PDF created with pdfFactory Pro trial version

168
:

MyBase

)( Finalize )( Dispose
:
Class DerivedClass
Inherits BaseClass

)(Protected Overrides Sub Finalize


Finalize '
)(MyBase.Finalize

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

PDF created with pdfFactory Pro trial version

:
169

)(Overridable Sub OverridedMethod


)" "(ArabicConsole.WriteLine
End Sub
End Class
Class DerivedClass
Inherits BaseClass
)(Overrides Sub OverridedMethod
)" "(ArabicConsole.WriteLine
End Sub
End Class


:Me

)(Dim obj As New DerivedClass


' )(obj.Test

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

PDF created with pdfFactory Pro trial version

170
:

) (Overrides
Overridable

Visual

Basic .NET )

Warnning (:

Class DerivedClass
Inherits BaseClass
)(Sub MyMethod

End Sub
End Class

: )( MyMethod Shadows

)( MyMethod
:

)(Dim obj As New DerivedClass


' )(obj.MyMethod

Shadows )

Warnings (:

Class DerivedClass
Inherits BaseClass
)(Shadows Sub MyMethod

End Sub
End Class

Warnings

.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

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

)(Shadows Sub MyMethod2


)( MyBase.MyMethod2
End Sub
End Class

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
173

Subclassing :

Class B
Inherits A

)(Shadows Sub MyMethod2


If Then
)( MyBase.MyMethod2
Else

End If
End Sub
End Class

Shared Members

Overrides Overridable :Shadows


Class BaseClass
)(Shared Sub MyMethod

End Sub
End Class
Class DerivedClass
Inherits BaseClass
'
)(Shared Shadows Sub MyMethod

End Sub
End Class

MyBase

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
175

MustInherit Class BaseClass

End Class

DerivedClass( :

' )(Dim X As New BaseClass


' )(Dim X As New DerivedClass

Abstract Classes

) (dev4arabs.com

MustInherit Class Item


Public Title As String
Public PostedDate As Date
Public Author As String

)(Sub Delete

End Sub
)(Overridable Sub Update

End Sub
)(Overridable Sub AddNew

End Sub
End Class

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

176
:

'
Class SourceCode
Inherits Item

End Class
'
Class Tip
Inherits Item

End Class
'
Class Article
Inherits Item
Public Introduction As String

)(Public Overrides Sub Update

End Sub
)(Public Overrides Sub AddNew

End Sub

End Class

MustOverride


Item :

MustInherit Class Item

)(Sub ShowDate
End Sub
End Class


MustOverride

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
177

MustInherit Class Item

)(MustOverride Sub ShowDate


End Class

MustOverride End Sub End

Function Get Set End Property .

MustOverride
MustInherit
.


Visibility:

Private Public .Friend


Protected Protected Friend .
.


:
:Private

Private

- Module Structure

Class :

'
Private Class TestClass

End Class

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
179

Class Outer ' Friend


Friend Class Inner

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

PDF created with pdfFactory Pro trial version

180
:

:Public
Friend Public Friend

. Public
Class Library DLL.

:Protected

Protected Private ) Private (

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

PDF created with pdfFactory Pro trial version

:
181

:Protected Friend
Protected Friend
Friend Friend Protected Friend

Friend Protected 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

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

184
:

)(Dim obj As New DerivedClass


' obj.x = 10

:Protected Friend

Protected Friend Friend

Public Class TestClass


)(Private Sub New

End Sub
End Class

Public

)(Dim obj As New TestClass

TestClass

) ( )
New( . .Not Creatable Class
:Private

Private
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
185

:Friend
Friend
.

:Public

:Protected
Protected

Public Class BaseClass


)(Protected Sub New

End Sub
End Class

:
Class DerivedClass
Inherits BaseClass
)(Public x As New BaseClass

End Class

:Protected Friend

Friend

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

186
:


Public Friend

Assembly

.Assemblies


.NET Framework
OOP -

w w.pdf actory.com

PDF created with pdfFactory Pro trial version


Visual Basic .NET

.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

PDF created with pdfFactory Pro trial version

188
:

Die Name )(.Move


)
(.

OOP Polymorphism

: Same names but different


.implementation

Polymorphism

TextFile

RTFFile HTMLFile

XMLFile PictureFile

FileName
FileSize )( Save )( Delete
.

:TextFile

)Sub SaveTextFile(ByVal FileObject As 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

PDF created with pdfFactory Pro trial version

:
189

Dim TextFileObject As New TextFile


Dim RTFFileObject As New RTFFile
Dim HTMLFileObject As New HTMLFile

Select Case FileType


Case 1
"TextFileObject.FileName = "xxxx
) SaveTextFile ( TextFileObject

Case 2
"RTFFileObject.FileName = "xxxx
) RTFRTFFile ( RTFFileObject

Case 3
"HTMLFileObject.FileName = "xxxx
) HTMLTextFile ( HTMLFileObject

End Sub

BinaryFile

IFile

:IFile

)Sub SaveFile(ByVal FileObject As IFile

)( FileObject.Save

End Sub

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

190
:

)TextFile

... HMTLFile RTFFile(


.IFile

IFile
. Visual Basic .NET

:Interface End Interface


Interface IFile
'
Property FileName() As String
Property FileSize() As Integer

'
)(Sub Save
)Sub Save(ByVal TargetFile As String
)(Sub Delete

End Interface

End Function End Sub


.End Property

OOP I
.NET
PascalCase .

Visibility Friend

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

PDF created with pdfFactory Pro trial version

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

Sub MyMethod() Implements IFile.MyMethod

End Sub
'
Sub MyMethod2() Implements IView.MyMethod

End Sub

End Class

Visual Basic .NET

Implements
:

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

PDF created with pdfFactory Pro trial version

196
:

Class ManyInterfaces
Implements IFile
Implements IView

Sub MethodFromFile () Implements IFile.MyMethod

End Sub

Sub MethodFromView () Implements IView.MyMethod

End Sub

End Class

( ... HTMLFile RTFFile TextFile)


IFile IFile

:... HTMLFile RTFFile TextFile

Dim textFileObject As New TextFile()


Dim file As IFile
'
file = textFileObject
file.FileName = "MyFile.TXT"

:IFile
Sub DoSave(ByVal fileObject As IFile)

fileObject.Save ()

End Sub

:.... HTMLFile RTFFile TextFile

w w.pdf actory.com

:
197

)(Dim htmlFileObject As New HMTLFile

)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

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

:
199

.NET Framework

.Visual Basic .NET

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

PDF created with pdfFactory Pro trial version

PDF created with pdfFactory Pro trial version

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

( Array ) Sort() .( IComparable


:

Dim PersonObject(10) As Person


Dim Counter As Integer
For Counter = 0 To UBound(PersonObject)
PersonObject(Counter) = New Person()
Next
PersonObject(0).Age = 33
PersonObject(1).Age = 50
PersonObject(2).Age = 14

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

Reference Type Variables


)( Dim Turki As New Person


Dim Ali As Person

'
'
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

PDF created with pdfFactory Pro trial version

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

)( Clone .Object CType

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
203

)( Clone

Class Person
Implements ICloneable

Private Function PrivateClone() As Object Implements


ICloneable.Clone
)(Return Me.Clone
End Function
Public Function Clone() As Person
)Return CType(Me.MemberwiseClone(), Person
End Function
End Class

)( Clone :CType
Ali = Turki.Clone

ICloneable
) )( (MemberwiseClone
.

Object

.Serialization .

IEnumerable IEnumerator
For Each Next

Arrays Collections

Interfaces For Each


IEnumerable .IEnumerator

IEnumerable IEnumerator

For Each

SplitString
Sentence :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

Private Function GetEnumerator() As IEnumerator Implements _


IEnumerable.GetEnumerator
Return Me
End Function
End Class

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

:
205

IEnumerator

For Each MoveNext()


: False True
Class SplitString

Private Function MoveNext() As Boolean Implements


IEnumerator.MoveNext
If Me.currentPosition > Me.Sentence.Length - 1 Then
Me.Reset()
Return False
Else
Return True
End If
End Function
End Class

Reset()

: For Each

Class SplitString

Private Sub Reset() Implements IEnumerator.Reset


Me.currentPosition = 0
End Sub
End Class

Current

:ReadOnly

Class SplitString

Private ReadOnly Property Current() As Object Implements _


IEnumerator.Current
Get
Dim counter As Integer
Dim tmpLength As Integer = 0

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

206
:

For counter = Me.currentPosition To Me.Sentence.Length - 1


If Me.Sentence.Chars(counter) = " "c Then
Exit For
Else
tmpLength += 1
End If
Next
Current = Me.Sentence.Substring(Me.currentPosition,
tmpLength)
Me.currentPosition += tmpLength + 1
End Get
End Property
End Class

SplitString For Each


:

Dim testObject As New SplitString()


Dim x As String
testObject.Sentence = ""
For Each x In testObject
ArabicConsole.WriteLine(x)
Next

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

)Sub ShowError(ByVal delegatePointer As OneParameter


)" "(delegatePointer.Invoke
End Sub

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

208
:

Message Box Console


) Browser ( ...

. - -

) ( Shared

C\C++

Function

Pointers .

C\C++ Visual Basic .NET

Visual Basic .NET

C\C++

. Visual Basic .NET

Static Procedures Instance Procedures


C\C++ .

Static Procedures ) Subs

(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

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

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

Delegate Function OneParameter(ByVal X As Integer) As Integer

OneParameter
) System.MulticastDelegate (System.Delegate
:OneParameter

'
Class OneParameter
Inherits System.MulticastDelegate

End Class

New

)Dim Dlgt As New OneParameter(AddressOf Abs

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

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 :

)(Delegate Sub NoParameter


)(Sub Main
)Dim dlgt As New NoParameter(AddressOf MySub1
)Dim dlgt2 As New NoParameter(AddressOf MySub2
Dim dlgt3 As NoParameter
)dlgt3 = dlgt.Combine(dlgt, dlgt2
MySub1 ' MySub2
)(dlgt3.Invoke
End Sub

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

)( Combine Shared Method

dlgt .

System.Delegate CType
Option Strict On:

_ dlgt = CType(dlgt.Combine( New NoParameter(AddressOf MySub1),


)New NoParameter(AddressOf MySub2) ), NoParameter

dlgt

)( Invoke ) (:

'
_ dlgt = CType(dlgt.Combine(dlgt, New NoParameter(AddressOf MySub3)),
)NoParameter
'
)(' MySub1
)(' MySub2
)(' MySub3
'
)(dlgt.Invoke

Function

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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()

dlgt = CType(dlgt.Remove(dlgt, dlgt2), NoParameterFun)


ArabicConsole.WriteLine(dlgt.Invoke()) ' False

Remove()
.
. GetInvocationList
:
dlgt.Remove(dlgt, dlgt.GetInvocationList(0))
ArabicConsole.WriteLine(dlgt.Invoke()) ' True

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

:
217

Attributes .NET Framework

-
Source Codes
Textual .Compiler

.
Compiler

.
Structure .

C\C++ #pragma Visual


Basic 6 ) .ctl

(idl. . .NET Framework

Attributes .NET .

Visual Basic .NET

Classes
> <

>)"<System.ComponentModel.DefaultProperty ("XXX

Namespace Imports

Imports System.ComponentModel
>)"<DefaultProperty ("XXX

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

218
:

. DebuggerStepThrough

)(<System.Diagnostics.DebuggerStepThrough()> Sub MySub

End Sub

_
:

_ >)(<System.Diagnostics.DebuggerStepThrough
)(Sub MySub

End Sub

.NET Framework
.NET Framework


Visual Basic .NET

Conditional Attribute

#If :

#If MyCondition Then


)( Sub MySub

End Sub
#End If

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
219

Sub Main
)( MySub

)( MySub
End Sub

)( MySub )

MyCondition (False
- )( MySub

#If :

Sub Main
#If MyCondition Then
)( MySub
#End If

#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

PDF created with pdfFactory Pro trial version

220
:

.NET Framework Conditional Attribute


:Sub
_ >)"<Conditional("MyCondition
)(Sub MySub

End Sub
Sub Main
)( MySub

)( MySub

End Sub

)( MySub


MyCondition .False

Conditional
.Function

MyCondition
Project Property Pages

Configuration Properties Build


) Custom Constants 2- 5 (.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
221

:2- 5 .Project Property Pages

DebuggerStepThrough Attributes

Debugging

Visual Studio .NET ) Step Into


Debug ].([F11

System.Diagnostics.DebuggerStepThrough

_ >)(<System.Diagnostics.DebuggerStepThrough
)(Sub MySub

End Sub

Obsolete Attribute

Warning

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

222
:

_ >)" "(<Obsolete
)(Sub MySub

End Sub

Warning ) Output

) (View->Other Windows->Output .(3- 5

:3- 5 Warning .
Obsolete Boolean

True

_ >)", True "(<Obsolete


)(Sub MySub

End Sub


.Obsolete

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

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 :

Object Double Single String Char Long Integer Short Byte


Enum One-Dimensional Array.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
227

:
_ )<AttributeUsage(AttributeTargets.All
Class CodeInfoAttribute
Inherits System.Attribute
'
'
'

Public ProgrammerName As String


Public TesterName As String
Public Tested As Boolean

)Sub New(ByVal programmerName As String


Me.ProgrammerName = programmerName
End Sub
End Class

) 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

PDF created with pdfFactory Pro trial version

228
:

CodeInfo

Visual Basic .NET


Visual Basic .NET
.NET Framework

Class Library

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

.NET Framework

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

w w.pdf actory.com


.NET Framework

.Visual Basic .NET



.

.NET Framework

MSDN

.NET Framework .
.NET Documentation

System.Object
.NET Framework
- System.Object

System.Object .

) Object Base Class

Derived Class
(:

'
Dim X As Object '
Dim X As System.Object
X = New AnyClass

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

232
: .NET Framework

System.Object .NET

Interfaces .

Object

Object

.
)(:Equals

Overridable True

)(Dim x As New TestClass


Dim y As Object = x
ArabicConsole.WriteLine(y.Equals(x)) ' 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

PDF created with pdfFactory Pro trial version

:
233

)(:ToString
Overridable ) (String
) :(Namespaces

)(Dim obj As New TestClass


ArabicConsole.WriteLine(obj.ToString) ' MyNamespace.TestClass

.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

)(Dim Turki As New Person


Dim Khaled As Person = Turki
ArabicConsole.WriteLine(Turki Is Khaled) ' True
ArabicConsole.WriteLine(Person.ReferenceEquals(Turki, Khaled)) ' True

)( ReferenceEquals )( Equals

: )( ReferenceEquals Shared Method

. Not Overridable
)(:MemberwiseClone

)( MemberwiseClone

.ICloneable

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

234
: .NET Framework

)( MemberwiseClone Protected

) .(System.Object

Protected
.

)(:Finalize
)( Finalize Overridable Protected

)( .MemberwiseClone

.Destructors


.NET Framework

Reference Type Value Type

Managed Heap
.

) Numbers ( Booleans

Structures Enums Value Type

Boolean -

Class End Class


Reference Type

.Value Type

System.ValueType )
)( Equals Overrides
(.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
235

.NET Framework Reference Type

Arrays .Strings
Numbers Structures Enums

.Value Type

Reference Type Value Type .NET

Documentation ) Object Browser 9- 1

(23 .

Value Type

Reference Type :

) (

Managed Heap .

Garbage Collection Managed Heap


. Value Type

Value Type Visual Basic .NET

Structures

Inheritance .

Structure Person
Public Name As String
Public Age As Integer
End Structure

) (Class End Class


)
4(.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

Option Strict On '


' CInt
)X = CInt(Y

Object ) )( WriteLine

.(ArabicConsole Value Type



.


String
:

Dim x As String
'
)ArabicConsole.WriteLine(x.Length

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
237

x Length

New
:
Char ' String
)Dim X As New String("A"c, 5
"Dim Y As String = "AAAAA

-
.
Reference Type
:

" " = Dim X As String


Dim Y As String = X
X ' Y
'
ArabicConsole.WriteLine(X Is Y) ' True

""( Visual Basic .NET


.String IntelliSense

) String 1- 6 (.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

238
: .NET Framework

:1- 6 IntelliSense .String


) ( Managed Heap .

Visual Basic .NET

" " = Dim X As String


" " = Dim Y As String
ArabicConsole.WriteLine(X Is Y) ' True

X Y

. &
:Compiling

" " = Dim X As String


"" & " " & "" = Dim Y As String
ArabicConsole.WriteLine(X Is Y) ' True

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
239


String Length Chars
Chars

Char ) (:

"Dim X As String = "ABCDE


' A
' E

))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

"

" = Dim MyString As String

' )ArabicConsole.WriteLine(MyString.Trim

)( Trim ) Char

(ParamArray :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

240
: .NET Framework

" ** ** " = Dim MyString As String


))ArabicConsole.WriteLine(MyString.Trim(" "c, "*"c

Trim )( TrimStart )( TrimEnd


.

ParamArray
.

)( StartsWith )( EndsWith

" " = Dim MyName As String


'
") Then"(If MyName.StartsWith
'
") Then"(If MyName.EndsWith

End If
End If

)( Insert )(

)( Remove

" " = Dim MyName As String


'))" " ArabicConsole.WriteLine(MyName.Insert(4,
' ))ArabicConsole.WriteLine(MyName.Remove(4, 8

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
241

)( Replace

Dim Story As String

))" " ","( ArabicConsole.WriteLine (Story.Replace

)( Split

" "c :

" " = Dim MyString As String


)Dim Words As String() = MyString.Split(" "c
Dim counter As Integer
)For counter = 0 To UBound(Words
))ArabicConsole.WriteLine(Words(counter
Next

)( ToCharArray Char
.
)(Dim Words As Char() = MyString.ToCharArray

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

242
: .NET Framework

)( ToUpper

Capital Letters )( ToLower :

"Dim MyString As String = "I like Visual Basic .NET


ArabicConsole.WriteLine(MyString.ToUpper) ' I LIKE VISUAL BASIC .NET
ArabicConsole.WriteLine(MyString.ToLower) ' I like visual basic .net

)( Compare

0 1 -
1 :

"Dim s1 As String = "AAA


"Dim s2 As String = "BBB
)Select Case String.Compare(s1, s2
Case 0
)"ArabicConsole.WriteLine("s1 = s2
Case 1
)"ArabicConsole.WriteLine("s1 > s2
Case -1
)"ArabicConsole.WriteLine("s1 < s2
End Select

Case-sensitive

" "turki TURKI )( Compare

:True

ArabicConsole.WriteLine(String.Compare("TURKI", "turki", True)) ' 0

) ( ""

"":
' 1
' 0

"( ArabicConsole.WriteLine (String.Compare

))"" ",
))""" ,"(ArabicConsole.WriteLine(String.Compare

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
243



)
(
.

)( Compare

)( CompareOrdinal
UNICODE ) ...(:

)"" ","( ArabicConsole.WriteLine(String.CompareOrdinal


' 0
") ' -19" ","( ArabicConsole.WriteLine(String.CompareOrdinal

CultureInfo

Visual Basic .NET .NET


Framework


... .

System.Globalization

.NET
Framework
.NET Documentation
Microsoft

- - .CultureInfo

CultureInfo

) ...(

LCID

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
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

)() Compare (String


CompareOptions.IgnoreSymbols:

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

246
: .NET Framework

)"Dim KSA As New CultureInfo("ar-SA


' 1
"(ArabicConsole.WriteLine(String.Compare

)""" ,
' 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

PDF created with pdfFactory Pro trial version

:
247

)( IndexOf

"?Dim x As String = "Can you find the word find


Dim index As Integer = 0
Do
)index = x.IndexOf("find", index + 1
If index < 0 Then
Exit Do
Else
)ArabicConsole.WriteLine(index
End If
Loop

" = Dim x As String

"
")) ' 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

Dim X As Char = "A"c


"Dim Y As Char = "B

PDF created with pdfFactory Pro trial version

248
: .NET Framework

Char Shared Methods

) )( (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

ArabicConsole.WriteLine(Char.IsDigit("A1", 0)) ' False


ArabicConsole.WriteLine(Char.IsDigit("A1", 1)) ' True

: Char Value Type

Reference Type .String


.

StringBuilder

)
( :

" " = Dim x As String


)ArabicConsole.WriteLine(x
'
' ))" " ArabicConsole.WriteLine(x.Insert(8,
))ArabicConsole.WriteLine(x.Remove(4, 4
'

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
249

Managed Heap " " " "

" " :

" " = Dim x As String


)" " Dim y As String = x.Insert(8,
)Dim z As String = x.Remove(4, 4
'
'
'

)ArabicConsole.WriteLine(x
)ArabicConsole.WriteLine(y
)ArabicConsole.WriteLine(z

Reference Type

Managed Heap .Garbage Collection


Garbage Collection
Reference Type
.

System.Text.StringBuilder
) (String Buffer
.

String Buffer Capacity

100 String Buffer '


50 '
)(Dim x As New System.Text.StringBuilder
x.Capacity = 100
'
)Dim x As New System.Text.StringBuilder(50

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

250
: .NET Framework

String

) )( Remove() Insert(
- StringBuilder - :

)"" x.Insert(0,
)" " x.Insert(4,
'
' )ArabicConsole.WriteLine(x

)( Append

)(Dim x As New System.Text.StringBuilder


Dim counter As Integer
For counter = 1 To 9
)x.Append(counter
Next
ArabicConsole.WriteLine(x) ' 123456789

StringBuilder
String String

:StringBuilder

)Dim Y As New System.Text.StringBuilder(50


' " " = Y


.NET Framework

Single Long Integer Short Byte :


Double Decimal .Value Type

Integer Short Long Int16 :

Int32 Int64
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

) Floating-point Single (Double

)( 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

PDF created with pdfFactory Pro trial version

252
: .NET Framework

)( ToString

:String

Dim x As Integer = 100


ArabicConsole.WriteLine(x.ToString) ' 100

)(ToString
# 0 :

Dim x As Integer = 10
ArabicConsole.WriteLine(x.ToString("####")) ' 10
ArabicConsole.WriteLine(x.ToString("0000")) ' 0010


.NET Documentation " ". " ",

" "% " "E

: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

) (:

Dim MyDouble As Double = 123456789


' Currency
.ArabicConsole.WriteLine(MyDouble.ToString("C")) ' 123,456,789.00 .
' Scientific
ArabicConsole.WriteLine(MyDouble.ToString("E")) ' 1.234568E+008

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

Dim Germany As New CultureInfo("de-DE")


Dim MyDouble As Double = 123456789
With Germany
' 123.456.789,00
ArabicConsole.WriteLine(MyDouble.ToString("C",
' 1,234568E+008
ArabicConsole.WriteLine(MyDouble.ToString("E",
' 12,345,678,900.00%
ArabicConsole.WriteLine(MyDouble.ToString("P",
' 123.456.789,00
ArabicConsole.WriteLine(MyDouble.ToString("N",
' 123456789,00
ArabicConsole.WriteLine(MyDouble.ToString("F",
End With

.NumberFormat))
.NumberFormat))
.NumberFormat))
.NumberFormat))
.NumberFormat))

NumberFormat

NumberFormatInfo
:

Imports System.Globalization

Dim Custom As New NumberFormatInfo()


Dim X As Double = -12345.6789
'
Custom.NumberDecimalSeparator = ";"
'
Custom.NegativeSign = "*"
ArabicConsole.WriteLine(X.ToString("", Custom)) ' *12345;6789

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

254
: .NET Framework

Math

Microsoft.VisualBasic.Math

Microsoft.VisualBasic
:

Imports Microsoft.VisualBasic

Math )( Abs Absolute

Value )( Sqrt )( Pow )(Log

)( 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:

Function NthSqr(ByVal num As Double, ByVal root As Double) As Double


)Return num ^ (1 / root
End Function

'
ArabicConsole.WriteLine(NthSqr(8, 3)) ' 2

)( IEEERemainder

)( Ceiling
)( Floor :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

ArabicConsole.WriteLine(Math.Round(1.1256, 1)) ' 1.1


ArabicConsole.WriteLine(Math.Round(1.1256, 2)) ' 1.13
ArabicConsole.WriteLine(Math.Round(1.1256, 3)) ' 1.126

)( ... Tan() Cos() Sin

. .NET Documentation

Random Numbers
System.Random
)( Next Integer:

)(Dim Rnd As New Random


Dim counter As Integer
For counter = 1 To 10
ArabicConsole.WriteLine(Rnd.Next) ' 2345684
Next

)( 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

PDF created with pdfFactory Pro trial version

256
: .NET Framework

)(Dim Rnd As New Random


Dim counter As Integer
For counter = 1 To 10
10- ' 10
))ArabicConsole.WriteLine(Rnd.Next(-10, 10
Next

Byte

)(:NextBytes

)(Dim Rnd As New Random


Dim counter As Integer
Dim x(99) As Byte
)Rnd.NextBytes(x
)For counter = 0 To UBound(x
))ArabicConsole.WriteLine(x(counter
Next

Date System.DateTime
:

Dim today As Date


Dim yesterday As DateTime

today yesterday Time Date

26 ' 2002
12:00 '
)Dim today As New Date(2002, 9, 26

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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#

) (ReadOnly Hour Day Month Year

Minute Second :

)Dim today As New Date(2002, 9, 26, 13, 30, 0


' 2002
' 9
' 26
' 13
' 30
' 0

)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

)( AddMinutes() AddHours() AddDays() AddMonths() AddYears


)(:AddSeconds

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

258
: .NET Framework

)Dim today As New Date(2002, 9, 26


Dim adate As Date
10 '
' 2002/10/06
)adate = today.AddDays(10

)Dim today As New Date(2002, 9, 26


Dim adate As Date
27 '
' 2002/8/30
)adate = today.AddDays(-27

)( DaysInMonths

ArabicConsole.WriteLine(Date.DaysInMonth(2002, 1)) ' 31

( -

'
)Dim today As New Date(2002, 9, 26
'
) ( '
'
ArabicConsole.WriteLine(today) ' 1423/7/20

today )(ToString
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
259

Calendar

:CultureInfo

Imports System.Globalization

)"Dim KSA As New CultureInfo("ar-SA


'
)Dim today As New Date(1423, 7, 20, KSA.Calendar

today )

( 6

) ( )(
:

Imports System.Globalization

)"Dim Egypt As New CultureInfo("ar-EG


: '
'
)Dim today As New Date(1423, 7, 20, Egypt.Calendar


HijriCalendar :

Imports System.Globalization

)(Dim hijra As New HijriCalendar


'
)Dim today As New Date(1423, 7, 20, hijra

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

260
: .NET Framework

HijriCalendar

Calendar .
Overrides - HijriCalendar

Overloads - )(GetDayOfMonth() AddYears() AddMonths

)( ... GetDayOfWeek ) .NET Documentation

(.

)( 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

PDF created with pdfFactory Pro trial version

:
261

:2- 6 Regional Options Control


.Panel


.Windows Registry

Dim x As Date = Date.Now


26/09/2002
26 September, 2002
10:41:32
10:41

'
'
'
'

)ArabicConsole.WriteLine(x.ToShortDateString
)ArabicConsole.WriteLine(x.ToLongDateString
)ArabicConsole.WriteLine(x.ToLongTimeString
)ArabicConsole.WriteLine(x.ToShortTimeString

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

262
.NET Framework :

:ToString()

Dim X As New Date(2002, 12, 20, 23, 30, 0)


' 2/12/20
ArabicConsole.WriteLine(X.ToString("y/M/d"))
' 02/12/20
ArabicConsole.WriteLine(X.ToString("yy/MM/dd"))
' 2002/Dec/Fri
ArabicConsole.WriteLine(X.ToString("yyy/MMM/ddd"))
' 2002/December/20 Friday
ArabicConsole.WriteLine(X.ToString("yyyy/MMMM/d dddd"))
' 11:30:00 P
ArabicConsole.WriteLine(X.ToString("hh:mm:ss t"))
' 11:30:00 PM
ArabicConsole.WriteLine(X.ToString("hh:mm:ss tt"))
' 23:30:00
ArabicConsole.WriteLine(X.ToString("HH:mm:ss"))
' 2002/30/20 11:30:00 PM
ArabicConsole.WriteLine(X.ToString("yyyy/m/d hh:mm:ss tt"))

mm MM
.

( ... )

. ( )
)DateTimeFormatInfo
:(DateTimeFormatInfo CultureInfo DateTimeFormat

Dim X As New Date(2002, 12, 20)


Dim arabicDateFormat As DateTimeFormatInfo
arabicDateFormat = New CultureInfo("ar-SA").DateTimeFormat
arabicDateFormat.Calendar = New HijriCalendar()
' 1423//16
ArabicConsole.WriteLine(X.ToString("yyyy/MMMM/d dddd", _
arabicDateFormat))

PDF created with pdfFactory Pro trial version

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

)( ToString Enum Overrides

Dim Turki As Programmer


Turki = Programmer.VisualBasic
' 0
' VisualBasic

)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

PDF created with pdfFactory Pro trial version

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

Turki = [Enum].Parse(GetType(Programmer), "CSharp", True)

Enum

Dim Turki As Programmer


Turki = CType(4, Programmer)
ArabicConsole.WriteLine(Turki)
ArabicConsole.WriteLine(Turki.ToString)

' 4
' Delphi

: IsDefined()
If [Enum].IsDefined(GetType(Programmer), 3) Then
Turki = CType(3, Programmer)
End If


String .GetValues() GetNames()
: Object

Dim names() As String = [Enum].GetNames(GetType(Programmer))


Dim values As Array = [Enum].GetValues(GetType(Programmer))
Dim counter As Integer
For counter = 0 To UBound(names)
ArabicConsole.WriteLine(names(counter) & " = " & _
CInt(values.GetValue(counter)))
Next

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

266
: .NET Framework

}Dim X() As Integer = {1, 2, 3


Dim Y As Array = X
)Y.SetValue(100, 0
)Y.SetValue(200, 1
)Y.SetValue(300, 2

)(' X
'
ArabicConsole.WriteLine(X(0)) ' 100
ArabicConsole.WriteLine(X(1)) ' 200
ArabicConsole.WriteLine(X(2)) ' 300

)( Clone

}Dim X() As Integer = {1, 2, 3


))(Dim Y() As Integer = CType(X.Clone, Integer
Y(0) = 100
Y(0) = 200
Y(0) = 300
'
)(' X
ArabicConsole.WriteLine(X(0)) ' 1
ArabicConsole.WriteLine(X(1)) ' 2
ArabicConsole.WriteLine(X(2)) ' 3

Array Rank

Length

GetLenght :

Dim X(9, 5) As Integer


2
60
10
6

'
'
'
'

)ArabicConsole.WriteLine(X.Rank
)ArabicConsole.WriteLine(X.Length
))ArabicConsole.WriteLine(X.GetLength(0
))ArabicConsole.WriteLine(X.GetLength(1

For Each Next

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
267

) (0, 0 ) (0, 1 ) (0, x ) (1, 0 ).... (1, 1

_ "}," "," ","{{ = Dim records(,) As String


}}"" "," ","{
Dim field As String
For Each field In records
)ArabicConsole.WriteLine(field
Next

.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 :

}Dim X() As Integer = {5, 2, 9


Dim counter As Integer
)Array.Sort(X
)Array.Reverse(X

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

268
: .NET Framework

)( Sort

}Dim X() As Integer = {1, 2, 3, 6, 4, 5, 7, 8, 9


Dim counter As Integer
'
)Array.Sort(X, 3, 5
)For counter = 0 To UBound(X
))ArabicConsole.WriteLine(X(counter
Next

)( Sort

:UNICODE

}"Dim X() As String = {"Turki", "Ali", "Basmah


Dim counter As Integer
)Array.Sort(X
)For counter = 0 To UBound(X
))ArabicConsole.WriteLine(X(counter
Next

)( Sort



Small Capital . a
Z.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
269

:
)( IndexOf

1- :

}"Dim X() As String = {"Turki", "Ali", "Ahmed


ArabicConsole.WriteLine(Array.IndexOf(X, "Ahmed")) ' 2
ArabicConsole.WriteLine(Array.IndexOf(X, "turki")) ' -1

)( IndexOf -

1-

}"" "," "," { = Dim X() As String


' -1
' -1
' -1

))"" ArabicConsole.WriteLine(Array.IndexOf(X,
))"" ArabicConsole.WriteLine(Array.IndexOf(X,
))"" ArabicConsole.WriteLine(Array.IndexOf(X,

)( IndexOf Linear Search

Binary
Search )(BinarySearch

}"Dim X() As String = {"Turki", "Ali", "Ahmed


' -1

' 0

))"ArabicConsole.WriteLine(Array.BinarySearch(X, "Ahmed
'
'
)Array.Sort(X
))"ArabicConsole.WriteLine(Array.BinarySearch(X, "Ahmed

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

270
: .NET Framework

System.Collections
System.Collections

.Collections Array

System.Collections
.

Interfaces

ICollection IList

System.Collections ICollection

) IEnumerable (
For Each .

ICollection Count

)( CopyTo

.Array

ICollection IList .IDictionary

IList )( Add
Insert() Remove() Clear()
.


) (Array
IList ) )( Add
)(.(Remove

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
271

System.Collections MSDN

.

Stack
Stack (LIFO) Last-In-First-Out
. )( Push
)( Pop :

)Dim st As New Stack(100


)st.Push(10
)st.Push(20
)st.Push(30
ArabicConsole.WriteLine(st.Pop) ' 30
ArabicConsole.WriteLine(st.Pop) ' 20
ArabicConsole.WriteLine(st.Pop) ' 10

:3- 6 .st

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

272
: .NET Framework

Queue

Queue (FIFO) First-In-First-Out

. )( 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

PDF created with pdfFactory Pro trial version

:
273

16
:Capacity
16 '
100 ' 101

)(Dim X As New ArrayList


)Dim Y As New ArrayList(100

)(: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

_ Function JoinTwoArrays(ByVal arr1 As ArrayList,


ByVal arr2 As ArrayList) As ArrayList
)JoinTwoArrays = New ArrayList(arr1.Count + arr2.Count
)JoinTwoArrays.AddRange(arr1
)JoinTwoArrays.AddRange(arr2
End Function

)( Remove

)( Clear ) ArrayList
:(IList

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

274
: .NET Framework

)""( X.Remove
)( Y.Clear



.NET Framework . .NET

Documentation .

.NET Framework
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version


" : Debugging
".

.NET Framework
.Visual Studio .NET

:
. :

) Design Time errors Syntax

(Errors
For .Next

Code Editor

Tool tip ) .(1- 7

:1- 7 .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

276
: .NET Framework

Visual Studio .NET

" "There were Build Errors ) .(2- 7

:2- 7 .
Yes ) (

No

) Task List (3- 7 View->Other


.Windows->Task List

:3- 7 .


Visual Basic .NET Run

Time Errors
. .NET .Exceptions

Exceptions

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
277

)( Move

:System.IO.File

)"System.IO.File.Move("D:\File.EXE", "C:\File.EXE

D:\File.EXE

- Visual Studio .NET


) Exception (4- 7 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

PDF created with pdfFactory Pro trial version

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(

... ...
.

Visual Basic .NET

Exception Err
.

.Bugs - -

)Sub Sleep(ByVal numOfSeconds As Integer


Dim startTime As Double
startTime = Timer
Do
)(System.Windows.Forms.Application.DoEvents
Loop Until Timer - startTime >= numOfSeconds
End Sub


Bug

) (23:59:59

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
279

) Windows Task Manager

] .([Alt] + [Ctrl] + [Del :

)Sub Sleep(ByVal numOfSeconds As Integer


Const NUMOFSEC As Double = 24 * 60 * 60
Dim startTime As Double
startTime = Timer
Do
)(System.Windows.Forms.Application.DoEvents
_ Loop Until CBool((Timer + NUMOFSEC - startTime) Mod
)NUMOFSEC >= numOfSeconds
End Sub

Debugging
) (

.Visual Studio .NET

Exception

.NET Exception )(
Microsoft

.NET Framework

Exception .

System.Exception
.

DivideByZeroException
OverFlowException NotFiniteNumberException

FileNotFoundException
... EndOfStreamException DirectoryNotFoundException

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

280
: .NET Framework

. .NET
.Documentation

.System.Exception Exception

Exception

Message StackTrace ReadOnly

-String ) "Attempted to :

" (divide by zero.

Throw an exception

.Catch the exception


.

Catching Exceptions

.Try Catch End Try

Try

:Catch

Try
'
'
'
Catch
'
'
'
End Try

Exception
:Catch

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

282
: .NET Framework

Catch

Exception
Exception .

Try Catch End Try

.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

PDF created with pdfFactory Pro trial version

:
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

Catch ex As Exception When StepNum = 1

Catch ex As Exception When StepNum = 2

Catch ex As Exception When StepNum = 3

End Try

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
285

Message

:Throw

)" "(Throw New Exception

.NET Framework
-
.

Try Catch End Try


:

)(Sub AAA
)(BBB
End Sub
)(Sub BBB
)(CCC
End Sub
)(Sub CCC
)(Throw New Exception
End Sub

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

288
: .NET Framework

Try Catch End Try

Throw :

Try

)(Throw New UnableToLoadUserFileException

Catch ex As UnableToLoadUserFileException

)ArabicConsole.WriteLine(ex.Message

End Try

Custom
Exceptions -
.Serializable
Serialization .

Err

Visual Basic .NET .NET Err

. Microsoft

Visual Basic 6 Visual Basic .NET


) Visual Basic 6->1
(.

Exception

Err .

Catching Exceptions
Err Try Catch End

Try On Error :
:

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

290
: .NET Framework

On Error Try Catch


End Try .

Throwing Exceptions

Err

)( Raise :

)Err.Raise(11

11 DivideByZeroException MSDN
1001 :

)" " Err.Raise(1001, ,

Exception Err


. Err

On Error

.Try End Try

On

Error Visual Basic .NET .NET


.

On Error Try

End Try :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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 .

Err.GetException Throw )(:Err.Raise

)(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

PDF created with pdfFactory Pro trial version

292
: .NET Framework

Throw )( Err.Raise
.

On Error Goto X
On Error Resume Next

.Caller

Visual Studio .NET


Visual Studio .NET -

.Visual Basic .NET


] [F5 Start .Debug
Visual Studio .NET .
- Start without Debugging Debug

] [Ctrl] + [F5

Start without Debugging



) Stop Debugging (Debug
-
.Windows Explorer

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
293

Breakpoints

Insert Breakpoint )

.(6- 7

:6- 7 Breakpoints .

Debug->Windows-

) Breakpoints (7- 7
>Breakpoints

:7- 7 .Breakpoints
Step Into

] [F11 Step Into

) .(8- 7
. Step Over

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

294
: .NET Framework

Debug Step Into


.

:8- 7 .Step Into

) Step Into (Step Over


Configuration Debug ) Release 13-1
.(32 .


Pause
) Breakpoints .(Step Into
. Local

Local Variables Autos

Call Stack .
) Debug->Windows .(9- 7

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
295

:9- 7 Autos Locals .Call Stack


.NET Framework Exceptions

Exceptions ) Debug .(10- 7

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

296
: .NET Framework

:10- 7 .Exceptions

Configurations
Configurations
Compiling .

Debug Release
) 13- 1 .(32

Debug Release

Configuration Manager Build

) .(11- 7

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
297

:11- 7 .Configuration Manager


Project Property Pages


Configuration Properties

) 12- 7 (.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

298
: .NET Framework

:12- 7 .

.NET

Exceptions

..NET Documentations
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version


System.IO .NET Framework

Directory File
Streams Path

DirectoryInfo FileInfo .


:
Imports System.IO

Directory

Directory Shared Methods

Folders )( CreateDirectory -
:
)"Directory.CreateDirectory("C:\Test\My Folder
)" \Directory.CreateDirectory("C:

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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 -

)"\Test \Directory.Move("C:\Test", "C:

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
301

)( Move
:

)"Directory.Move("C:\Test", "C:\TestEx

( )( Exists True
:

If Directory.Exists("C:\Test") = True Then

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

PDF created with pdfFactory Pro trial version

302
: .NET Framework

)( GetCurrentDirectory
)(:SetCurrentDirectory

)"Directory.SetCurrentDirectory("C:\Test

)( GetFiles() GetDirectories() GetLogicalDrives

)( GetFileSystemEntries String -

Dim x As String
For Each x In Directory.GetLogicalDrives
)ArabicConsole.WriteLine(x
Next

_ Dim x() As String = Directory.GetFileSystemEntries("C:\Test",


)""*.exe
Dim counter As Integer
)For counter = 0 To UBound(x
))ArabicConsole.WriteLine(x(counter
Next

)( GetParent

DirectoryInfo
.


. )( PrintFilesAndFolders


Recursion .
:

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
303

Sub PrintFilesAndFolders(ByVal path As String, _


Optional ByVal subDirectories As Boolean = False)
Dim folderName As String
Dim fileName As String
For Each folderName In Directory.GetDirectories(path)
ArabicConsole.WriteLine(folderName)
If subDirectories Then
PrintFilesAndFolders(folderName, True)
End If
Next
For Each fileName In Directory.GetFiles(path)
ArabicConsole.WriteLine(fileName)
Next
End Sub


: 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

PDF created with pdfFactory Pro trial version

= 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)

:FileAttributes Enum GetAttributes()

Dim fileAttr As FileAttributes


fileAttr = File.GetAttributes("C:\Test\program.exe")
'
If CBool(fileAttr And FileAttributes.Archive) Then
ArabicConsole.WriteLine(")"
End If
'
If CBool(fileAttr And FileAttributes.ReadOnly) Then
ArabicConsole.WriteLine(")"
End If
'
If CBool(fileAttr And FileAttributes.Hidden) Then
ArabicConsole.WriteLine(")"
End If

PDF created with pdfFactory Pro trial version

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

Stream .Storage Medium

File Memory Stream

) Virtual Device ( Parallel Port


.Network Stream

Stream Abstract Class

) (1- 8 MemoryStream FileStream NetworkStream


FileStream .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

306
: .NET Framework

:1- 8 .

Abstract Classes
.

Stream

.FileStream

-NetworkStream
. ) (

CanWrite CanRead CanSeek True


.

Buffering

) (FileStream

Buffer

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
307

)( Flush
) .(2- 8

:2- 8 )( Flush
- Stream

Stream Length

Position
.

)( Read

Byte Array )( ReadByte

. )( Write
Byte Array )( WriteByte


Position
: + .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

308
: .NET Framework

)( Close

)( Close
- )( Flush - Buffering
.FileStream

) )( ... Write() Read(

Byte Array

)
... Double Integer(
StreamReader

StreamWriter

BinaryReader

BinaryWriter

XmlTextReader .XmlTextWriter

FileStream ) .(3- 8

:3- 8 .FileStream

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
309

) !( :

-
)( Close .

StreamWriter StreamReader
BinaryReader .BinaryWriter
XmlTextReader XMLTextWriter
.XML

.MSDN

Textual Files StreamWriter


)"Dim textFile As New StreamWriter("C:\Test.TXT


Append True :

)Dim textFile As New StreamWriter("C:\Test.TXT", 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

PDF created with pdfFactory Pro trial version

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

)( Write )( WriteLine )( Write


String )( WriteLine

String NewLine :

)"Dim textFile As New StreamWriter("C:\test.TXT

)" "(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

PDF created with pdfFactory Pro trial version

:
311

.StreamReader StreamWriter
:
)"Dim textFile As New StreamWriter("C:\Test.TXT

)( ReadLine :String

)"Dim textFile As New StreamReader("C:\test.TXT

) )(ArabicConsole.WriteLine( textFile.ReadLine

)(textFile.Close

)( ReadToEnd

)"Dim textFile As New StreamReader("C:\test.TXT

)ArabicConsole.WriteLine(textFile.ReadLineToEnd

)(textFile.Close

)( Read Overloads
MSDN .

StreamWriter StreamReader

) (FileStream BaseStream Length


:

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

312
.NET Framework :

Dim textFile As New StreamReader("C:\test.TXT")

ArabicConsole.WriteLine( textFile.BaseStream.Length )

textFile.Close()

BinaryWriter Binary Files

.BinaryReader
: FileStream

Dim st As FileStream = File.Open("C:\test.dat", FileMode.Create)


Dim binaryFile As New BinaryWriter(st)

Write()

:( ... Double Integer Char String )

Dim st As FileStream = File.Open("C:\test.dat", _


FileMode.OpenOrCreate)
Dim binaryFile As New BinaryWriter(st)
' Integer
binaryFile.Write(10)
' Double
binaryFile.Write(200.5)
' Boolean
binaryFile.Write(True)

binaryFile.Close()

BinaryReader

: ReadXXX()

Dim st As FileStream = File.Open("C:\test.dat", FileMode.OpenOrCreate)


Dim binaryFile As New BinaryReader(st)
' Integer
ArabicConsole.WriteLine(binaryFile.ReadInt32())
' Double
ArabicConsole.WriteLine(binaryFile.ReadDouble())
' Boolean
ArabicConsole.WriteLine(binaryFile.ReadBoolean())

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

:
313

)( ReadXXX
.

Strings

)( Write
:

_ Dim st As FileStream = File.Open("C:\test.dat",


)FileMode.OpenOrCreate
)Dim binaryFile As New BinaryWriter(st
)" "(binaryFile.Write
)" "(binaryFile.Write
)" "(binaryFile.Write


)( ReadString

_ Dim st As FileStream = File.Open("C:\test.dat",


)FileMode.OpenOrCreate
)Dim binaryFile As New BinaryReader(st
' ))(ArabicConsole.WriteLine(binaryFile.ReadString
' ))(ArabicConsole.WriteLine(binaryFile.ReadString
' ))(ArabicConsole.WriteLine(binaryFile.ReadString


)( Seek

.Position

Char Array

)( Write )( ReadChars

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

314
: .NET Framework


Prefixed-length Strings
.Fixed-length Strings
.NET
.Documentation

Custom Streams
)... BinaryReader StreamWriter StreamReader(

) Double Boolean String Integer(


Person:

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

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
317

Dim X As String = "C:\Test\File.EXE"


' C:\Test
ArabicConsole.WriteLine(Path.GetDirectoryName(X))
' File.EXE
ArabicConsole.WriteLine(Path.GetFileName(X))
' .EXE
ArabicConsole.WriteLine(Path.GetExtension(X))
' C:\
ArabicConsole.WriteLine(Path.GetPathRoot(X))
' True
ArabicConsole.WriteLine(Path.HasExtension(X))
' File
ArabicConsole.WriteLine(Path.GetFileNameWithoutExtension(X))

FileInfo DirectoryInfo

FileInfo DirectoryInfo
:

'
Dim folder As New DirectoryInfo("C:\Windows")
'
Dim file As New FileInfo("C:\Autoexec.bat")

FileSystemInfo

Attributes Exists Extension FullName Name :

:Delete() Refresh() LastAccessTime LastWriteTime CreationTime

' Windows
ArabicConsole.WriteLine(folder.Name)
' Autoexec.bat
ArabicConsole.WriteLine(file.Name)
' C:\Windows
ArabicConsole.WriteLine(folder.FullName)
' C:\Autoexec.bat
ArabicConsole.WriteLine(file.FullName)

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

318
: .NET Framework

DirectoryInfo

Parent )( Create
. )( GetDirectories

) (DirectoryInfo
:

)"Dim folder As New DirectoryInfo("C:\Windows


Dim subfolder As DirectoryInfo
For Each subfolder In folder.GetDirectories
)ArabicConsole.WriteLine(subfolder.Name
Next

FileInfo
Length

.
)() GetFiles (DirectoryInfo :FileInfo

)"Dim folder As New DirectoryInfo("C:\Windows


Dim subfile As FileInfo
)"For Each subfile In folder.GetFiles("*.EXE
)ArabicConsole.WriteLine(subfile.Name
Next



subfolder .subfile

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
319


Streams
Streams

Object Serialization .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

322
: .NET Framework



.NET

Attributes
.

.Object Instance

Turki As New Person


Ali As New Person
X As Person

Turki

Dim
Dim
Dim

= X

Two object instances

Turki X Both Turki and X pointers point to

) the same object instance


( ) .(1- 9

:1- 9 .Person

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

323 : Object Serialization

Serialization Object Instance


) Stream

...(

.Deserializing

Scope
.

.NET Framework


Web Services
.ASP.NET

Custom Exceptions Serializable


.

)
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

PDF created with pdfFactory Pro trial version

324
: .NET Framework

.
BinaryFormatter )( Serialize

) Stream FileStream
( :

}"" "," ","{ = )(Dim data As String


)Dim st As FileStream = File.Open("C:\test.dat", FileMode.OpenOrCreate
)(Dim SerialObj As New BinaryFormatter
'
)SerialObj.Serialize(st, data

' Stream
)(st.Close

BinaryFormatter

)( Deserialize

Stream ) Object
CType :(Option Strict On

)(Dim data As String


)Dim st As FileStream = File.Open("C:\test.dat", FileMode.OpenOrCreate
)(Dim SerialObj As New BinaryFormatter
' Deserializing
))(data = CType(SerialObj.Deserialize(st), String
'
'
'

))ArabicConsole.WriteLine(data(0
))ArabicConsole.WriteLine(data(1
))ArabicConsole.WriteLine(data(2
)(st.Close

Object Instance

data )( Serialize

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

325 : Object Serialization

data
)( Deserialize ) .(2- 9

:2- 9/ .

Class End Class .

) (

Serializable

Attribute :

_ >)(<Serializable
Class Person

End Class

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

326
.NET Framework :

(Private )

Static Variables
:Class End Class
<Serializable()> _
Class Person
Public Name As String

' Public

Private m_Age As Integer ' Private


Property Age() As Integer
Get
Return m_Age
End Get
Set(ByVal Value As Integer)
m_Age = Value
End Set
End Property
Function GetValue() As Integer
Static x As Integer
' Static
x += 1
Return x
End Function
End Class

GetValue()

Dim st As FileStream = File.Open("C:\test.dat", FileMode.OpenOrCreate)


Dim SerialObj As New BinaryFormatter()
Dim Turki As New Person()
Turki.Name = ""
Turki.Age = 99
Turki.GetValue()
Turki.GetValue()
Turki.GetValue()
SerialObj.Serialize(st, Turki)
st.Close()

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

327 : Object Serialization


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

PDF created with pdfFactory Pro trial version

328
: .NET Framework

Object Graph
Object

Hierarchies Containment -

-OOP Has a
.NET Framework Object

Object Graph Relationships

References Object Hierarchy


:

_ >)(<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

PDF created with pdfFactory Pro trial version

329 : Object Serialization

:3- 9 .

Object Graph
Reference Type Value Type
.Has a

Object Graph
:

)Dim st As FileStream = File.Open("C:\test.dat", FileMode.OpenOrCreate


)(Dim SerialObj As New BinaryFormatter
)(Dim Turki As New Person
'
" " = Turki.Name
"Turki.Car.Name = "BMW
"Turki.Car.Model = "Class 7
"Turki.Car.Engine.Cylinder = "12 V
"Turki.Car.Engine.Volume = "999 xm
'
)SerialObj.Serialize(st, Turki

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

331 : Object Serialization

Brother
Abbas Burey .


.NET Abbas Burey

)st As FileStream = File.Open("C:\test.dat", FileMode.OpenOrCreate


)(SerialObj As New BinaryFormatter
)(Abbas As New Person
)(Burey As New Person

Dim
Dim
Dim
Dim

"" = Abbas.Name
"" = Burey.Name
Abbas.Brother = Burey
Burey.Brother = Abbas
'
)SerialObj.Serialize(st, Abbas

Dim Test As Person


)st.Seek(0, SeekOrigin.Begin
)Test = CType(SerialObj.Deserialize(st), Person
)ArabicConsole.WriteLine(Test.Name
'
)ArabicConsole.WriteLine(Test.Brother.Name
'
)(st.Close


ICloneable

)( MemberwiseClone .Object

) (
:

Class Car
Public Name As String
Public Model As String
End Class

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

332
: .NET Framework

Class Person
Implements ICloneable

Public Name As String


)(Public Car As New Car
Private Function PrivateClone() As Object Implements
ICloneable.Clone
)(Return Me.Clone
End Function
Public Function Clone() As Person
)Return CType(Me.MemberwiseClone(), Person
End Function
End Class

:
)(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

ArabicConsole.WriteLine(Turki.Car Is Turki2.Car) ' True

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

333 : Object Serialization

:4- 9 Car.
.NET Shallow Copying

Object Graph .

.Deep Copying
)( Clone Person ) Serializable

Attributes Person :(Car

_ >)(<Serializable
Class Car

End Class
_ >)(<Serializable
Class Person
Implements ICloneable

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

334
.NET Framework :

Public Function Clone() As Person


Dim st As FileStream = File.Open("C:\temp.tmp", _
FileMode.OpenOrCreate)
Dim SerialObj As New BinaryFormatter()
SerialObj.Serialize(st, Me)
st.Seek(0, SeekOrigin.Begin)
Return CType(SerialObj.Deserialize(st), Person)
st.Close()
File.Delete("C:\temp.tmp")
End Function
End Class

:
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

ArabicConsole.WriteLine(Turki.Car Is Turki2.Car) ' False

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

335 : Object Serialization

:5- 9 .Deep Copying

)( Serialize BinaryFormatter
Stream
. )( Clone
Person FileStream
MemoryStream .

Custom Serialization

Serializable Attributes
NonSerialized Attributes
.

Custom Serializations .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

336
: .NET Framework

ISerializable
ISerializable

)( GetObjectData:

_ Sub GetObjectData(ByVal info As SerializationInfo,


)ByVal context As StreamingContext

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

)(Public Sub New


End Sub

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

Object Serialization : 337


TestClass
Integer ) Integer

ISerializable (

Private Sub GetObjectData()

: New()

<Serializable()> _
Class TestClass
Implements ISerializable
Public
Public
Public
Public

X
Y
Z
W

As
As
As
As

Integer
Integer
Integer
Integer

Public Sub New()


'
'
'
End Sub
'
' Deserialization
Private Sub New(ByVal info As SerializationInfo, _
ByVal context As StreamingContext)
On Error Resume Next
Me.X = info.GetInt32("X")
Me.Y = info.GetInt32("Y")
Me.Z = info.GetInt32("Z")
Me.W = info.GetInt32("W")
End Sub
'
Public Sub GetObjectData(ByVal info As SerializationInfo, _
ByVal context As StreamingContext) Implements _
ISerializable.GetObjectData
If Me.X >= 0 Then
info.AddValue("X", Me.X)
End If
If Me.Y >= 0 Then
info.AddValue("Y", Me.Y)
End If

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

338
.NET Framework :

If Me.Z >= 0 Then


info.AddValue("Z", Me.Z)
End If
If Me.W >= 0 Then
info.AddValue("W", Me.W)
End If
End Sub
End Class

) /
:(

Dim st As FileStream = File.Open("C:\test.dat", FileMode.OpenOrCreate)


Dim SerialObj As New BinaryFormatter()
Dim TestObject As New TestClass()
TestObject.X
TestObject.Y
TestObject.Z
TestObject.W

=
=
=
=

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 :

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

339 : Object Serialization

XML '
Public Class Person

End Class
'
Class Car

End Class

: Public :
'
'
'

Public Class Test


Public X As Integer
Friend Y As Integer
Private Z As Integer

End Class

Object Graph

Circular Reference

.Binary

XML

XML

Web Services

. .XML


:
Imports System.Xml.Serialization

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

340
: .NET Framework

XmlSerializer
XML

Serializable Attribute :Public

Public Class Person


Public Name As String
Public Age As Integer
End Class

XML ) XmlSerializer

(System.XML.Serialization

BinaryFormatter :

)Dim st As FileStream = File.Open("C:\test.xml", FileMode.OpenOrCreate


))Dim SerialObj As New XmlSerializer(GetType(Person
)(Dim Turki As New Person
" " = Turki.Name
Turki.Age = 99
)SerialObj.Serialize(st, Turki
)(st.Close

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

PDF created with pdfFactory Pro trial version

Object Serialization : 341

- BinaryFormatter

XmlSerializer Deserialize() -XML


:

Dim st As FileStream = File.Open("C:\test.xml", FileMode.OpenOrCreate)


Dim SerialObj As New XmlSerializer(GetType(Person))
st.Seek(0, SeekOrigin.Begin)
Dim Test As Person = CType(SerialObj.Deserialize(st), Person)
ArabicConsole.WriteLine(Test.Name)
ArabicConsole.WriteLine(Test.Age)

'
' 99

st.Close()


Attributes .NET
: .XML
:XmlRoot Attributes

Root XML XmlRoot Attributes


. Namespace XML Document Element

<XmlRoot("PersonRecord", namespace:="http://www.dev4arabs.com")> _
Public Class Person
Public Name As String
Public Age As Integer
End Class


:Person PersonRecord

<?xml version="1.0" ?>


<PersonRecord xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.dev4arabs.com">
<Name>< /Name>
<Age>99</Age>
</PersonRecord>

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

342
.NET Framework :

:XmlElement Attributes
XML Tags XML
.

:XmlElement Attributes XML

Public Class Person


<XmlElement("FullName")> Public Name As String
Public Age As Integer
End Class

Name

: FullName

<?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>

:XmlAttributeAttribute Attributes
XmlAttributeAttribute Attributes
: ID Element XML Documents

Public Class Person

<XmlAttributeAttribute("PersonID")> Public ID As String

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>

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

Object Serialization : 343

:XmlText Attributes
XML XmlText Attributes

:Tags

Public Class Person

<XmlText()> Public Note As String

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>

:XmlArray and XmlArrayItem Attributes


XmlArray and XmlArrayItem Attributes
( )

XML Elemetent XmlArray Attributes


: Customer .

Public Class Order


<XmlAttributeAttribute("OrderId")> Public OrderID As String
Public [Date] As Date
Public Total As Decimal
End Class
Public Class Customer
Public Name As String
Public Address As String
<XmlArray("CustomerOrders"), XmlArrayItem("CustOrder")> _
Public Orders(3) As Order
End Class

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

344
.NET Framework :

Customer
) XML
XmlArray and XmlArrayItem Attributes Bold
:(

<?xml version="1.0" ?>


<Customer xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>< /Name>
<Address>< /Address>
<CustomerOrders>
<CustOrder OrderId="1">
<Date>2002-12-12T02:09:48.9743296+03:00</Date>
<Total>100</Total>
</CustOrder>
<CustOrder OrderId="2">
<Date>2002-12-10T00:00:00.0000000+03:00</Date>
<Total>200</Total>
</CustOrder>
<CustOrder OrderId="3">
<Date>2002-12-09T00:00:00.0000000+03:00</Date>
<Total>300</Total>
</CustOrder>
<CustOrder xsi:nil="true" />
</CustomerOrders>
</Customer>

:XmlIgnore Attributes

XmlIgnore Attributes

: MotherName .

Public Class Person

<XmlIgnore()> Public MotherName As String

End Class

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

345 : Object Serialization


XmlSerializer
.XML
- - XML

.
.

UnknownElement

XML

.
.

XML

. Person:

Public Class Person


Public Name As String
Public Age As Integer
End Class

XML

>? "<?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

Name FirstName :LastName

>? "<?xml version="1.0


"<Person xmlns:xsd="http://www.w3.org/2001/XMLSchema
>"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
></FirstName><FirstName
></LastName><LastName

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

346
.NET Framework :

<Age>99</Age>
</Person>

Age

XML . Name
UnknowXMLElemntEvent

Sub UnknowXMLElemntEvent(ByVal sender As Object, _


ByVal e As XmlElementEventArgs)
Dim tmpObj As Person = CType(e.ObjectBeingDeserialized, Person)
If e.Element.Name = "FirstName" Then
tmpObj.Name = e.Element.InnerXml
ElseIf e.Element.Name = "LastName" Then
tmpObj.Name = tmpObj.Name & " " & e.Element.InnerXml
End If
End Sub


e.ObjectBeingDeserialized


XML





e.Element.Name

FirstName . e.Element.InnerXml

.Name LastName
WithEvents UnknownElement

: AddHandler

Dim st As FileStream = File.Open("C:\test.xml", _


FileMode.OpenOrCreate)
Dim SerialObj As New XmlSerializer(GetType(Person))
st.Seek(0, SeekOrigin.Begin)
'
AddHandler SerialObj.UnknownElement, AddressOf UnknowXMLElemntEvent
'
Dim Test As Person = CType(SerialObj.Deserialize(st), Person)
ArabicConsole.WriteLine(Test.Name)
ArabicConsole.WriteLine(Test.Age)
st.Close()

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

'
' 99

347 : Object Serialization

Object
Serialization

.Visual Basic .NET


MSDN .

-
.Threading

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

350
: .NET Framework


.
(1 (2 (3

.Three Threads
.

- .

Server


Client

.
.

.
!

: Free Threading

.Apartment Threading

Global Variable

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

: Threading
353

:
.

.NET Framework Thread


Delegate ) AddressOf

(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

PDF created with pdfFactory Pro trial version

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 :

)Dim newThread As New Thread(AddressOf DoSomething

'
)(newThread.Start

'
)(newThread.Suspend

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Threading
355

) ( '
)(newThread.Resume

'
)(newThread.Abort

)( Sleep ) (

0.001:

' )Thread.CurrentThread.Sleep(500

)( Join

)Dim newThread As New Thread(AddressOf DoSomething

'
)(newThread.Start
'

)( newThread.Join
'
'

IsAlive - )(:Join

)Dim newThread As New Thread(AddressOf DoSomething

'
)(newThread.Start

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

356
: .NET Framework

'

Do While newThread.IsAlive() = True


Loop
'
'

IsAlive :
If Thread.CurrentThread.IsAlive Then
True .

Name String


Debugging Debug location

) :(1- 10

" " = Thread.CurrentThread.Name


" " = newThread.Name

:1- 10 .Debug Location

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Threading
357

ThreadState

If newThread.ThreadState = ThreadState.Unstarted Then

ThreadState.Aborted

ThreadState.AbortRequested

ThreadState.BackGround

BackGround

ThreadState.Running

.Thread

ThreadState.Suspended
ThreadState.SuspendedRequested

.
.

ThreadState.UnStarted

Join

ThreadState.WaitSleepJoin

:Priority

Windows Multitasking


. ) Windows

Windows ME ( Processing Time

Processes

. 10

- )

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

358
: .NET Framework

(
) Active Process (.

Windows

Priority Windows NT
.

Windows

Programs

Processing

Scheduling Performance Option

) Control Panel -> System -> Advanced -> Performance -> Settings - 10
.(2

:2- 10 .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Threading
359

- BelowNormal Low :

High AboveNormal Normal .Realtime

Windows Task Manager


]) [Alt]+[Ctrl]+[Del 3 - 10 (.

Threads

Process
Priority

ThreadPriority.BelowNormal :

ThreadPriority.AboveNormal ThreadPriority.Normal ThreadPriority.Lowest

.ThreadPriority.Highest

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

Threading :
361

Sub DoSomething()
Dim counter As Integer
For counter = 1 To 100
Next
Console.WriteLine("THREAD B HAS FINISHED")
End Sub


100
:

THREAD B HAS FINISHED


THREAD A HAS FINISHED

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

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

362
: .NET Framework

) 200 (
ThreadPriority.Highest
ThreadPriority.Lowest :

THREAD A HAS FINISHED


THREAD B HAS FINISHED


Pentium 800 MHz
.

:IsBackground


Background Threads
.

Background Thread

) IsBackground (:

)Dim newThread As New Thread(AddressOf DoSomething

newThread.IsBackground = True

If newThread.IsBackground Then
)(newThread.Abort
End If

. )
(:

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

: 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

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

: 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

PDF created with pdfFactory Pro trial version

368
: .NET Framework

) ( )( .


Thread Free Threading

' Public X As Integer


)(Sub Main
Dim counter As Long
)Dim newThread As New Thread(AddressOf DoSomething
)(newThread.Start
For counter = 1 To 1000
X += 1
Next
)(newThread.Join
Console.WriteLine("X = " & X) ' 2000
End Sub
)(Sub DoSomething
Dim counter As Integer
For counter = 1 To 1000
X += 1
Next
End Sub


.... . Synchronization
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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 .

DoSomething counter :Static

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

Threading :
371

Console.WriteLine(X) ' 200


Console.WriteLine(Y) ' 100
End Sub
Sub DoSomething()
X = 200
Y = 200
End Sub
End Module

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

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

372
: .NET Framework

TLS
Thread Local

(TLS) Storage

. TLS Data
) Slot .(10- 4

:10- 4 .Data Slots


.NET Framework Data

Slots : Named data slots

.Unnamed data slots

Named data slots

String
.

)(:AllocateNamedDataSlot

'
)"Thread.AllocateNamedDataSlot("Name

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Threading
373

LocalDataStoreSlot
:

Dim namedDataSlot As LocalDataStoreSlot


)"namedDataSlot = Thread.AllocateNamedDataSlot("Name

Name
)(:SetData

)" " Thread.SetData(namedDataSlot,

)( GetData :
' ))Console.WriteLine(Thread.GetData(namedDataSlot

nameDataSlot

Name )(:GetNamedDataSlot

Dim namedDataSlot2 As LocalDataStoreSlot


)"namedDataSlot2 = Thread.GetNamedDataSlot("Name
' ))Console.WriteLine(Thread.GetData(namedDataSlot2

)(:FreeNamedDataSlot

)"Thread.FreeNamedDataSlot("Name

TLS
)( GetNamedDataSlot
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

374
: .NET Framework

Unnamed data

) slots (Allocated data store slots


String
LocalDataStoreSlot :

Dim dataSlot As LocalDataStoreSlot


)(dataSlot = Thread.AllocateDataSlot
)" " Thread.SetData(dataSlot,
' ))Console.WriteLine(Thread.GetData(dataSlot


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

PDF created with pdfFactory Pro trial version

: 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

PDF created with pdfFactory Pro trial version

376
: .NET Framework

Class ThreadData

)(Event ThreadFinish
)(Sub DoSomething

)(RaiseEvent ThreadFinish
End Sub
End Class

:
Module Module1
)(Sub Main

AddHandler One.ThreadFinish, AddressOf ThreadHasBeenFinished

End Sub
)(Sub ThreadHasBeenFinished

End Sub
End Module

)( ThreadHasBeenFinished
)

AddHandler ( .
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Threading
377

Thread Synchronization

.

SyncLock End SyncLock



- :

If X = 10 Then
X = 0
Else
X = 10
End If

SyncLock End SyncLock

SyncLock End SyncLock

Reference Type Nothing


:

SyncLock y
If X = 10 Then
X = 0
Else
X = 10
End If
End SyncLock

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

: 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

Visual Basic .NET


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

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

: 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
(.

SyncLock End SyncLock Synchronization


MethodImpl

Mutex Interlocked Monitor :


ManualResetEvent ReaderWriterLock .AutoResetEvent

.NET Documentation
Monitor
SyncLock End SyncLock .

SyncLock End SyncLock

-
. Monitor
SyncLock End SyncLock .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

382
: .NET Framework

Monitor

Shared Methods )( Enter


)( Exit

Global Variables Reference Nothing


-SyncLock End SyncLock :

"Public X As String = "Lock1

SyncLock X

'

End SyncLock

Monitor :
"Public X As String = "Lock1

)Monitor.Enter(X

'

)Monitor.Exit(X

Monitor :
"Public X As String = "Lock1

)If Y = 0 Then Monitor.Enter(X

'

)Monitor.Exit(X

)( Exit )( Enter
.
:
)If Y = 0 Then Monitor.Exit (X

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Threading
383

)( Enter )( Exit



)(:TryEnter

"Public X As String = "Lock1

'
'
)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

PDF created with pdfFactory Pro trial version

384
: .NET Framework

)ThreadPool.QueueUserWorkItem(AddressOf DoSomething, 100

)Sub DoSomething(ByVal x As Object

Console.WriteLine (X) ' 100


End Sub

)( 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
.

Apartment Threading Free Threading

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

Global Reference Variables

: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

PDF created with pdfFactory Pro trial version

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

Background Thread ) False

(IsBackground )( .Abort
Thread

Timers

.NET Framework Timers:


Threading.Timer Timers.Timer Windows.Forms.Time

.System
.Controls

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

Elapsed AutoReset False

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

PDF created with pdfFactory Pro trial version

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

) Dim MyTimer As New Threading.Timer(AddressOf DoSomething,


)Sub DoSomething(ByVal x As 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

PDF created with pdfFactory Pro trial version

: 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

PDF created with pdfFactory Pro trial version

390
: .NET Framework

Threading
Multi-

Threading

.NET Framework .Assemblies

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

11

Assemblies
Windows Class Libraries


.Assembly

.NET .
.Managed Modules

Managed Modules
) Visual Basic .NET .NET(

Managed Module EXE

) DLL "" EXE (


.
.Assembly

.
:
(1

:Windows PE File Header

Windows Microsoft

.Windows
(2

:.NET Framework File Header

.NET Framework

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

392
: .NET Framework


Metadata...

(3

:Metadata

) Classes Modules

Structure Enum ... Interfaces( . .NET


Reflection

Classes .
(4

:MSIL Visual Basic

.NET JIT
Assembly Microsoft

MSIL) Intermediate Language .(IL MSIL


.

Windows CRL .NET

Metadata
Reflection Classes
Visual Basic .NET -

Assemblies
Assembly .NET

... . EXE DLL


)... BMP HTML DOC DLL EXE(.

-
. Nonexecutable

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Assemblies
393

Resource Files HTML Texts

... Pictures.

.NET

) .(1- 11

:1- 11

EXE
Visual Studio .NET

] .[F5
AL.EXE .

- EXE DLL

- .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

394
: .NET Framework


) ( -

-.NET : Library Windows


Application .Console Application

Libraries DLL

Reference

.NET.

Windows Application Console Application

.Entry Point )
)( Sub Main (Visual Basic .NET
.

Windows Application Console Application

Console
.

Output Type Project

) Property Pages .(2- 11

:2- 11 .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Assemblies
395


Private Assemblies

.Shared Assemblies

.
. :

C:\Folder\AAA.DLL
C:\BBB.EXE
C:\Folder\CCC.EXE
C:\Folder\SubFolder\DDD.EXE

AAA.DLL BBB.EXE CCC.EXE


.
> <probing BBB.EXE

) Probing MSDN
.


Add References Visual Studio .NET
- .

-
!

.NET

X:\Windows\assembly

.(GAC) Global Assembly Cache


Windows Explorer

) X:\Windows\assembly 3- 11 (.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

396
: .NET Framework

:3- 11 .GAC
Windows Explorer

Command DOS Prompt

Delete GAC
GACUTIL.EXE .


GAC Administrator
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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

Strong Name SN.EXE

Assembly

Assembly
... :

Imports System.Reflection
Imports System.Runtime.InteropServices

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

398
: .NET Framework

>)" "(AssemblyTitle
"(AssemblyDescription
>)" "(AssemblyCompany
>)" "(AssemblyCopyright
>)"AssemblyVersion("1.0.2321432

<Assembly:
<Assembly:
>)"
<Assembly:
<Assembly:
<Assembly:

*
:
>)"*<Assembly: AssemblyVersion("1.0.

Visual Studio .NET

AssemblyInfo.vb .

Configuration Files

.Configuration Files
XML Notepad
.

Windows ) 3.x (

*.ini .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Assemblies
399


.NET
.NET : Application Configuration File

Publisher Configuration File Machine Configuration

.File :

:Application Configuration File

.config .
:

C:\MyProg\application.exe

:
C:\MyProg\application.exe.config

:Publisher Configuration File

Shared Assemblies

.
- ) (

- .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

400
: .NET Framework

:Machine Configuration File


) Administrator Configuration

(File .NET .NET


Framework . machine.config

\) C:\WINDOWS\Microsoft.NET\Framework\vxxx\CONFIG xxx

.NET Framework (
:

C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\CONFIG\machine.config

> <configuration :XML


>?"<?xml version="1.0" encoding="UTF-8
><configuration

></configuration

> <configuration .

Application configuration files


machine.config .

machine.config
.


.NET
:Documantation

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Assemblies
401

>:<requiredRuntime
.NET Framework

> <requiredRuntime > <startup


:

>?"<?xml version="1.0" encoding="UTF-8


><configuration
><startup
><requiredRuntime version="v1.0.3705" /
></startup
></configuration

XML ) case-
.sensitive .

> <requiredRuntime

) (

Windows Registry


safemode
True




>:<requiredRuntime

>?"<?xml version="1.0" encoding="UTF-8


><configuration
><startup
><requiredRuntime version="v1.0.3705" safemode="true" /
></startup
></configuration

>:<gcConcurrent

Garbage Collection

. MSDN

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

402
: .NET Framework

Servers . > <gcConcurrent


> <runtime False enabled
Garbage Collection:

>?"<?xml version="1.0" encoding="UTF-8


><configuration
><runtime
><gcConcurrent enabled="false"/
></runtime
></configuration


Garbage Collection
.

>:<add

> <appSettings )
... (

> <add > <appSettings :

>?"<?xml version="1.0" encoding="UTF-8


><configuration
><appSettings
><add key="Site" value="www.dev4arabs.com" /
><add key="DBPath" value="C:\Folder\Data.MDB" /
><add key="Show Startup Window" value="False" /
></appSettings
></configuration


System.Configuration.ConfigurationSettings.AppSettings

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

.NET Framework Configuration


.NET

Microsoft (4- 11 )Framework Configuration


Administrative Tools .NET Framework Configuration

PDF created with pdfFactory Pro trial version

.Control Panel

..NET Framework Configuration :4- 11

w w.pdf actory.com

404
: .NET Framework

.NET Framework Configuration


Windows .Microsoft Management Console snap-in
Windows Windows NT
Windows XP 2000 .

> <gcConcurrent

Garbage Collection

machine.config My Computer

Properties ) My Computer Properties


.(4- 11

:4- 11 .Garbage Collection

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Assemblies
405

Application

.
.Configured Assemblies

) Visual Studio .NET

(
.Command Prompt

Command

Prompt Visual Studio .NET


.NET .

Command Prompt corvars.bat

X:\Program Files\Microsoft Visual Studio

(.NET\FrameworkSDK\Bin Paths

Visual Studio .NET Command Prompt


Microsoft Visual Studio .NET ) Start .(6- 11

:6- 11 .Visual Studio .NET Command Prompt

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

406
: .NET Framework

Microsoft
Visual Studio .NET
Visual Programming !

.NET Documentation
.

VBC.EXE

VBC.EXE Visual Basic Compiler


.IL ) (

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

PDF created with pdfFactory Pro trial version

: Assemblies
407

:
C:\>vbc test.vb test2.vb test3.vb

test.exe
) /out * (:

C:\>vbc /out:myprog *.vb

myprog.exe

Console

.Application Windows Application

Library ) /target :(/t

) ( winprog.exe
C:\>vbc winprog.vb /target:winexe
) ( mylib.exe
C:\>vbc mylib.vb /t:library

VBC.EXE

Single File Assembly


AL.EXE module :/target

C:\>vbc test.vb /target:module

test.netmodule )
(
:/addmodule

C:\Test>vbc test.vb /target:module /addmodule:other.netmodule


.AL.EXE

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

408
: .NET Framework

AL.EXE
AL.EXE Assembly Linker
.Multiple File Assemblies

.NET .

AL.EXE

C:\>al file1.netmodule file2.netmodule /out:myass.dll

file1.netmodule

file2.netmodule ) myass.dll .(7- 11


- file1.netmodule file2.netmodule

.myass.dll

:7- 11 .

.NET Documentation
myass.dll
.Assembly's Manifest

Library

Console Application Windows Application /t:exe


/t:win :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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

PDF created with pdfFactory Pro trial version

410
: .NET Framework

)( Sub Main )( Sub2

Visual Basic .NET


)( Sub3 :C#
// file3.cs
namespace file3
{
class clsfile3
{
)(static public void Sub3
{
;)(file4.clsfile4.Sub4
}
}
}
// file4.cs
namespace file4
{
class clsfile4
{
)(static public void Sub4
{
;)"System.Console.WriteLine ("C# code works.
;)(System.Console.Read
}
}
}

C# ) .cs (C Sharp
.CSC.EXE

C:\Test (CSC.EXE) C#

file3.cs file4.csc /target:module

C:\Test>csc /target:module *.cs

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Assemblies
411

.file3.netmodule file.vb

file2.vb VBC.EXE
/addmodule file2.vb

)( Sub3 :

C:\Test>vbc /target:module *.vb /addmodule:file3.netmodule

AL.EXE
(/t:exe) Console Application )(Main

) (/main:MainModule.Main ):(/out:myprog.exe
/t:exe /out:myprog.exe

C:\test>al file.netmodule file3.netmodule


/main:MainModule.Main

MS-DOS :

C:\test>myprog
VB code works.
C# code works.
_ >C:\test

) (8- 11 .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

412
: .NET Framework

:8- 11 file3.netmodule File.netmodule .myprog.exe

SN.EXE

SN.EXE Strong Names


Partial key ) :(k
C:\>sn k mykey.snk

) Public Key

Private Key (.

VBC.EXE AL.EXE

/keyfile :

C:\>vbc /out:myprog *.vb /keyfile:mykey.snk

Visual Studio .NET

:AssemblyInfo.vb

)"<Assembly: AssemblyKeyFile("mykey.snk

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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

C:\>gacutil u mylib, ver=1.2.3432432

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

414
: .NET Framework


MSDN

Reflection Classes
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

12

Reflection
Classes
Reflection Classes
System.Reflection Assemblies

Managed Modules Classes and Objects Interfaces


Structures Enums )

(.

" ".

IntelliSense Visual
Studio .NET .


System.Reflection
:
Imports System.Reflection


Assembly : .Module

.NET

Documentation .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

416
: .NET Framework

Assembly
Assembly - .

New
)(:GetExecutingAssembly

]Dim ass As [Assembly


)(ass = [Assembly].GetExecutingAssembly

)(:LoadFrom
]Dim ass As [Assembly
)"ass = [Assembly].LoadFrom("C:\myLib.dll

.MSDN

Assembly keyword Visual


Basic .NET ] [
:
]Dim ass As [Assembly

) (Public Key

FullName
GAC GlobalAssemblyCache Location

]Dim ass As [Assembly


ass = [Assembly].GetExecutingAssembly
)ArabicConsole.WriteLine(ass.FullName
)ArabicConsole.WriteLine(ass.GlobalAssemblyCache
' False
)ArabicConsole.WriteLine(ass.Location
' C:\test.dll

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Reflection Classes
417

EntryPoint

Refelection.MethodInfo :

]Dim ass As [Assembly


Dim mthd As MethodInfo
ass = [Assembly].GetExecutingAssembly
mthd = ass.EntryPoint
ArabicConsole.WriteLine(mthd.Name) ' main

EntryPoint Nothing

Library .

Assemblies
Entry Point MethodInfo
.

)( GetTypes Type

) ... ( :

]Dim ass As [Assembly


Dim t As Type
)"ass = [Assembly].LoadFrom("C:\myLib.dll
)(For Each t In ass.GetTypes
)ArabicConsole.WriteLine(t.Name
Next

)( GetTypes )

Friend (Private

)( GetExportedTypes Public

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

418
: .NET Framework

]Dim ass As [Assembly


Dim t As Type
)"ass = [Assembly].LoadFrom("C:\myLib.dll
)(For Each t In ass.GetExportedTypes
)ArabicConsole.WriteLine(t.Name
Next

Late Binding

)( CreateInstance
:

]Dim ass As [Assembly


)"ass = [Assembly].LoadFrom("C:\test\test.dll
)"Dim obj As Object = ass.CreateInstance("LibNamespace.PublicClass
'
' )ArabicConsole.WriteLine(obj.GetType.FullName
LibNamespace.PublicClass

Module

Module Managed Modules

)( GetModule Assembly

)( GetModules :

]Dim ass As [Assembly


)"ass = [Assembly].LoadFrom("C:\test\test.dll
]Dim mdl As [Module
For Each mdl In ass.GetModules
)ArabicConsole.WriteLine(mdl.Name
Next

Assembly Module )(GetTypes

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Reflection Classes
419



.
System.Type .

System.Type

- System. Reflection
Type .System System.Type

Primitive

) Type ... Boolean String Long Integer( Class


Strucuter Enum .Interface

New

Type - )( GetTypes

Assembly:

]Dim ass As [Assembly


Dim t As Type
)"ass = [Assembly].LoadFrom("C:\myLib.dll
)(For Each t In ass.GetTypes
)ArabicConsole.WriteLine(t.Name
Next

)( GetType Visual
:Basic .NET

Dim t As Type
)t = GetType(Integer
ArabicConsole.WriteLine(t.FullName) ' System.Int32

) System.Object .NET Framework(

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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-

Sensetive ) .NET Framework Int32

.... DateTime Int64( Visual Basic .NET

) ... Date Long Integer(.

)( GetType )( GetTypeArray

}", 100, 3.5"{ = Dim X() As Object


)Dim t() As Type = Type.GetTypeArray(X

ArabicConsole.WriteLine(t(0).FullName) ' System.String


ArabicConsole.WriteLine(t(1).FullName) ' System.Int32
ArabicConsole.WriteLine(t(2).FullName) ' System.Double

:COM

COM

Type COM
)( GetTypeFromProgID ) ProgID
COM (:

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Reflection Classes
421

' Microsoft Word


)"Dim word As Type = Type.GetTypeFromProgID("Word.Application
ArabicConsole.WriteLine(word.FullName) ' System.__ComObject


Type Name

FullName

Module Managed Module


Assembly :
)Dim t As Type = GetType(String
' String
' System.String
' CommonLanguageRuntimeLibrary

)ArabicConsole.WriteLine(t.Name
)ArabicConsole.WriteLine(t.FullName
)ArabicConsole.WriteLine(t.Module

BooleanIsInterface IsClass :

IsValueType IsEnum Class

Interface Enum Value Type


Structure :

)Dim t As Type = GetType(TestClass


' True
' False

)ArabicConsole.WriteLine(t.IsClass
)ArabicConsole.WriteLine(t.IsValueType

IsPublic True Public


IsNestedPrivate True Private

IsNestedAssembly True Friend

IsNestedFamily True Protected


IsNestedFamORAssem True Protected

.Friend

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

422
: .NET Framework

NotInheritable IsSealed True


IsAbstract True .MustInherit

MSDN .



) (
. ) (

MSDN .

MemberInfo
MemberInfo Member ) (
PropertyInfo FieldInfo :

EventInfo ) MethodInfo .(1- 12

:1- 12 MemberInfo

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Reflection Classes
423

MemberInfo MemberInfo
New
)( GetMembers :

)Dim T As Type = GetType(Integer


Dim m As MemberInfo
For Each m In T.GetMembers
)ArabicConsole.WriteLine(m.Name
Next

:Integer
MaxValue
MinValue
ToString
GetTypeCode
ToString
CompareTo
GetHashCode
Equals
ToString
ToString
Parse
Parse
Parse
Parse
GetType

Overrides
)( GetMembers
Enum BindingFlags :

BindingFlags.Public

BindingFlags.Static Shared Members

BindingFlags.NonPublic .

BindingFlags.Instance .Instance Members

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

424
: .NET Framework

BindingFlags.DeclaredOnly
.

Instance Members

Public :

)Dim T As Type = GetType(Integer


Dim m As MemberInfo
_ For Each m In T.GetMembers(BindingFlags.Public
_ Or BindingFlags.Instance Or
)BindingFlags.DeclaredOnly
)ArabicConsole.WriteLine(m.Name
Next

:
ToString
GetTypeCode
ToString
CompareTo
GetHashCode
Equals
ToString
ToString

Overloads .
:

MemberInfo
Name

MemberType ) Field Method Property


...( Attributes Attribute .

IsPublic True Public IsPrivate

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Reflection Classes
425

True Private IsAssembly

True Friend IsFamily True

Protected IsFamilyORAssembly True


.Protected Friend

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

)Dim T As Type = GetType(Person


Dim f As FieldInfo
)(For Each f In T.GetFields
)ArabicConsole.WriteLine(f.Name
Next

:
Name
BirthDate
Salary
Address

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

426
: .NET Framework

)( GetFields BindingFlags
)(.GetMembers

:
FieldInfo IsNotSerialized False

Serializable FieldType Type

)Dim T As Type = GetType(Person


)"Dim F As FieldInfo = T.GetField("BirthDate
ArabicConsole.WriteLine(F.FieldType.ToString) ' System.DateTime

FieldInfo )( SetValue

)( GetValue

Late

.Binding

PropertyInfo Property PropertyInfo

.MemberInfo

PropertyInfo New
)( GetProperties

)Dim T As Type = GetType(String


Dim P As PropertyInfo

)(For Each P In T.GetProperties


)ArabicConsole.WriteLine(P.Name
Next

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Reflection Classes
427

:
Chars
Length

)( GetProperties BindingFlags
)(.GetMembers

PropertyInfo CanRead True

CanWrite

PropertyType Type :

)Dim T As Type = GetType(String


)"Dim P As PropertyInfo = P.GetProperty("Length
ArabicConsole.WriteLine(P.PropertyType.ToString) ' System.Int32

FieldInfo )( SetValue

)( GetValue

Late

.Binding )( GetGetMethod )( GetSetMethod


MethodInfo ) (Property Get

) (Property Set :
Property xxxx() As yyyy
Get
'
End Get
)Set(ByVal Value As yyyy
'
End Set
End Property

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

428
: .NET Framework


MethodInfo Method
.MemberInfo
MethodInfo New

)( GetMethods

)Dim T As Type = GetType(Double


Dim M As MethodInfo
For Each M In T.GetMethods
)ArabicConsole.WriteLine(M.Name
Next

:
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

PDF created with pdfFactory Pro trial version

: Reflection Classes
429

:
MethodInfo ReturnType

Type ) Function (
IsAbstract True MustOverride

IsVirtual True .Overridable

MethodInfo )( Invoke

.Late Binding

MethodInfo
PropertyInfo .


EventInfo Event EventInfo
.MemberInfo
EventInfo New

)( GetEvents
) TestClass (:

Class TestClass
)(Event XXX
)(Event YYY
)(Event ZZZ
End Class

)Dim T As Type = GetType(TestClass


Dim E As EventInfo
For Each E In T.GetEvents
)ArabicConsole.WriteLine(E.Name
Next

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

: 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

Person Double Integer String

... TestClass .

Reflection -
.

ReflectionExample

ReflectionExample :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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
:

Dim obj As New ReflectionExample()


Dim F As FieldInfo = obj.GetType.GetField("ExampleField")
obj.ExampleField = "***"
'
ArabicConsole.WriteLine(F.GetValue(obj)) ' ***

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

: Reflection Classes
433

)( SetValue

)(Dim obj As New ReflectionExample


)"Dim F As FieldInfo = obj.GetType.GetField("ExampleField
)"F.SetValue(obj, "$$$
'
)ArabicConsole.WriteLine(obj.ExampleField

)( GetProperties )(GetProperty
PropertyInfo

)( GetValue Nothing
:

)(Dim obj As New ReflectionExample


)"Dim P As PropertyInfo = obj.GetType.GetProperty("ExampleProperty
obj.ExampleProperty = 111
'
ArabicConsole.WriteLine(P.GetValue(obj, Nothing)) ' 111


ExampleProperty1 )(SetValue

) Nothing (:

)(Dim obj As New ReflectionExample


)"Dim P As PropertyInfo = obj.GetType.GetProperty("ExampleProperty
)P.SetValue(obj, 999, Nothing
'
ArabicConsole.WriteLine(obj.ExampleProperty) ' 999

MethodInfo

)( Invoke

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

434
: .NET Framework

Nothing Object

)(Dim obj As New ReflectionExample


)"Dim M As MethodInfo = obj.GetType.GetMethod("ExampleMethod
}Dim params() As Object = {-5, 5
)M.Invoke(obj, params

:
5
-5


Optional Parameters



Type.Missing

)( ExampleMethod2
:10

)(obj As New ReflectionExample


)"M As MethodInfo = obj.GetType.GetMethod("ExampleMethod2
}params() As Object = {Type.Missing
}params2() As Object = {10

Dim
Dim
Dim
Dim

)M.Invoke(obj, params
)M.Invoke(obj, params2

:
-1
10

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Reflection Classes
435


)
Late Binding .

)(Dim obj As New ReflectionExample

Reflection

.AssemblyName.TypeName )(CreateInstance
System.Activator Type :

)"Dim T As Type = Type.GetType("MyAssembly.MyClass


)Dim obj As Object = Activator.CreateInstance(T

Constructor

)( CreateInstance :Object

)"Dim T As Type = Type.GetType("MyAssembly.MyClass


}Dim params() As Object = {-5, 5
)Dim obj As Object = Activator.CreateInstance(T, params

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

PDF created with pdfFactory Pro trial version

436
: .NET Framework


StackTrace
Exception

System.Diagnostics
Reflection.

StackTrace

StackTrace New
)( GetFrame StackFrame

StackFrame )( GetMethod

) MethodBase System.Collection

(MethodInfo :Stack Trace

)(Dim ST As New StackTrace


Dim counter As Integer
For counter = 0 To ST.FrameCount - 1
)Dim SF As StackFrame = ST.GetFrame(counter
)")( " & Console.WriteLine(SF.GetMethod.Name
Next

)( 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

PDF created with pdfFactory Pro trial version

Reflection Classes :
437

For counter = 0 To ST.FrameCount - 1


Dim SF As StackFrame = ST.GetFrame(counter)
ArabicConsole.WriteLine(SF.GetMethod.Name & " ()")
Next
CalleeSub()
End Sub
Sub CalleeSub()
Dim ST As New StackTrace()
Dim counter As Integer
ArabicConsole.WriteLine("** CalleeSub *********")
For counter = 0 To ST.FrameCount - 1
Dim SF As StackFrame = ST.GetFrame(counter)
ArabicConsole.WriteLine(SF.GetMethod.Name & " ()")
Next
End Sub
End Module

Main()

** CallerSub *********
CallerSub ()
main ()
** CalleeSub *********
CalleeSub ()
CallerSub ()
main ()


String GetStack()

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

438
: .NET Framework

)(Function GetStack() As String


Dim counter As Integer
Dim stackArray() As String
)(Dim ST As New StackTrace
For counter = 1 To ST.FrameCount - 1
)Dim SF As StackFrame = ST.GetFrame(counter
)ReDim Preserve stackArray(counter
stackArray(counter - 1) = SF.GetMethod.Name
Next
Return stackArray
End Function

)( GetStack
)( GetStack .

Reflection

.NET
Framework )

Object

.(Serialization Console Application

- Windows .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version


Windows

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

13

Windows Forms
Windows

ArabicConsole
.System.Windows.Forms

Windows

.Windows Application

Windows Forms Controls


GDI+

Windows .

Console Application
:
Imports System.Windows.Forms

Windows Application
Imports Project Property
) Pages .(7-2

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

442
: Windows

Windows Forms
Visual Basic .NET
System.Windows.Forms.Form

Public Class Form1


Inherits System.Windows.Forms.Form

End Class

)( Show :
Dim myForm As New Form1
)( myForm.Show

Class End Class .


.Form Designer

Form Designer

Code Generator
) .(1- 13

Form Class
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Windows Forms
443

:1- 13 .Form Designer



.Module
Private
.

Windows Application

Visual Studio .NET .Form1

Code Editor
) (:

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

444
Windows :

Public Class Form1


Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
' .
InitializeComponent()
'
End Sub
' .
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'
Private components As System.ComponentModel.IContainer
'
'
'
<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 Region
End Class

( Base Class ) Click

.
:MsgBox Click formWasClicked

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

: Windows Forms
445

Public Class Form1


Inherits System.Windows.Forms.Form

_ Private Sub formWasClicked(ByVal sender As Object,


ByVal e As System.EventArgs) Handles MyBase.Click
)" MsgBox("Windows Form
End Sub
End Class

)
( ) :(2- 13

:2- 13 .

components

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

446
: Windows

Form1

- System.Windows.Forms.Form :

Public Class Form1


Inherits System.Windows.Forms.Form

End Class


)( InitializeComponent

Public Class Form1

)(Public Sub New


)(MyBase.New
. '
)(InitializeComponent
'
End Sub

End Class

Overloads Overrides )(Dispose

Destructor )

(:

Public Class Form1

_ Protected Overloads Overrides Sub Dispose(ByVal


)disposing As Boolean
If disposing Then
If Not (components Is Nothing) Then
)(components.Dispose
End If
End If
)MyBase.Dispose(disposing
End Sub

End Class

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Windows Forms
447

)( InitializeComponent

)
( .

Public Class Form1

'
'
'
_ >)(<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
.

) (:

Public Class Form1


Inherits System.Windows.Forms.Form
)(Public Sub New
)(MyBase.New
End Sub

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

448
: Windows

_ Protected Overloads Overrides Sub Dispose(ByVal


)disposing As Boolean
)MyBase.Dispose(disposing
End Sub
End Class

Windows Application

Startup Window Startup Object


) Project Property Pages .(3- 13

)( .Show
.

:3- 13 .

)( Application.Run
)( Run )( Sub Main
:

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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

Scroll Bars . ContainerControl


ScrollableControl Container .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

: Windows Forms
451

)( InitializeComponent Form Designer .


- Text :

)(Private Sub InitializeComponent

" " = Me.Text


End Sub

Text

.String

MaximizeBox MinimizeBox Boolean


False

False .ControlBox

Icon )( BackgroundImage

) Tile Wall
.(Paper

Opacity 1 0

1 0 0.5

TransparencyKey

.
.

ShowInTaskBar

Task Bar .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

452
: Windows

7 :FormBorderStyle Sizable

FixedSingle Fixed3D
None .

Hide SizeGripStyle

Size Grip ) (.
:

DesktopBounds DesktopLocation
SetDesktopBounds SetDesktopLocation

CenterScreen

.StartPosition

WindowState Maximized Minimized


.Normal

MaximumSize MinimumSize

True TopMost

.Windows

:Scrolling
True AutoScroll

Scroll Bars

.
HScroll .VScroll

AutoScrollMargin

. ).(0; 0

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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

PDF created with pdfFactory Pro trial version

454
: Windows

:6- 13 .
- )( Show

)( Show

Dim MyForm As New Form2


)( MyForm.Show
'

)( Show
Windows )( Show

-Windows Modeless Window


.

)( ShowDialog Modal Window

) Dialog Boxes (
:

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Windows Forms
455

Dim MyForm As New Form2


)(MyForm.ShowDialog
'
'

)( Show Active Window


)(.Activate

)( Hide


)( Show . )( Close

)( SetDesktopLocation

x y

) (0 0
.

)( SetDesktopBounds :
Dim MyForm As New Form2
)MyForm.SetDesktopBounds(0, 0, 200, 100

)( AddOwnedForm )(:RemoveOwnedForm

Windows Owner Windows

.Owned Windows
. Minimize
.Task Bar

)(:AddOwnedForm
)(Dim x As New ownedForm
)(Dim y As New ownedForm

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

456
: Windows

)Me.AddOwnedForm(x
)Me.AddOwnedForm(y
)(x.Show
)(y.Show

OwnedForms

Dim frm As Form


For Each frm In Me.OwnedForms
" " = Frm.Text
Next

Owner

If Me.Owner Is Nothing
'

Else
'

End If

)(RemoveOwnedForm
.

.NET Framework
Control

Visual Studio .NET

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Windows Forms
457

Base Class Events


) .(7- 13

:7- 13 .

)( <- New <- Load <- Paint <- Activated

<- Deactivated <- Closing <- Closing <- Closed


)(.Dispose


) ... GotFocus LostFocus Move Resize(
Control
.Form

)( New )(:Dispose


Base Class

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

458
: Windows

)(Public Sub New


)(MyBase.New

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

_ Private Sub Form1_Load(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles MyBase.Load
)" "(MsgBox
End Sub

)( Show .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Windows Forms
459

:Paint
Paint
Paint .

Paint.

Scrollbars Paint

Paint

Paint
:

_ Private Sub Form1_Resize(ByVal sender As Object,


ByVal e As System.EventArgs) Handles MyBase.Resize
)Me.Form1_Paint(Me, Nothing
End Sub

Paint

)( Refresh
:

_ Private Sub Form1_Resize(ByVal sender As Object,


ByVal e As System.EventArgs) Handles MyBase.Resize
)(Me.Refresh
End Sub

Activated :Deactivated

Active Window
Activated .Deactivated

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

460
: Windows

Closing :Closed

Closing )( Close
.

True Cancel :

_ Private Sub Form1_Closing(ByVal sender As Object, ByVal e


As ComponentModel.CancelEventArgs) Handles MyBase.Closing
e.Cancel = True
End Sub

Closed

)(.Me.Show
:

MinimumSizeChange

MinimumSize MaximumSizeChange

MaximumSize MaximizedBoundsChange
.MaximizedBounds

MDI Forms

- MDI
.

MDI True IsMdiContainer


.

Windows Forms MDI

.
Windows MDI MDI.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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

:8- 13 Child .MDI


MDI

MdiParent

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

462
: Windows

)( ,AddOwnedForm

MdiParent
.

Menus

) MDI ( )(AddOwnedForm
.

Maximize MDI
MDI
.

Child Windows IsMdiChild

True :

If Me.IsMdiChild Then

End If

MdiParent MDI

- True
:

If Not Me.MdiParent Is Nothing Then


"Me.MdiParent.Text = "...

End If

MDI

MidiChildren :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Windows Forms
463

Dim childForm As Form


For Each childForm In Me.MdiChildren
"childForm.Text = ".....
Next

ActiveMdiChild
:
" "= Me.ActiveMdiChild.Text

)( ActivateMdiChild

))Me.ActivateMdiChild(Me.MdiChildren(0

MDI

MdiChildActivate
:

_ Private Sub MDIForm_MdiChildActivate(ByVal sender As Object,


ByVal e As System.EventArgs) Handles MyBase.MdiChildActivate
End Sub

)( LayoutMdi

MdiLayout : ArrangeIcons Cascade

TileHorizontal :TileVertical

)Me.LayoutMdi(MdiLayout.ArrangeIcons
)Me.LayoutMdi(MdiLayout.Cascade
)Me.LayoutMdi(MdiLayout.TileHorizontal
)Me.LayoutMdi(MdiLayout.TileVertical

Menus

Windows Forms Menus

) (4- 15 MainMenu

MainMenu

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

464
: Windows

) Visulally .(9- 13

:9- 13 .

- Delete

Properties Window
.

Designer's Tray Area


.
.Controls

MainMenu

Menu :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Windows Forms
465

Me.Menu = MainMenu2

MainMenu .Menu
MainMenu
.MenuItem

MenuItem .

Text

& Underline
] [Alt

.Mnemonic " "- Text


.

Checked True

RadioCheck

MenuItems

MenuItem
.Parent

Shortcut False ShowShortcut


.

)(GetMainMenu

MainMenu )(PerformClick

Click )( PerformSelect Select


.

Click

Select

) (.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

466
: Windows

Popup-Menu

Popup-Menus
ContextMenu MainMenu

.
ContextMenu ) (:

Button1.ContextMenu = ContextMenu1

)( Show :

))ContextMenu1.Show(Button1, New Point(0, 0


Point
.Controls

DefaultItem True

Default Item

Bold.

ContextMenu

.Popup

MDI
MDI Child

MDI MergeType
MainMenu .MenuItem

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

: Windows Forms
469

ContextMenu
AddHandler )(:MenuClicked

_ Private Sub Form1_Load(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles MyBase.Load
)(Dim X As New ContextMenu
)(Dim sub1 As New MenuItem
)(Dim sub2 As New MenuItem
" sub1.Text = "1
" sub2.Text = "2
)X.MenuItems.Add(sub1
)X.MenuItems.Add(sub2
AddHandler sub1.Click, AddressOf MenuCliked
AddHandler sub2.Click, AddressOf MenuCliked
Button1.ContextMenu = X
End Sub
)Sub MenuCliked(ByVal send As Object, ByVal e As EventArgs
)" "(MsgBox
End Sub

Windows Forms
: Modal Form Inheritance

.Localized Forms

Modeless

)( Show

:Modeless

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

470
: Windows

Dim MyForm As New Form2


)( MyForm.Show
'


. :


) Closing ( :Modeless

)( Sub ShowForm
)(Dim mdless As New Form1
AddHandler mdless.Closing, AddressOf FormHasBeenClosed
)(mdless.Show
End Sub
_

Sub FormHasBeenClosed(ByVal sender As Object, ByVal e As


)System.ComponentModel.CancelEventArgs
) " & sender.text "(MsgBox
End Sub

Form Inheritance

Inheritance

. Base
) Form (

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Windows Forms
471

.
:

Controls

Field

TextBox :

Class Form1
Inherits System.Windows.Forms.Form

Friend WithEvents TextBox1 As Forms.TextBox

End Class

Private
Protected


Modifier
.

Private :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

472
: Windows

Private

Class Form1
Inherits System.Windows.Forms.Form

Private WithEvents TextBox1 As Forms.TextBox


'
Friend Property TextValue() As String
Get
Return TextBox1.Text
End Get
)Set(ByVal Value As String
TextBox1.Text = Value
End Set
End Property

End Class

) (10- 13
.PasswordForm

:10- 13 .
) Build xxx xxx (

Build

PasswordForm :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Windows Forms
473

Class TestForm
Inherits PasswordForm

End Class

Build xxx

.

Visual

Studio .NET Add Inherited Form Project


Open
) Inheritance Picker .(11- 13

:11- 13 .Inheritance Picker

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

474
: Windows

OK
) (12- 13

:12- 13 .

Private

Localized Forms



Visual Studio .NET .

) (13- 13

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Windows Forms
475

:13- 13 .

.Localized Form

True Localizable

) ( True

Resource File
.

) Language (14- 13 )
(.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

476
: Windows

:14- 13 ) Arabic (Saudi Arabia .


Language

) (13- 13

) .(15- 13

:15- 13 )Arabic (Saudi Arabia


)

(13- 13 ) (Default Language


) (15- 13 ) Arabic (Saudi Arabia .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Windows Forms
477

) (13- 13
) Language ).((Default
:

Internationalization Forms

Visual Studio

.NET

.resx
.

Solution Explorer

) Show All Files .(16- 13

:16- 13 .Show All Files



) XML 17- 13 ( . XML
XML .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

478
: Windows

:17- 13 .XML



.Resources


Controls


.Control

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

14

Controls
Windows

Controls

.Windows Forms

Windows Forms

) Control 4- 13 (449

Control
- ) (Control
.


Form
Form .Control

) Properties Windows (5- 14

)( InitializeComponent .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

480
: Windows

)
( .Shared Members
Common Members
.Control

Name

Name

Name
)(.InitializeComponent

-
)( InitializeComponent.

Text3 Text2 Text1

) (

Visible Enabled Boolean


False

Enabled

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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

CheckBox Button RadioButton .

Left Right : Center .HorizontalAlignment

Font System.Drawing.Font

GDI+
Font
:System.Drawing.Font

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

482
: Windows

_ TextBox1.Font = New Font("Tahoma", 20, FontStyle.Bold Or


)FontStyle.Italic

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

PDF created with pdfFactory Pro trial version

: Controls
483

System.Drawing.Rectangle Client Region


Pixel
.

Point Location

Size Size

) (:

'
)TextBox1.Location = New Point(0, 0
400 ' 100
)TextBox1.Size = New Size(400, 100

Height Top Left Width


) Visual Basic (1->6
Right Bottom .

.Optimization

System.Drawing.Rectangle

Bounds ) (

ClientRectangle ) ( .
:

TextBox1.Bounds = Form1.ClientRectangle

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

484
: Windows

:Anchor
Anchor

AnchorStyles.Bottom AnchorStyles.Top
AnchorStyles.Right .AnchorStyles.Left

.AnchorStyles.None

) (


) Tree .(Windows Explorer

) 2- 14 (:

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Controls
485

:2- 14 .Anchor

TextBox1 : Right Top : Left TextBox2Bottom Top :

Right Left Label Right : Top Button


Anchor Left : .Top

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

Left Right Bottom


:

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

PDF created with pdfFactory Pro trial version

: Controls
487

DockPadding
) ContainerControl 4-13
.(449

)( FindForm Parent
)() FindForm )( FindForm Method (

.Parent Parent
) !(:

Dim frmForm2 As New Form2


TextBox1.Parent = frmForm2
)( frmForm2.Show

) Form1.TextBox1
WithEvents (

(.

)( FindForm Parent

" " = TextBox1.FindForm().Test

Panel GroupBox

) ContainerControl 4- 13 (449
Controls
.

Controls Collection

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

488
: Windows

Form1
GroupBox1
TextBox1
TextBox2
TextBox3
GroupBox2
TextBox4
TextBox5

Form1.Controls GroupBox1 GroupBox2


GroupBox1.Controls TextBox2 TextBox1
TextBox3 TextBox4 TextBox5

.GroupBox2.Controls


ForeColor BackColor

- .

Windows .NET :
System Colors .Custom Colors

Control Panel Windows .


.

:System.Drawing.SystemColors

TextBox1.BackColor = SystemColors.Window
TextBox2.BackColor = SystemColors.ActiveBorder

System.Drawing.Color :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Controls
489

TextBox1.BackColor = Color.Black
TextBox1.ForeColor = Color.White

)( FromArgb

)TextBox1.BackColor = Color.FromArgb (255, 0, 0

BackColor ForeColor
) .(Font

.


Focus Active Control

Focus ) TextBox ( .
CanFocus

.ReadOnly
Focused .

(
ActiveControl ) (.

Windows ] [TAB

Focus

TabStop .TabIndex True TabStop

] [TAB
TabIndex .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

490
: Windows

False TabStop
.


Disposing Created

Disposed True -

Menu ContextMenu

.Pop-up menu

Custom Controls

ProduceVersion ProductName .CompanyName

) Locked (

) (

AccessibleRole AccessibleName AccessibleDescription - IsAccessible

MSDN .

)( SetSize

)( SetBounds
.

)( BringToFront )( SendToBack

)( Show ) True (Visible )(Hide

) False .(Visible

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Controls
491

ForeColor (BackColor

)( ResetBackGround )(.ResetForeColor

) ( )( Focus

TabIndex ][TAB

)( GetNextControl .

)( Refresh() Invalidate )( Update

MSDN .

.
.

) .(4- 14

:4- 14 .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

492
: Windows

Click DblClick

MouseDown

(
Button :

_ Private Sub Button1_MouseDown(ByVal sender As Object,


ByVal e As Forms.MouseEventArgs) Handles Button1.MouseDown
If e.Button = MouseButtons.Left Then
'

ElseIf e.Button = MouseButtons.Middle Then


'

ElseIf e.Button = MouseButtons.Right Then


'

End If
End Sub

) X Y

( ) :(Control.MousePosition

_ Private Sub Button1_MouseDown(ByVal sender As Object,


ByVal e As Forms.MouseEventArgs) Handles Button1.MouseDown
Me.Text = e.X & " - " & e.Y
End Sub

MouseDown

Click Delta
.Mouse Wheel

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Controls
493

MouseDown MouseEventArgs

MouseMove MouseUp .MouseWheel


MouseHover MouseLeave MouseEnter

.(MouseMove


KeyUp KeyDown :

.KeyPress
KeyChar Handled
True

.NET

True ) .
TextBox (.

KeyDown KeyUp

KeyDown
.

KeyEventArgs Alt

Shift Control ] [Shift] [Alt ] [Ctrl

. KeyCode

) Enum (Keys Handled


Handled .KeyPress

KeyPress KeyUp KeyDown

KeyPress ][Enter

] [Tab ] [Esc ][F2] [F1

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

494
: Windows

... ]... [Alt] [Ctrl] [Shift KeyDown


.

KeyPress HelpRequested

].[F1

KeyPreview True .False


GotFocus
.LostFocus

Microsoft .NET Documentation Enter

Leave ) (GotFocus
) .(LostFocus

Enter Leave GotFocus

LostFocus
:

.Validated <- Validating <- Leave <- GotFocus <- Enter

Validating Validated

TextBox TextBox
.


- Paint

Windows

-Forms Resize
Move )
(.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Controls
495

ControlAdded

ControlRemoved
.

PropertyChanged

PropertyName


Visual Studio .NET

) ToolBox (5- 15 ToolBox

View
Form Desinger .

:5- 14 .ToolBox

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

496
: Windows


Customize ToolBox Customize Toolbox

) .(6- 14

:6- 14 .Customize ToolBox


Customize ToolBox Tab
ActiveX Controls COM

COM ..NET

.NET Framework Component

Custom Controls .

ToolBox Windows Application

. .NET
Documentation

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Controls
497

Label

TextAlignment 6 ) (1- 14

PreferredWidth PreferredHeight
.

FlatStyle

Image
.ImageAlign

True UseMnemonic

Label TabIndex ][Alt

& Text
& . &
&&.

LinkLabel

LinkLabel Label
HTML .

LinkArea Text "

" 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

PDF created with pdfFactory Pro trial version

498
: Windows

_ Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object,


_ )ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs
Handles LinkLabel1.LinkClicked
)(Select Case e.Link.LinkData
"Case "Link1
)" "(MsgBox
"Case "Link2
)" "(MsgBox
End Select
End Sub

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

PDF created with pdfFactory Pro trial version

: Controls
499

MaxLength PasswordChar
) * (.

PasswordChar TextBox
Copy Cut
.

.

Upper

CharacterCasing Capital Lower


.

) :

...( ) (
.

True Multiline

Multi-Line

Textbox .

True AcceptsReturn AcceptsTab

] [Enter ] [Tab ] [Enter


) ( Tab

.TabIndex

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

500
: Windows

Default Button
] [Enter
.Button

.AcceptsReturn

ScrollBars

H ScrollBar

WordWrap . False

Lines

)( ScrollToCaret
.
:

Validating Validated TextBox

: X Y

CausesValidation False

True Validating X
True Cancel :Validating

_ Private Sub X_Validating(ByVal sender As Object,


_ )ByVal e As System.ComponentModel.CancelEventArgs
Handles X.Validating
If X.Text = "" Then e.Cancel = True
End Sub

X Validated )

LostFocus( Cancel
Validated .Y

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Controls
501

Button
Windows
.

AcceptButton CancelButton

] [Enter

] [Esc
:

Me.AcceptButton = Button1
Me.CancelButton = Button2

CheckBox

Windows

True Checked False True


Indeterminate CheckState

Checked

False AutoCheck

.Checked

CheckAlign ) TextAlign (1- 14

Checked True ThreeState

Checked Checked True


Indeterminate CheckState

Checked ...

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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 )

)(... Count() Clear() Insert() Add(:

'
Dim counter As Integer
For counter = 1 To 10
)ListBox1.Items.Add(counter
Next
'
)(ListBox1.Items.Clear

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Controls
503

'
Dim item As Object
For Each item In ListBox1.Items

Next



.ICollection

) Primitave Types

... Double Integer String( :

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

Overrides Function ToString() As String


Return Me.Name
End Function
End Class

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

504
: Windows

ListBox

SelectionMode MultiSimple ) MultiExtended


] [Ctrl ] [Shift (
:SelectedItems

Dim x As String
For Each x In ListBox1.SelectedItems

Next

)( SetSelected True False


:

)ListBox1.SetSelected(0, True
)ListBox1.SetSelected(1, False

)( BeginUpdate )( EndUpdate
:

Dim counter As Integer


)(ListBox1.BeginUpdate
For counter = 0 To 10000
)ListBox1.Items.Add(counter
Next
)(ListBox1.EndUpdate

CheckedListBox

CheckedListBox ListBox
SelectionMode

ListBox

CheckBox

SelectedItems .SelectedItems

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Controls
505

ComboBox
ComboBox ListBox

TextBox ListBox

TextBox ComboBox.

ComboBox DropDownStyle

Simple DropDown : DropDownList


True .DroppedDown

ImageList


Image

ImageList
) TreeView (ListView

ImageList .

ImageList

Images

) Image Collection Editor (7- 14 .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

506
: Windows

:7- 14 ImageList

Item Collection
ICollection
) )(()Count Clear() Insert() Add
...( .

TreeView

TreeView
Windows Explorer ImageList

ImageList TreeView
ImageList .TreeView

Nodes

Nodes Collection

) Tree Node Editor .(8- 14

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Controls
507

:8- 14 Node .TreeView


Nodes )

Items (ListBox

TreeNode )( Add )(:Insert

))" "(TreeView1.Nodes.Insert(0, New TreeNode


))" "(TreeView1.Nodes(0).Nodes.Add(New TreeNode

TreeView ShowLines

ShowPlusMinus )(+
) (- Indent
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

: Controls
509

LargeImageList ImageList ) LargeIcon

.(View

ListView TreeView

TreeView Nodes

ListView Items .

ListView View Details

Columns

SubItems Items

)( .

ToolBar StatusBar
ToolBar StatusBar

Buttons

.Panels

ImageList

Buttons Panels ICollection

) Nodes (TreeView Items

) ListBox (ListView
.

Panels
StatusBar True .ShowPanels

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

510
: Windows

Splitter
Splitter

Windows

(Explorer

) .(10- 14

:10- 14 .Splitter
Splitter Dock

Splitter X Right
) Dock ( Splitter

Dock Right Y Top Dock


Splitter Top Dock Z Fill

.Dock

) .(10- 14

Windows
... . .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

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

Page Setup PageSetupDialog

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

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

514
: Windows


Provider Controls

.
.

:ToolTip
ToolTip ) (11- 14

ToolTip
ToolTip on ToolTip1

:11- 14 .ToolTip

Provider Controls
" on ".

ReshowDelay AutoPopDelay AutomaticDelay

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Controls
515

:HelpProvider
HelpProvider Help
] [F1

Help Help Files


.

HelpProvider HelpNamespace

MyHelpFile.CHM

HelpKeyword HelpNavigator :
.HelpString

Contents ... Index


HelpString
) (11- 14 ] [F1 )
HelpKeyword (.

Windows Forms
.

PictureBox Image


.SizeMode

Panel GroupBox Container

AutoScroll

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

516
: Windows


.Text

HScrollBar VScrollBar

Custom Controls

- .
Maximum Minimum Scroll

.Value

NotifyIcon System Tray

Windows ) .(12- 14

Icon ToolTip
.Visible
.ContextMenu

:12- 14 .System Tray


TabControl Tab

) Windows (13- 14

TabPage .Container
TabPages ICollection
ImageList .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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

PDF created with pdfFactory Pro trial version

518
: Windows

MS-DOS Nafitha

Arabic Helper .

" "Right To Left

) Windows Forms .NET(.

RightToLeft

Control RightToLeft

- )
Enum :(RightToLeft

Yes

) (.
) (.

No
Inherit

TextAlign Right

Left
.

ScrollBars

- -



RightToLeft




RightToLeftChanged Control .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Controls
519

. Buttons
Label ... TextBox

Label

TextBox
:MirrorLocations

)Private Sub MirrorLocations(ByVal ctl As Control


Dim C As Control
For Each C In ctl.Controls
_ C.Location = New Point(C.Parent.ClientRectangle.Width
)- C.Size.Width - C.Location.X, C.Location.Y
If C.Controls.Count > 0 Then
)MirrorLocations(C
End If
Next
End Sub

MirrorLocations

:RightToLeftChanged

_ Private Sub Form1_RightToLeftChanged(ByVal sender As Object,


ByVal e As System.EventArgs) Handles MyBase.RightToLeftChanged
)MirrorLocations(Me
End Sub

TextAlign

RightToLeft MirrorLocation
Windows Forms .

Windows Forms Anchor Dock

TextAlign

Right Left
:MirrorLocation

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

520
Windows :

Private Sub MirrorLocations(ByVal ctl As Control)


Dim C As Control
For Each C In ctl.Controls
C.Location = New Point(C.Parent.ClientRectangle.Width _
- C.Size.Width - C.Location.X, C.Location.Y)
If CBool(C.Anchor And AnchorStyles.Left) Then
C.Anchor = (C.Anchor Or AnchorStyles.Right) Xor
AnchorStyles.Left
ElseIf CBool(C.Anchor And AnchorStyles.Right) Then
C.Anchor = (C.Anchor Or AnchorStyles.Left) Xor
AnchorStyles.Right
End If
If C.Dock = DockStyle.Right Then
C.Dock = DockStyle.Left
ElseIf C.Dock = DockStyle.Left Then
C.Dock = DockStyle.Right
End If
If C.Controls.Count > 0 Then
MirrorLocations(C)
End If
Next
End Sub

RightToLeft

RightToLeft

Form

(14- 14 )RightToLeft
.

. RightToLeft :14- 14

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

: Controls
521

StatusBar ProgressBar Panel ListView

ToolBar TabControl TreeView RightToLeft


. RightToLeft
.

Mirroring )
(Right to Left Layout

) ... ( .
Windows 98 Enabled
Local Windows 2000
.

) .(15- 14

:15- 14 .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

522
: Windows

GDI+ .


RightToLeft
!

Visual Basic .NET

:
Button PictureBox ) TabControl .(16- 14

:16- 14 Button PictureBox .TabControl

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Controls
523

WS_EX_LAYOUTRTL

Extended Style

)( SetWindowLong API -
.API

Extended Style Windows



...) . MSDN
API
)(.(SetWindowLong

Windows Forms Windows

Forms )() CreateWindow


(API

Overrides .CreateParams

CreateParams CreateParams

ExStyle
) :(17- 14

_ Protected Overrides ReadOnly Property CreateParams() As


System.Windows.Forms.CreateParams
Get
Const WS_EX_LAYOUTRTL As Integer = &H400000
Dim MirrorExStyle As System.Windows.Forms.CreateParams
MirrorExStyle = MyBase.CreateParams
'
MirrorExStyle.ExStyle = MirrorExStyle.ExStyle Or
WS_EX_LAYOUTRTL
Return MirrorExStyle
End Get
End Property

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

524
: Windows

:17- 14 Button
.PictureBox
) (17- 14

Button
.PictureBox WS_EX_NOINHERITLAYOUT

:WS_EX_NOINHERITLAYOUT

Const WS_EX_NOINHERITLAYOUT As Integer = &H100000


_ MirrorExStyle.ExStyle = MirrorExStyle.ExStyle Or
WS_EX_LAYOUTRTL Or WS_EX_NOINHERITLAYOUT

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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

PDF created with pdfFactory Pro trial version

PDF created with pdfFactory Pro trial version

526
Windows :


WS_EX_NOINHERITLAYOUT
.
.

.
.
.
.
.

Form
ListView
Panel
StatusBar
TabControl
TabPage
ToolBar
TreeView

TreeView

. WS_EX_NOINHERITLAYOUT
TreeView CreateParams

:TreeView

Public Class ArabicTreeView


Inherits System.Windows.Forms.TreeView
Protected Overrides ReadOnly Property CreateParams() As _
System.Windows.Forms.CreateParams
Get
Const WS_EX_LAYOUTRTL As Integer = &H400000
Dim MirrorExStyle As System.Windows.Forms.CreateParams
MirrorExStyle = MyBase.CreateParams
MirrorExStyle.ExStyle = MirrorExStyle.ExStyle Or
WS_EX_LAYOUTRTL
Return MirrorExStyle
End Get
End Property
End Class

w w.pdf actory.com

: Controls
527

) TreeView

ListView (ToolBar ) .(19- 14

:19- 14 ToolBar

) NotInheritable

(Imagelist CreateParams

WS_EX_NOINHERITLAYOUT

) .(17- 14


)SaveFileDialog OpenFileDialog

PageSetupDialog ColorDialog FontDialog PrintDialog

.Local

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

528
: Windows


MsgBox

MsgBoxRight MsgBoxRtlReading :

_ ", MsgBoxStyle.MsgBoxRight "(MsgBox


_ Or MsgBoxStyle.MsgBoxRtlReading
_ Or MsgBoxStyle.YesNo Or MsgBoxStyle.Question
)" " Or MsgBoxStyle.DefaultButton2,

:20- 14 Message Box .


) Yes (No Local

API .MSDN

MessageBox RtlReading RightAlign

_ ", " ", "(MessageBox.Show


_ MessageBoxButtons.YesNo,
_ MessageBoxIcon.Question, MessageBoxDefaultButton.Button2,
)MessageBoxOptions.RightAlign Or MessageBoxOptions.RtlReading

MessageBox MsgBox
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Controls
529

.Windows Forms

.
.NET Framework

. GDI+
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

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

)(Dim gr As Graphics = MainForm.CreateGraphics

) (

)( CreateGraphics
:

)(gr.Dispose
gr = Nothing

Graphics
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: GDI+
533


Graphics )

( . Overloads

) Pen

(Pen
.Rectangle )( DrawLine
)( DrawRectangle )( DrawEllipse -
) (:

_ Private Sub Form1_Paint(ByVal sender As Object,


ByVal e As PaintEventArgs) Handles MyBase.Paint
Dim gr As Graphics = e.Graphics
)gr.DrawLine(Pens.Black, 0, 0, 200, 200
))gr.DrawRectangle(Pens.Red, New Rectangle(0, 0, 200, 200
)gr.DrawEllipse(Pens.Blue, 0, 0, 200, 200
End Sub


Rectangle
Controls
.

)( DrawArc
)( DrawEllipse
) (:

)gr.DrawArc(Pens.Black, 0, 0, 200, 200, 0, 90

) 1- 15 ( .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

534
: Windows

:1- 15 ).DrawArc (, 0, 0, 200, 200, 0, 90

)( DrawLines )( DrawRectangles

Point Rectangle :

Dim gr As Graphics = e.Graphics


_ Dim points() As Point = {New Point(10, 10),
_New Point(200, 200), New Point(10, 100),
})New Point(10, 10
)gr.DrawLines(Pens.Green, points

)( DrawCurve )( DrawBezier

MSDN
)( DrawBezier ) :(2- 15

Dim gr As Graphics = e.Graphics


)gr.DrawBezier(Pens.Black, 10, 30, 100, 20, 140, 190, 300, 200

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: GDI+
535

:2- 15 )(.DrawBezier

Pen

.NET

Framework ... Pens.Green Pens.Red Pens.Black : .


System Colors ) SystemPens:

.(SystemPens.ControlDark

... . Pen
.

Pen

4:

)Dim myPen As New Pen(Color.Black, 4

myPen Graphics
:

Dim gr As Graphics = e.Graphics


)gr.DrawLine(myPen, 0, 0, 200, 200

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

536
: Windows

)(myPen.Dispose
myPen = Nothing

) (2- 15 . . . . . .

- - - - - - DashStyle

:DashStyle

Dim gr As Graphics = e.Graphics


)Dim myPen As New Pen(Color.Black, 4
myPen.DashStyle = DashStyle.DashDot
)gr.DrawLine(myPen, 0, 0, 200, 200
myPen.DashStyle = DashStyle.Dash
)gr.DrawLine(myPen, 0, 20, 200, 220
)(myPen.Dispose

:2- 15 .DashStyle

Single DashPattern )
1 (:

Dim gr As Graphics = e.Graphics


)Dim myPen As New Pen(Color.Black, 7
}Dim customDash() As Single = {2, 1, 5, 1
myPen.DashPattern = customDash
)gr.DrawLine(myPen, 10, 10, 300, 10

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: GDI+
537

Pen -

StartCap :EndCap

Dim gr As Graphics = e.Graphics


)Dim myPen As New Pen(Color.Black, 7
myPen.StartCap = LineCap.ArrowAnchor
myPen.EndCap = LineCap.ArrowAnchor
)gr.DrawLine(myPen, 10, 40, 300, 40

) :(3- 15

:3- 15 StartCap DashPattern .EndCap


1

) (0, 0 ) (0, 0

1 .

Alignment :

Dim gr As Graphics = e.Graphics


)Dim myPen As New Pen(Color.LightGray, 8
myPen.Alignment = PenAlignment.Center
))gr.DrawRectangle(myPen, New Rectangle(10, 10, 100, 100
))gr.DrawRectangle(Pens.Black, New Rectangle(10, 10, 100, 100
myPen.Alignment = PenAlignment.Inset
))gr.DrawRectangle(myPen, New Rectangle(150, 10, 100, 100
))gr.DrawRectangle(Pens.Black, New Rectangle(150, 10, 100, 100
)(myPen.Dispose

Alignment

) .(4- 15

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

538
: Windows

:4- 15 Alignment 1.

GraphicsPath

) )(AddLine

)(... AddCirlce() AddRectangle( .

GraphicsPath

:New

)(Dim myPath As New GraphicsPath

:
)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

PDF created with pdfFactory Pro trial version

: GDI+
539

)( CloseFigure :
)(myPath.CloseFigure

Graphics )() DrawPath - 16


:(6

Dim gr As Graphics = e.Graphics

)gr.DrawPath(Pens.Black, myPath
)(myPath.Dispose

:6- 16 GraphicsPath .

)( Dispose
.

Graphics Overloads

) Filled ( FillRectangles() FillRectangle() :

)( FillPath() FillClosedCurve() FillPie() FillEllipse )( .FillRegion


.NET Documantation .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

540
: Windows

Brush

Brushes

) SystemBrushes (System Color


:

Dim gr As Graphics = e.Graphics


'
)gr.FillEllipse(Brushes.Black, 0, 0, 200, 200

)( FillPath )

(GraphicsPath )( FillRegoin

) Region (.

Brush

Brushes

.SystemBrushes
- .Brush

SolidBrush :

Dim gr As Graphics = e.Graphics


)Dim myBrush As New SolidBrush(Color.Red
)gr.FillEllipse(myBrush, 0, 0, 200, 200
)(myBrush.Dispose

)( Dispose
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: GDI+
541

HatchBrush

56 ) HatchStyle
!( :

Dim gr As Graphics = e.Graphics


_ Dim myBrush As New HatchBrush(HatchStyle.BackwardDiagonal
), Color.Green, Color.White
)gr.FillRectangle(myBrush, 0, 0, 100, 100
)(myBrush.Dispose

HashStyle
.

LinearGradientBrush

Dim gr As Graphics = e.Graphics


_ Dim myBrush As New LinearGradientBrush(New Rectangle(0,
_ 0, 200, 200), Color.Black, Color.Blue,
)LinearGradientMode.BackwardDiagonal
)gr.FillRectangle(myBrush, 0, 0, 300, 300
)(myBrush.Dispose

Tile

TextureBrush
:

Dim gr As Graphics = e.Graphics


)Dim myBrush As New TextureBrush(PictureBox1.Image
)gr.FillRectangle(myBrush, 0, 0, 300, 300
)(myBrush.Dispose

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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:

Dim gr As Graphics = e.Graphics


)(Gr.ResetTransform
'
_ gr.TranslateTransform(Picture1.ClientRectangle.Width \ 2,
)Picture1.ClientRectangle.Height \ 2

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: GDI+
543

)( DrawRectangle

)(TranslateTransform

) - 15
:(7

_ Private Sub Form1_Paint(ByVal sender As Object, ByVal e


As Forms.PaintEventArgs) Handles MyBase.Paint
Dim gr As Graphics = e.Graphics
)gr.DrawRectangle(Pens.Black, -50, -50, 100, 100
_ gr.TranslateTransform(Me.ClientRectangle.Width \ 2,
)Me.ClientRectangle.Height \ 2
)gr.DrawRectangle(Pens.Black, -50, -50, 100, 100
End Sub

:7- 15 )( TranslateTransform .
:

)( TranslateTransform

)( RotateTransform x and y axis

Graphics

.
) :(8- 15

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

PDF created with pdfFactory Pro trial version

544
Windows :

Dim gr As Graphics = e.Graphics


gr.TranslateTransform(Me.ClientRectangle.Width \ 2, _
Me.ClientRectangle.Height \ 2)
gr.DrawRectangle(Pens.Black, -50, -50, 100, 100)
gr.RotateTransform(-45)
gr.DrawRectangle(Pens.Black, -50, -50, 100, 100)

.Graphics RotateTransform() :8- 15


:
) ScaleTransform()
:(9- 15

Dim gr As Graphics = e.Graphics


Dim myPath As New GraphicsPath()
Dim counter As Single
myPath.AddRectangle(New Rectangle(0, 0, 200, 200))
myPath.AddEllipse(New Rectangle(0, 0, 200, 200))
For counter = 1 To 1.6 Step 0.1
gr.DrawPath(Pens.Black, myPath)
gr.ScaleTransform(counter, counter)
Next

w w.pdf actory.com

: GDI+
545

:9- 15 )( ScaleTransform .Graphics


:

Graphics Pixel
PageUnitInch :

Millimeter Point ) 75/1( Display ) 72/1(


Document ) 300/1( :

Gr.PageUnit = GraphicsUnit.Inch


GDI+ .
Imports

System.Drawing.Imaging .


Image Bitmap

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

546
: Windows

)( LoadFromFile

Stream )( LoadFromStream :

)"Dim JPG As Image = Image.FromFile("C:\Ibrahim.JPG


Streams
.

:
)"Dim JPG As New Bitmap("C:\Ibrahim.JPG

GDI+ PNG BMP GIF JPGE


... TIFF.

Bitmap Image

)( Save :

)"Dim JPG As New Bitmap("C:\Ibrahim.JPG


)JPG.Save("C:\Ibrahim.GIF", ImageFormat.Gif

)( Save

....


Bitmap Image
)( DrawImage :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: GDI+
547

_ Private Sub Form1_Paint(ByVal sender As Object,


_ )ByVal e As System.Windows.Forms.PaintEventArgs
Handles MyBase.Paint
Dim gr As Graphics = e.Graphics
)"Dim JPG As New Bitmap("C:\Ibrahim.JPG
)gr.DrawImage(JPG, 0, 0
End Sub

Paint
.
.

)( DrawImage Overloads
30 .
)
:(Rectangle

Dim gr As Graphics = e.Graphics


)"Dim JPG As New Bitmap("C:\Ibrahim.JPG
gr.DrawImage(JPG, 0, 0, New Rectangle(10, 10, 50, 50),
)GraphicsUnit.Pixel

:
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

PDF created with pdfFactory Pro trial version

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

)gr.DrawImage(JPG, destRect, sourceRect, GraphicsUnit.Pixel


..NET Documentation

) (10- 15 )(.DrawImage

:10- 15 .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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

PDF created with pdfFactory Pro trial version

550
: Windows

Dim gr As Graphics = e.Graphics


)"Dim JPG As New Bitmap("C:\Eiffel.JPG
_ Dim points() As Point = {New Point(JPG.Width, 0),
})New Point(0, 0), New Point(JPG.Width, JPG.Height
)gr.DrawImage(JPG, points

V Flipping )

) (x0, y0 ) (0, 0(:

Dim gr As Graphics = e.Graphics


)"Dim JPG As New Bitmap("C:\Eiffl.JPG
_ Dim points() As Point = {New Point(0, JPG.Height),
})New Point(JPG.Width, JPG.Height), New Point(0, 0
)gr.DrawImage(JPG, points

Skewing

L / )
) (x0, y0 ) (0, 0(:

Dim gr As Graphics = e.Graphics


)"Dim JPG As New Bitmap("C:\Eiffl.JPG
Dim L As Integer = 50
Dim points() As Point = {New Point(L, 0), New Point(JPG.Width + L,
_0),
})New Point(0, JPG.Height
)gr.DrawImage(JPG, points

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

PDF created with pdfFactory Pro trial version

: GDI+
551

))Dim a As Single = CSng(Math.Cos(AngleInRad


))Dim b As Single = CSng(Math.Sin(AngleInRad
_ Dim points() As PointF = {New PointF(0, 0),
_ New PointF(JPG.Width * a, JPG.Width * b),
})New PointF(-JPG.Height * b, JPG.Height * a
)gr.DrawImage(JPG, points

PointF Point
X Y Single .Integer

:12- 15 50 90.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

552
: Windows


Transparent Color
)() MakeTransparent :(13- 15

Dim gr As Graphics = e.Graphics


)"Dim JPG As New Bitmap("C:\dev4arabs.JPG
)gr.DrawImage(JPG, 0, 0
)JPG.MakeTransparent(Color.White
)gr.DrawImage(JPG, 0, 100

:13- 15 .
)

Opacity ( ImageAttribute

)() DrawImage (Graphics

ImageAttribute Two Dimensional

Array SetColorMatrix
.NET Documentation .

Icons
Icon Windows
Icons Image

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: GDI+
553

) Icon

Stream(:

)"Dim icon As New Icon ("C:\test.ico

SystemIcons :Windows

)(Dim icon As Icon = SystemIcons.WinLogo

Icon

Graphics :

Dim gr As Graphics = e.Graphics


)"Dim icon As New Icon("C:\dev4arabs.ico
)gr.DrawImage(icon, 0, 0

)(:Dispose
)(Icon.Dispose

Icon

Image
Bitmap )(:ToBitmap

Dim gr As Graphics = e.Graphics


)"Dim icon As New Icon("C:\dev4arabs.ico
)(Dim BMP As Bitmap = icon.ToBitmap
)JPG.MakeTransparent(Color.White
)gr.DrawImage(BMP, 0, 100
)(icon.Dispose
)(BMP.Dispose

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

554
: Windows

Graphics )(DrawIconUnstretched

Icon Rectangle
.


GDI+

Fonts .

.System.Drawing.Text


Font Family

Tahoma ) Tahoma Regular :(Tahoma


) Bold() Tahoma Italic ( ) Tahoma Bold Italic (.

Families

InstalledFontCollection

:FontFamily

)(Dim fonts As New InstalledFontCollection


Dim fontFamilies() As FontFamily = fonts.Families
Dim fontFamily As FontFamily
For Each fontFamily In fontFamilies

Next

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: GDI+
555

Families TrueType
OpenType.

)( FontFamily.GetFamilies :Graphics

Dim gr As Graphics = Me.CreateGraphics


)Dim fontFamilies() As FontFamily = FontFamily.GetFamilies(gr
)(gr.Dispose

Families

Graphics )

(.

FontFamily

:
)"Dim fontFamily As New FontFamily("Tahoma

FontFamily

)( IsAvailable

True :

)"Dim fontFamily As New FontFamily("Tahoma


If fontFamily.IsStyleAvailable(FontStyle.Bold) Then

End If

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

556
: Windows


Graphics

. Font
13 Overloads :

)Dim font1 As New Font("Tahoma", 12

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

Dim myFont As New Font("Tahoma", 20, FontStyle.Bold,


)GraphicsUnit.Pixel

)( DrawString
String Font
Brush :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: GDI+
557

Dim gr As Graphics = e.Graphics


)Dim myFont As New Font("Tahoma", 20, FontStyle.Bold
)", myFont, Brushes.Black, 0, 0 "(gr.DrawString

)( MeasureString SizeF
:Font

Dim size As SizeF


"Dim myText As String = "...
)Dim myFont As New Font (...
)size = gr.MeasureString(myText, myFont


Width :Wrap
)gr.MeasureString(myText, myFont, 200

)( DrawString RectangleF

Dim gr As Graphics = e.Graphics


)Dim myFont As New Font("Tahoma", 14
_ & " " = Dim text As String
" "
_ gr.DrawString(text, myFont, Brushes.Black, New
))RectangleF(10, 10, 200, 200
'
))gr.DrawRectangle(Pens.Black, New Rectangle(10, 10, 200, 200

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

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

Text Direction FormatFlags


:( 15- 15 )DirectionRightToLeft

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))

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

: GDI+
561

Windows
] [Ctrl] + [Shift.

Rectangle

LineAlignment ) Near() Center (


) Far(.
:Justify

Justify

MSDN
- Web Forms HTML

. ArJustify ) - 15
.(17

:17- 15 .ArJustify

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

562
Windows :

: ArJustify

True Font

JustifiedText .
:

Dim myText As String


myText = New ArJustify(gr, myText, myFont, 200, True).JustifiedText
gr.DrawString(myText, myFont, Brushes.Black, _
New RectangleF(250, 10, 200, 200), sf)

JustifiedText()

AddKashidas()
:

Class ArJustify

Public ReadOnly Property JustifiedText() As String


Get
Return Me.text
End Get
End Property
Private Sub JusitfyLines()
Dim counter As Integer = 0
Me.textLines = Me.text.Split(" "c)
Do While counter <= UBound(Me.textLines)
If gr.MeasureString(Me.textLines(counter), Me.font).Width
_
= Me.width Then
'
ElseIf gr.MeasureString(Me.textLines(counter), _
Me.font).Width > Me.width Then
'
Else
'
counter += 1
Do While counter <= UBound(Me.textLines)
If gr.MeasureString(Me.textLines(counter - 1) & _

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

GDI+ :
563

" "c & Me.textLines(counter), _


Me.font).Width = Me.width Then
Me.textLines(counter - 1) &= " "c & _
Me.textLines(counter)
RemoveWord(counter)
counter -= 1
Exit Do
ElseIf gr.MeasureString(Me.textLines(counter - 1)_
& " "c & Me.textLines(counter), Me.font).Width
> Me.width Then
counter -= 1
Me.AddKashidas(counter)
Exit Do
Else
Me.textLines(counter - 1) &= " "c & _
Me.textLines(counter)
RemoveWord(counter)
End If
Loop
If counter >= UBound(Me.textLines) Then
Me.AddKashidas(counter - 1)
End If
End If
counter += 1
Loop
Me.text = Me.text.Join(" "c, Me.textLines)
End Sub

Private Sub AddKashidas(ByVal index As Integer)


Dim counter As Integer
Dim canAddKashida As Boolean
Dim allowedAfterLetters As String = ""
Dim allowedBeforeLetters As String = _
""
If Me.JustifyLastLine = False AndAlso index = _
UBound(Me.textLines) Then
Exit Sub
End If
If Me.textLines(index).Length <= 1 Then
Exit Sub
Else
counter = Me.textLines(index).Length - 2
End If
Do While gr.MeasureString(Me.textLines(index), Me.font).Width
_

PDF created with pdfFactory Pro trial version

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
.

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

: GDI+
565



.StringBuilder

ArJustify

) .(18- 15

:18- 15 ArJustify .

ArJustify


.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

_ gr.DrawString(myText, myFont, Brushes.Black,


)New RectangleF(10, 10, 280, 200), sf
)sf.SetDigitSubstitution(&H401, StringDigitSubstitute.Traditional
_ gr.DrawString(myText, myFont, Brushes.Black,
)New RectangleF(10, 40, 280, 200), sf

:19- 15 )

(.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: GDI+
567


LCID
.245

Controls

) ListBox (MenuBox

Device Context

ListBox
) .(20- 15

:20- 15 .
ListBox

Load :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

568
Windows :

Public Class Form1


Inherits System.Windows.Forms.Form
...
...
Structure ColorName
Dim ArabicName As String
Dim Brush As Brush
End Structure
Dim colorItems(6) As ColorName
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim ci As ColorName
colorItems(0).ArabicName = ""
colorItems(0).Brush = Brushes.White
colorItems(1).ArabicName = ""
colorItems(1).Brush = Brushes.Yellow
colorItems(2).ArabicName = ""
colorItems(2).Brush = Brushes.Silver
colorItems(3).ArabicName = ""
colorItems(3).Brush = Brushes.Blue
colorItems(4).ArabicName = ""
colorItems(4).Brush = Brushes.Orange
colorItems(5).ArabicName = ""
colorItems(5).Brush = Brushes.Red
colorItems(6).ArabicName = ""
colorItems(6).Brush = Brushes.Green
For Each ci In colorItems
ListBox1.Items.Add(ci.ArabicName)
Next
End Sub
End Class

DrawMode ListBox

OwnerDrawFixed
. ItemHeight

DrawItem

Index Bounds
(... ) State

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

GDI+ :
569

DrawItem

:(20- 15 )

Private Sub ListBox1_DrawItem(ByVal sender As Object, _


ByVal e As System.Windows.Forms.DrawItemEventArgs) _
Handles ListBox1.DrawItem
Dim gr As Graphics = e.Graphics
Dim myFont As New Font("Tahoma", 13)
Dim rect As Rectangle = e.Bounds
rect.Inflate(-3, -3)
gr.FillRectangle(colorItems(e.Index).Brush, rect)
If CBool(e.State And DrawItemState.Selected) Then
rect.Inflate(-1, -1)
gr.DrawRectangle(SystemPens.Highlight, rect)
rect.Inflate(-1, -1)
gr.DrawRectangle(SystemPens.Highlight, rect)
End If
gr.DrawString(colorItems(e.Index).ArabicName, _
myFont, Brushes.Black, _
rect.Width - gr.MeasureString(colorItems(e.Index).ArabicName,_
myFont).Width, rect.Y)
myFont.Dispose()
End Sub

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

570
: Windows

GDI+

GDI+ .NET Documentation


.

Custom Controls Windows Services .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

16


Windows Forms
Custom Controls Windows Services

Windows

Windows
.Windows

Visual Studio .NET


Controls
Custom Controls
.

: Author

Programmer
User .

Authoring Time

Design Time Programmer

Run Time
.

.
:

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

572
: Windows

Controls
) (TreeView Mirroring

) ProgressBar (ImageList

- ) TextBox Label

ListView Picture(
.

New->Project File

Windows Control Library Visual Studio .NET


) UserControl1.vb .(1- 16

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
573

:1- 16 .Windows Control Library

Windows Control Library


Class Library

Visual Studio .NET
.Project Property Pages

TextBoxExProject

UserControl1 :TextBox

Public Class TextBoxEx


Inherits System.Windows.Forms.TextBox
)(Sub New
)(MyBase.New
End Sub
End Class

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

574
Windows :

TextBox TextBoxEx

.TextBox
.

True AutoSelect

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

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

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

:
575

_ Private Sub TextBoxEx_Enter(ByVal sender As Object,


ByVal e As System.EventArgs) Handles MyBase.Enter
)(Me.SelectAll
End Sub
End Class

Bulid TextExProject Build

DLL .
:

New Project Add Project File


Windows Application Solution

) Startup Project ] ([F5

Solution Explorer Set as


Startup Project ) .(2- 16

:2- 16 .Startup Project

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

576
: Windows

New Solution
Windows Application

.

Debugging ) Visual
(Studio .NET

.


.

ToolBox Customize Toolbox Customize

Toolbox .NET Framework Component

) Brows (
. Open
) Customize ToolBox .(3- 16

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
577

:3- 16 TextBoxExProject .
OK Visual Studio

.NET ) TextBoxEx (4- 16


.

:4- 16 TextBoxEx .
TextBoxEx TextBox

) AutoSelect

( ) .(5- 16

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

578
: Windows

:5- 16 AutoSelect .
TextBoxEx True

Base Control

Overrides Overloads .
.


Form

Visual

) WindowState
... MaximizeBox ShowInTaskBar(.

Button TextBox
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
579

Custom Control :

Button TextBox ) OpenFileDialog .(6- 16

:6- 16 .
Anchor ) TextBox : (

Click Button :

_ Private Sub Button1_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
TextBox1.Text = OpenFileDialog1.FileName
End If
End Sub

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
581



GDI+ .

Microsoft
..NET Framework

Rotator

) (7- 16

Text Angle

Text Paint :

_ Private Sub Rotator_Paint(ByVal sender As Object,


ByVal e As System.Windows.Forms.PaintEventArgs) Handles
MyBase.Paint
Dim gr As Graphics = e.Graphics
)(Dim sf As New StringFormat
_ gr.TranslateTransform(Me.ClientRectangle.Width / 2,
)Me.ClientRectangle.Height / 2
)gr.RotateTransform(Me.Angle
_ gr.DrawString(Me.Text, Me.Font, Brushes.Black, New RectangleF(0,
))0, Me.ClientRectangle.Width, Me.ClientRectangle.Height
)(gr.ResetTransform
)gr.DrawRectangle(Pens.Black, Me.ClientRectangle
End Sub

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
583

Enum


) .(8- 16

:8- 16 .

) Windows Forms Size Color Font

... Rectangle( ) 9- 16
(:

Property TextColor() As Color

End Property

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

584
: Windows

:9- 16 TextColor .


TypeConverter
MSDN .

Design time properties


DesignMode True
False :
Public Property ModeType() As Boolean
Get
If Not Me.DesignMode Then
)" "(Throw New Exception
End If
End Get
)Set(ByVal Value As Boolean
If Not Me.DesignMode Then
)" "(Throw New Exception
End If
End Set
End Property

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

:
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

User Interface Server .

Windows Internet Information Server

) (IIS Microsoft Proxy Microsoft SQL Server


Server Administrating Directing

... Watching .

Windows

Services Administrative Tools Control


) Panel (11- 16

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

588
: Windows

:11- 16 Windows .

Windows Start : Stop


Pause ) Resume

(.

Windows Service
New->Project File Windows

Service Windows Visual Studio


.NET ) Service1.vb .(12- 16

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
589

:12- 16 .Windows Service


Windows Windows

) (
WindowsService1 .FolderWatcher

Windows

.NET Windows Class

.System.ServiceProcess.ServiceBase

Windows

Service1 ) (Name ServiceName


Service1 .DirWatcher

True CanStop Stop

) Control Panel (

CanPauseAndContinue Pause ) .(13- 16

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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()

' Add any initialization after the InitializeComponent() call


End Sub
'UserService overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
' The main entry point for the process

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

592
: Windows

Bold )

) ((Name Service1 :DirWathcer

ServicesToRun = New System.ServiceProcess.ServiceBase() {New


})(DirWathcer

.FileSystemWatcher

System.IO. FileSystemWatcher
FileSystemWatcher

Windows
FolderWatcher .

FileSystemWatcher

Path :

)(Dim FW As New System.IO.FileSystemWatcher


"FW.Path = "C:\Windows

) (

Changed Deleted Created


) Renamed WithEvents AddHandler( .

FileSystemEventArgs

FullPath :

)(Dim WithEvents FW As New System.IO.FileSystemWatcher


_ Public Sub FW_Deleted(ByVal sender As Object,
ByVal e As System.IO.FileSystemEventArgs) Handles FW.Deleted
)MsgBox (e.FullPath
End Sub

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
593

True

EnableRaisingEvents True
IncludeSubdirectories :
FW.IncludeSubdirectories = True
FW.EnableRaisingEvents = True

System.IO.FileSystemWatcher

Windows
.MSDN



System.ServiceProcess.ServiceBase

)( OnStart )( OnStop
Overrides

Public Class DirWatcher


Inherits System.ServiceProcess.ServiceBase

)(Dim WithEvents FW As New System.IO.FileSystemWatcher


)Protected Overrides Sub OnStart(ByVal args() As String
"FW.Path = "C:\Windows
FW.IncludeSubdirectories = True
FW.EnableRaisingEvents = True
End Sub
)(Protected Overrides Sub OnStop
FW.EnableRaisingEvents = False
End Sub
End Class

True ) CanPauseAndContinue (13- 16

)( OnPause )( OnContinue

Pause :Resume

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

PDF created with pdfFactory Pro trial version

594
Windows :

Public Class DirWatcher


Inherits System.ServiceProcess.ServiceBase

Protected Overrides Sub OnPause()


FW.EnableRaisingEvents = False
End Sub
Protected Overrides Sub OnContinue()
FW.EnableRaisingEvents = True
End Sub
End Class

FileSystemWatcher

.Windows

Windows ) Test.TXT

:(Server

Public Class DirWatcher


Inherits System.ServiceProcess.ServiceBase

Dim WithEvents FW As New System.IO.FileSystemWatcher()


Private Sub FW_Deleted(ByVal sender As Object, _
ByVal e As System.IO.FileSystemEventArgs) Handles FW.Deleted
Dim textFile As New System.IO.StreamWriter("C:\Test.TXT", _
True)
textFile.WriteLine(" & " e.FullPath)
textFile.Close()
End Sub
End Class


Streams
.

w w.pdf actory.com

:
595


) ] ([F5

Visual Studio .NET ) (14- 16


EXE

:14- 16 .

Visual Studio .NET .


Add Installer ) 13- 16

(590 ProjectInstaller.vb
ServiceProcessInstaller1 ) ServiceInstaller1 .(15- 16

:15- 16 .
ServiceInstaller

.NET Documentation

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

596
: Windows

DisplayName ServiceName

StartType )
(DirWatcher ) " -
( "DirWatcher Automatic

) System Booting (.

ServiceProcessInstaller1 Account

User Account

LocalSystem
) . MSDN
(.

EXE

InstallUtil.EXE
.System Registry

InstallUtil.EXE

Command Prompt corvars.bat

X:\Program Files\Microsoft Visual Studio

(.NET\FrameworkSDK\Bin Paths InstallUtil.EXE


Visual Studio .NET Command Prompt

Microsoft Visual Studio .NET ) Start


Assemblies

( ) .(6 - 11

DirWatcher EXE

:InstallUtil

C:\>InstallUtil FolderWatcher.EXE


Restart Service

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
597

Administrative Tools Control Panel


Start ) .(16- 16

:16- 16 DirWatcher .

InstallUtil.EXE :/u

C:\>InstallUtil FolderWatcher.EXE /u

Stop .
DirWatcher ) (16-16
Stop
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

598
: Windows


Windows

Windows

Windows Application Windows Services

.Custom Controls

Application

Application

New Application .
Application Shared Members ReadOnly
ExecutablePath StartupPath

MsgBox (Application.ExecutablePath) ' C:\Folder\MyAss.EXE


MsgBox (Application.StartupPath) ' C:\Folder

: CompanyName

CurrentCulture

ProductVersion ProductName

DoEvents

)( Exit )(ExitThread

MSDN Application

ThreadExit ApplicationExit : Idle

) Idle
(.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
599

Cursor
Cursor
Cursor .

Cursor Cursor

28

:Cursor

Button1.Cursor = Cursors.No

Cursor

)"Dim myCur As New Cursor ("C:\myCur.cur


Button1.Cursor = myCur

)(:Dispose
)(myCur.Dispose

Current Cursor

Cursor.Current = Cursors.Hand

Cursor Default


.Cursor

Cursor

) Clip
(Rectangle :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

~ ] [Enter + ] [Shift ^ ][Ctrl

% ] [Alt ] [Shift -

:Capital

)")SendKeys.Send("+(turki

} { }{TAB

}.... {F3} {F2} {F1} {RIGHT} {LEFT} {ESC .NET


Documentation .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
601

)( Send
API
FindWindow .SetForegroundWindows

Registry RegistryKey
Registry RegistryKey Windows

Registry .
) .(17- 16

:17- 16 .Windows Registry


Keys


Data .Value

Registry RegistryKey

Registry :RegistryKey

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

Dim name As String


For Each Name In root1.GetSubKeyNames

Next

)( OpenSubKey RegistryKey:

Dim IE As RegistryKey
)"IE = root1.OpenSubKey("Internet Explorer.Main

:
)(IE.Close

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

:
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

-Microsoft HTML Help Compiler CHM

) 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

PDF created with pdfFactory Pro trial version

604
: Windows

HelpNavigator.Topic

)(:ShowHelp

)Help.ShowHelp(Me, "C:\helpfile.chm",HelpNavigator.Topic ,3

keyword

)"" Help.ShowHelp(Me, "C:\helpfile.chm",

.NET Framework
Windows
..NET Documentation

.NET Framework .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

17

ADO.NET
ADO.NET

ADO.NET

(ERD) Entity Relation Diagrams



.Visual Basic .NET


:
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient

Project Property Pages
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

608
:

ADO.NET
ADO.NET System.Data

Data Sources


ADO.NET

: Connected Mode
.Disconnected Mode

Inbox

. ADO.NET

- .
SQL
- Data Structure Table

Relationships .

Microsoft SQL Server


.Microsoft Access

Servers Clients

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: ADO.NET
609


ADO.NET .

.NET Data Providers


ADO.NET

Microsoft Access

Microsoft FoxPro Microsoft SQL Server Oracle

... .

ADO.NET


ADO.NET

) .NET Data Providers .(1- 17

:1- 17 .NET Providers ADO.NET

.NET Data Providers ADO.NET

ADO.NET Microsoft

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

610
:

Access .NET Data Provider Microsoft Access

Microsoft SQL Server

.Microsoft SQL Server

ADO.NET

.NET Data Providers

.NET Data Providers

.NET Framework:

:OLE DB .NET Data Provider

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

) ( .

ODBC .NET Data Provides ODBC Drivers

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: ADO.NET
611

) OLE DB .NET Data Providers

(.

ADO.NET

ADO.NET
DataAdapter DataReader Command Connection : DataSet

) (2- 17
.

:2- 17 .ADO.NET
- -

. Connection

) .NET Data Provider

...( .

Command ) DELETE SELECT


INSERT( Connection.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

612
:

Command

Records DataReader
.

Connected Mode

DataSet .

DataSet DataAdapter

/ .Connection

Command Connection .DataReader

.Connection

Connection
ADO.NET
.Connection )

.(Disconnected Mode
.


Connection Connection
OLE DB .NET
Data Provider :OleDbConnection

)(Dim msAccessCn As New OleDbConnection

SQL Server .NET Data


Provider SQLConnection :

)(Dim msSQLCn As New SqlConnection

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: ADO.NET
613

IDbConnection

Polymorphism -
:
)Sub ConnectionDB(ByVal dbCon As IDbConnection

End Sub

Connection String
) (String

(Microsoft SQL Server

...
:Microsoft Access
_ ";Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0
";& "Data Source=C:\Folder\Data.MDB

Provider Data Source .


Connection Timeout

10
) 15(:

_ ";Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0


"& "Data Source=C:\Folder\Data.MDB; Connection Timeout=10

ConnectionString
:

'
)(Dim msAccessCn As New OleDbConnection
msAccessCn.ConnectionString = connString

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

614
:

'
)Dim msAccessCn As New OleDbConnection(connString




project.exe.config

.

ReadOnly:

)Dim msAccessCn As New OleDbConnection(connString


)MsgBox(msAccessCn.Provider
' Microsoft.Jet.OLEDB.4.0
MsgBox(msAccessCn.DataSource) ' C:\Folder\Data.MDB
MsgBox(msAccessCn.ConnectionTimeout) ' 10

SqlConnection
SqlConnection

:SQL Server .NET Data Provider

)(Dim msSQLCn As New SqlConnection


_ ";msSQLCn.ConnectionString = "Data Source=DEV4ARABS_SERVER
_ "; =; Password =& "User ID
" =& "Initial Catalog

ConnectionString
)(:Open

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: ADO.NET
615

)Dim msAccessCn As New OleDbConnection(connString


)Dim msSQLCn As New SqlConnection(connString2
)( msAccessCn.Open
)( msSQLCn.Open

connString Connection String



.

)(:Close
)( msAccessCn.Close
)( msSQLCn.Close

State

Closed : Open Connecting

Executing Fetching
:

)(Dim cn As New OleDbConnection

If (cn.State And ConnectionState.Open) <> 0 Then


)(cn.Close
End If

Open ) Closed (

StateChange :

)(Dim WithEvents cn As New OleDbConnection


_ Sub cn_StateChange(ByVal sender As Object,
_ ByVal e As System.Data.StateChangeEventArgs) Handles
cn.StateChange

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

616
:

If (e.CurrentState And ConnectionState.Open) <> 0 Then


" " = Label1.Text
Elseif e.CurrentState = ConnectionState.Closed Then
" " = Label1.Text
End If
End Sub

:Try End Try

)(Dim cn As New OleDbConnection


Try
)(cn.Open

Catch ex As Exception
)MsgBox(ex.Message
End Try

)( Close

) Garbage

Collection(

)(Dim cn As New OleDbConnection


Try
)(cn.Open

Catch ex As Exception
)MsgBox(ex.Message
Finally
)(cn.Close
End Try

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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

PDF created with pdfFactory Pro trial version

618
:

Command Command

Connection
OLE DB .NET Data Provider :OleDbCommand
)( Dim msAccessCmd As New OleDbCommand

SQL Server .NET Data


Provider SqlCommand :

)(Dim msSQLCmb As New SqlCommand

IDbCommand

Polymorphism -
:

)Sub CommandDB(ByVal dbCmd As IDbCommand

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

PDF created with pdfFactory Pro trial version

: ADO.NET
619

SqlCommand OLEDbCommand
:

)Dim cn As New SqlConnection(connString


)(Dim cmd As New SqlCommand
)(cn.Open
cmd.Connection = cn

Command

Connection - )( Close

SQL :

)Dim cn As New OleDbConnection(connString


)(Dim cmd As New OleDbCommand
)(cn.Open
cmd.Connection = cn
)(cn.Close
'
)(cmd.ExecuteNonQuery


) .(3- 17

:3- 17 Command Connection .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

620
:

SQL

Command SQL

SQL SELECT
Command
)(.ExecuteXXX

SQL

)( ExecuteNonQuery .
-

INSERT INTO UPDATE .DELETE

)( ExecuteNonQuery

SQL CommandText :Command

)Dim cn As New OleDbConnection(connString


)(cn.Open
_ "][ ] SET [ Dim sqlStatement As String = "UPDATE
"] = 99999 [ & " = 5000 WHERE
)(Dim cmd As New OleDbCommand
cmd.Connection = cn
cmd.CommandText = sqlStatement
)(cmd.ExecuteNonQuery

Connection CommandText

:Command

)Dim cmd As New OleDbCommand(sqlStatement, cn

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: ADO.NET
621

Try
)( cmd.ExecuteNonQuery

Catch ex As Exception

End Try

SELECT
Command ExecuteScalar() ExecuteReader() :
.ExecuteXMLReader

)(:ExecuteReader

)( ExecuteReader DataReader
) Command DataReader
DataReader (:

)]", cn [ Dim cmd As New OleDbCommand("SELECT * FROM


)(Dim dr As OleDbDataReader = cmd.ExecuteReader
)(Do While dr.Read
)))""(ListBox1.Items.Add(CInt(dr.Item
Loop
)(dr.Close

)(:ExecuteScalar

)( ExecuteScalar Field
:
_ " ] FROM [ Dim cmd As New OleDbCommand("SELECT
)] = 1", cn[ ] WHERE [ " &
)(Dim Name As String = cmd.ExecuteScalar

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

622
:

)( ExecuteScalar

-
Field
.

)( ExecuteScalar

_ " Dim cmd As New OleDbCommand("SELECT COUNT(*) FROM


)]", cn [ " &
))(Dim countOfFrogs As Integer = CInt(cmd.ExecuteScalar

)(:ExecuteXMLReader
SQL Server .NET Data Provider

)( ExecuteXMLReader Microsoft SQL


Server FOR XML SQL

.XML

)( ExecuteReader DataReader

)( ExecuteXMLReader System.XML.XmlReader

- :DataReader

)]", cn [ Dim cmd As New SqlCommand("SELECT * FROM


)(Dim xmlr As System.Xml.XmlReader = cmd.ExecuteXmlReader
)(Do While xmlr.Read
)MsgBox(xmlr.Value
Loop
)(xmlr.Close

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: ADO.NET
623


)( ExecuteXmlReader
XmlReader ADO.NET .XML

DataReader

Command )(ExecuteReader

DataReader

.

DataReader New

)( ExecuteReader Command
Command OLE DB .NET Data Provider
:OleDbDataReader

)]", cn[ Dim cmd As New OleDbCommand("SELECT * FROM


)(Dim dr As OleDbDataReader = cmd.ExecuteReader

Command SQL Server


.NET Data Provider SqlDataReader

)]", cn[ Dim cmd As New SqlCommand ("SELECT * FROM


Dim dr As SqlDataReader = cmd.ExecuteReader

IDataReader OleDbDataReader
SqlDataReader :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

624
:

)Sub ReaderDB(ByVal dr As IDataReader

End Sub


DataReader

)( Read Item
:

)(Dim dr As OleDbDataReader = cmd.ExecuteReader


)(dr.Read
) ))""(") & " " CInt(dr.Item"(MsgBox ( dr.Item
)(dr.Read
) ))""(") & " " CInt(dr.Item"(MsgBox ( dr.Item
)(dr.Close

:
) ))MsgBox ( dr(0) & " " & CInt(dr(1

)( Read

False

Do Loop :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: ADO.NET
625

)(Dim dr As OleDbDataReader = cmd.ExecuteReader

)(Do While dr.Read


)))""(") & " " CInt(dr.Item"(Msgbox (dr.Item
Loop
)(dr.Close

Item DataReader
:
) ))""(") & " " & CInt(dr"(MsgBox ( dr

Item Object

))(... CSng() CLng() CInt(

)( Getxxx :

Dim age As Integer


)""(age = CInt(dr.Item
)age = dr.GetInt32(1

DataReader )(Close

DataReader Connection
Command )( Close
.

DataReader

GetName ) (
FieldCounter IsDBNull

True ) Null
(.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

626
:

Microsoft SQL Server

SQL Server .NET Data Provider

)( GetSqlxxx :Item

)(Dim dr As SqlDataReader = cmd.ExecuteReader


)dr.GetSqlInt32(0

.NET Documantation

) (Narrowing

Microsoft SQL Server

.NET Framework SqlDecimal 38

.NET Framework 28 .Decimal

)( GetSqlxxx
System.Data.SqlTypes .System

System.Data.SqlTypes

:Microsoft SQL Server

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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

) (Microsoft SQL Server


";" :
;] < 50[ ] WHERE [ SELECT * FROM
] > 90[ ] WHERE [ SELECT * FROM

)( NextResult

False :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

628
:

)Dim cn As New SqlConnection(connString


)(cn.Open
_ "] [ Dim cmd As New SqlCommand("SELECT * FROM
_ " ] [ ] < 50; SELECT * FROM[ & "WHERE
)] > 90", cn[ & "WHERE
)(Dim dr As SqlDataReader = cmd.ExecuteReader
Do
Do While dr.Read
))""(ListBox1.Items.Add(dr.Item
Loop
Loop While dr.NextResult
)(dr.Close
)( cn.Close

ADO.NET

Connected Mode ADO.NET

Disconnected Mode .

ADO.NET ActiveX Data Objects ADO


COM
!Microsoft

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

630
:

:1- 18 .DataSet

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

ADO.NET :
631

) (1- 18
DataTableCollection DataRelationCollection

Tables :Relations

)(Dim ds As New DataSet

)MsgBox(ds.Tables.Count
)MsgBox(ds.Relations.Count


Item :
)(Dim ds As New DataSet
Dim dt As DataTable
)" "(dt = ds.Tables.Item

For Each )(... Remove() Insert() Add


:

)(Dim ds As New DataSet


Dim dt As DataTable
For Each dt In ds.Tables
)MsgBox(dt.TableName
Next

)(Dim ds As New DataSet


)(Dim dt As New DataTable

)ds.Tables.Add(dt

DataSet

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

632
:

)(Dim ds As New DataSet


Dim dc As DataColumn
").Columns "(For Each dc In ds.Tables.Item
)MsgBox(dc.ColumnName
Next

) Collection (ICollection

.DataTable

DataTable
DataTable

) Rows (DataRowCollection

) Columns (DataColumnsCollection

)( .

TableName
:

)(Dim Table1 As New DataTable


"Table1.TableName = "2
)"Dim Table2 As New DataTable("2

Primary key

DataColumns PrimaryKey
PrimaryKey
:

})(Dim pkeys() As DataColumn = {New DataColumn(), New DataColumn


)(Dim myTable As New DataTable
myTable.PrimaryKey = pkeys

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

ADO.NET :
633

ColumnChanging

ColumnChanged


RowChanged




RowChanging
RowDeleting RowDeleted .

DataRow

DataRow New
DataRow )(NewRaw

)(Dim table As New DataTable

)(Dim dr As DataRow = Employees.NewRow

Object
Rows :DataTable

}", 40, True "{ = )(Dim dr2 As Object


)table.Rows.Add(dr2

Item

" " = )""(dr.Item


") = 40"(dr.Item
") = True"(dr.Item
)""(Dim x As String = tables.Rows(0).Item

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

634
:

Item DataRow
:
" " = )""(dr
") = 40"(dr
") = True"( dr

DataColumn

DataColumn

ColumnName :

)(Dim nameField As New DataColumn


"nameField.ColumnName = "1
)"Dim nameField2 As New DataColumn("2

AutoIncrement

True
AutoIncrementSeed

AllowDBNull Unique

False Null True


:

)(Dim idField As New DataColumn


With idField
.AutoIncrement = True
.AutoIncrementSeed = 1
.AllowDBNull = False
.Unique = True
End With

DataRelation

Relationships DataRelation
ParentColumns

ChildColumns : RelationNames

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

ADO.NET :
635

)(Dim Table1 As New DataTable


)(Dim Table2 As New DataTable

Dim rel As New Relation


"rel.RelationName = "1
))" "(rel.ParentColumns(Table1.Columns
))" "(rel.ChildColumns(Table2.Columns

:
_ ",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

PDF created with pdfFactory Pro trial version

636
:

:DataSet
)(Dim myDataSet As New DataSet

:
)""(Dim myDataSetAs New DataSet

DataTable

)""(Dim Employees As New DataTable


)""(Dim Sales As New DataTable

DataColumn

)( Add Columns :

))", GetType(Integer"(With Employees.Columns.Add


.AutoIncrement = True
.AutoIncrementSeed = 1
.AllowDBNull = False
.Unique = True
End With
))", GetType(String"(With Employees.Columns.Add
.MaxLength = 100
End With
))", GetType(Integer "(Sales.Columns.Add
))", GetType(Boolean "(Sales.Columns.Add
))", GetType(Decimal"(Sales.Columns.Add


Primary Key DataColumn

:PrimaryKey

})""(Employees.PrimaryKey = New DataColumn() {Employees.Columns

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

ADO.NET :
637

Primary keys

-1
DataRelation :

_ ",Dim rel As New DataRelation("1


_ "),"(Employees.Columns
))" "(Sales.Columns

DataSet :

)myDataSet.Tables.Add(Employees
)myDataSet.Tables.Add(Sales
)myDataSet.Relations.Add(rel

:
DataSet

Dim dr As DataRow = Employees.NewRow


Dim dr2 As DataRow = Sales.NewRow
") = 1"(dr
" " = )""(dr
") = 1 "(dr2
") = True "(dr2
") = 100"(dr2
)Employees.Rows.Add(dr
)Sales.Rows.Add(dr2

:
)}" " 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

PDF created with pdfFactory Pro trial version

638
:

DataAdapter
DataSet
MSDN

DataSet
!

ADO.NET Disconnected Mode


) (3- 18 :
Connection DataAdapter DataSet

DataSet
.Connection

:3- 18 DataAdapter

.DataSet

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

ADO.NET :
639

DataSet

Client
.Server

-DataSet

DataAdapter

DataSet .

DataSet DataSet
- DataAdapter

DataSet
DataSet -

Microsoft Access

.Microsoft SQL Server

DataAdapter


DataAdapter

OLE DB .NET Data Provider


:OleDbDataAdapter

)(Dim msAccessDa As New OleDbDataAdapter

SQL Server .NET Data Provider


SqlDataAdapter :

)(Dim msSQLDa As New SqlDataAdapter

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

640
:

OleDbDataAdapter SqlDataAdapter




) DbDataAdapter

(System.Data.Common

:DataAdapter

)Sub UpdateDate(ByVal da As Common.DbDataAdapter

End Sub

DbDataAdapter Abstract Class


MustInherit
New :
! '
)(Dim x As New DbDataAdapter


) (

DataAdapter

Connection DataAdapter
:

)Dim cn As New OleDbConnection(connString


)(cn.Open

)]", cn[ Dim da As New OleDbDataAdapter("SELECT * FROM

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

ADO.NET :
641


SQL .NET Data Provider SqlConnection

SqlDataAdapter OleDbDataAdapter
:

)Dim cn As New SqlConnection(connString


)(cn.Open

)]", cn[ Dim da As New SqlDataAdapter("SELECT * FROM

DataAdapter

Connection )( Close

) Command (.

ADO.NET

)( Close .DataSet

Connection

Explicitly Connection String :

_ Dim da As New OleDbDataAdapter("SELECT * FROM ",


)" ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source


Connection DataAdapter

DataAdapter.

DataAdapter DataSet DataSet


)( Fill :DataAdapter

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

642
:

)Dim cn As New OleDbConnection(connString


)(cn.Open
)]", cn [ Dim da As New OleDbDataAdapter("SELECT * FROM
)(Dim ds As New DataSet

)" " da.Fill(ds,

)(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

PDF created with pdfFactory Pro trial version

ADO.NET :
643

End Try

.NET Documentation FillError


) DataSet .NET Framework
( DataSet

FillError DataAdapter

) DataSet )( (Fill
FillErrorEventArgs Errors

True Continue
:

)(Sub LoadDataSet

)Dim da As New OleDbDataAdapter(" ", cn


)(Dim ds As New DataSet
AddHandler da.FillError, AddressOf FillError
)" " da.Fill(ds,

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

PDF created with pdfFactory Pro trial version

644
:


DataSet
)( Update DataAdapter :

)]", cn["(Dim da As New OleDbDataAdapter


)(Dim ds As New DataSet

)"" 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

PDF created with pdfFactory Pro trial version

ADO.NET :
645

DeleteCommand RowState Added

SQL InsertCommand
) DataAdapter .(4- 18

:4- 18 .
UpdateCommand InsertCommand DeleteCommand

) Command
( .NET Framework
CommandBuilder .

:CommandBuilder
CommandBuilder SQL
INSERT SELECT

UPDATE OleDbDataAdapter
:DataAdapter

)Dim da As New OleDbDataAdapter(" ", cn


)Dim cmd As New OleDbCommandBuilder(da

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

646
:

SQL Server .NET Provider


:SqlCommandBuilder

)Dim da As New SqlDataAdapter(" ", cn


)Dim cmd As New SqlCommandBuilder(da

Commandbuilder

DataAdapter


)( GetxxxCommand

:xxxCommand

da.UpdateCommand = cmd.GetUpdateCommand
da.DeleteCommand = cmd.GetDeleteCommand
da.InsertCommand = cmd.GetInsertCommand

:

Microsoft Access

)( Fill

DataAdapter :DataSet

)Dim cn As New OleDbConnection(connString


)(cn.Open
)]", cn[ Dim da As New OleDbDataAdapter("SELECT * FROM
)(Dim ds As New DataSet
)"" da.Fill(ds,

: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

PDF created with pdfFactory Pro trial version

ADO.NET :
647

)( Update xxxCommand
:CommandBuilder

)Dim cmd As New OleDbCommandBuilder(da


da.UpdateCommand = cmd.GetUpdateCommand
da.DeleteCommand = cmd.GetDeleteCommand
da.InsertCommand = cmd.GetInsertCommand
)"" da.Update(ds,

CommandBuilder

= 4 WHERE SELECT * FROM

] [ :
] = 4 [ ] WHERE [ SELECT * FROM

QuotePrefix

QuoteSuffix :

)Dim da As New OleDbDataAdapter(" ", cn


)Dim cmd As New OleDbCommandBuilder(da
"[" = cmd.QuotePrefix
"]" = cmd.QuoteSuffix
da.UpdateCommand = cmd.GetUpdateCommand
da.DeleteCommand = cmd.GetDeleteCommand
da.InsertCommand = cmd.GetInsertCommand

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

648
:

xxxCommand
CommandBuilder
SQL xxxCommand
CommandBuilder

) SELECT (
.

Primary Key


SELECT
.DataAdapter

xxxCommand DataAdapter
Parameters .SQL

(InsertCommand CommandBuilder

) UpdateCommand (DeleteCommand
:Command

Dim delSQL As String


Dim updateSQL As String
"? = ] [ ] WHERE[ delSQL = "DELETE FROM
_ "] = ? WHERE[ ] = ? ,[ ] SET[ updateSQL = "UPDATE
"? = ] [ " &
)Dim cmdDel As New OleDbCommand(delSQL, cn
)Dim cmdUpd As New OleDbCommand(updateSQL, cn

Command Parameters
) ? ( Parameters Collection
:

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

ADO.NET :
649

))With cmdDel.Parameters.Add("@p1", GetType(Integer


"" = .SourceColumn
End With
))With cmdUpd.Parameters.Add("@p1", GetType(String
"" = .SourceColumn
End With
))With cmdUpd.Parameters.Add("@p2", GetType(Integer
"" = .SourceColumn
End With
))With cmdUpd.Parameters.Add("@p3", GetType(Integer
" " = .SourceColumn
End With


)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

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

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 :

Dim WithEvents da As OleDbDataAdapter


_ Private Sub da_RowUpdated(ByVal sender As Object,
_ )ByVal e As System.Data.OleDb.OleDbRowUpdatedEventArgs
Handles da.RowUpdated

End Sub

RowUpdated

) (
StatementType

Insert Delete Update

. Select .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

19

XML

. ADO.NET

XML

.Web Services

Windows

Forms XML
.ADO.NET

Data Binding Data Source


Windows Form
) ... ListBox TextBox(.

Windows Forms


) Next Back

... ( ) .(1- 19

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

654
:

:1- 19 .

One-way data binding Two-way data

.binding

ReadOnly
.
.

Simple Binding Complex Binding

-
Text TextBox .
) (

- Items ListBox
.

IList

Array ADO.NET -

. .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: XML
655


Visual Studio .NET

) .(2- 19

:2- 19 .Data Binding


BindingContext

) (

BindingContext

BindingManagerBase

- Position
.

Windows Forms DataBindings

.ControlBindingCollection

Binding
.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

XML :
657

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
Private m_married As Boolean
Property Married() As Boolean
Get
Return m_married
End Get
Set(ByVal Value As Boolean)
m_married = Value
End Set
End Property
Sub New(ByVal name As String, ByVal age As Integer, _
ByVal married As Boolean)
Me.Name = name
Me.Age = age
Me.Married = married
End Sub
End Class

:
Public Class Form1
Inherits System.Windows.Forms.Form

Dim Persons() As Person = {New Person("A", 1, True), _


New Person("B", 2, False), New Person("C", 3, True)}
End Class

Binding CheckBox TextBox


DataBindings

) DataBindings Add() New


Binding (ControlBindingCollection

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

658
:

Public Class Form1


Inherits System.Windows.Forms.Form

Private Sub Form1_Load(ByVal sender As System.Object, _


ByVal e As System.EventArgs) Handles MyBase.Load
Dim b As New Binding("Text", Persons, "Name")
txtName.DataBindings.Add(b)
txtAge.DataBindings.Add("Text", Persons, "Age")
CheckBox1.DataBindings.Add("Checked", Persons, "Married")
End Sub
End Class

Button
BindingManagerBase Position

:BindingContext

Public Class Form1


Inherits System.Windows.Forms.Form

Private Sub cmdNext_Click(ByVal sender As System.Object, _


ByVal e As System.EventArgs) Handles cmdNext.Click
Me.BindingContext(Persons).Position += 1
End Sub
Private Sub cmdBack_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cmdBack.Click
Me.BindingContext(Persons).Position -= 1
End Sub
Private Sub cmdLast_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cmdLast.Click
Me.BindingContext(Persons).Position = _
Me.BindingContext(Persons).Count - 1
End Sub

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

: XML
659

_ Private Sub cmdFirst_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles cmdFirst.Click
Me.BindingContext(Persons).Position = 0
End Sub
End Class

ADO.NET
ADO.NET Persons

:DataSet

)Dim cn As New OleDbConnection(connString


)(cn.Open
)]", cn[ Dim da As New OleDbDataAdapter("SELECT * FROM
)(Dim ds As New DataSet
)"" da.Fill(ds,
)(cn.Close
)"." txtName.DataBindings.Add("Text", ds,

Two-way data binding

DataSet ADO.NET

Disconnected Mode
)( Update DataAdapter

ADO.NET .

Visual Studio .NET



) Server Explorer
(View Drag & Drop

) .NET Documentation (.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

660
:

) BindingManagerBase (2- 19
)( AddNew

)( CancelCurrentEdit )( RemoveAt

PositionChanged :

Dim WithEvents Bmb As BindingManagerBase


_ Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load

)(Dim ds As New DataSet

)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

ComboBox ListBox DataGrid

Relationships

Simple Binding

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: XML
661

) .(A 4- 19
ComboBox

) .(B 4- 19

:4- 19 ComboBox .
ComboBox

ValueMember DisplayMember : .DataSource


) (
) (
. :

)]", cn [ Dim da2 As New OleDbDataAdapter("SELECT * FROM


)(Dim ds2 As New DataSet
)" " da2.Fill(ds2,
"] []. [" = ComboBox1.DisplayMember
"] []. [" = ComboBox1.ValueMember
ComboBox1.DataSource = ds2

ComboBox1
) ( " "

:SelectedValue

ds '
_ ComboBox1.DataBindings.Add("SelectedValue", ds,
)"] []. ["

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

.NET Framework .XML

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: XML
663

XML :
Imports System.XML
: XML
XML
.

XmlTextReader

- StreamReader

BinaryReader
XmlTextReader .XML

XmlTextReader

StreamReader BinaryReader

DataReader Connected Mode

.ADO.NET

DataReader Command

XmlTextReader :

)"Dim xmlData As New XmlTextReader("C:\mydata.xml

XML

Do Loop )( Read :DataReader

)"Dim xmlData As New XmlTextReader("C:\mydata.xml


Do While xmlData.Read

Loop

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

664
:

XML

XML Document XML Element XML


Attribute ... Comment :NodeType
Do While xmlData.Read
Select Case xmlData.NodeType
Case XmlNodeType.Document

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
:

_ Dim xmlData As New XmlTextWriter("C:\Test.xml",


)System.Text.Encoding.UTF8

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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

PDF created with pdfFactory Pro trial version

666
:

XML
XML

:DataSet WriteXml()

Dim cn As New OleDbConnection(connString)


cn.Open()
Dim daEmp As New OleDbDataAdapter("SELECT * FROM [Employees]")
Dim daDep As New OleDbDataAdapter("SELECT * FROM [Departments]")
Dim ds As New DataSet()
daEmp.Fill(ds, "Employees")
daDep.Fill(ds, "Departments")
cn.Close()
ds.Relations.Add("1", ds.Tables("Departments").Columns("ID"), _
ds.Tables("Employees").Columns("DepartmentID"))
ds.WriteXml("C:\test.xml")

DataSet
: xml

<?xml version="1.0" encoding="utf-8" ?>


<NewDataSet>
<Employees>
<Name>< /Name>
<Age>99</Age>
<DepartmentID>1</DepartmentID>
</Employees>
<Employees>
<Name>< /Name>
<Age>88</Age>
<DepartmentID>2</DepartmentID>
</Employees>
<Employees>
<Name>< /Name>
<Age>77</Age>
<DepartmentID>2</DepartmentID>
</Employees>

<Departments>
<ID>1</ID>
<Name>< /Name>
</Departments>
<Departments>
<ID>2</ID>

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

668
:

></Departments

></NewDataSet

XML

)( WriteXml

XML DataSet ReadXml:

Dim ds As New DataSet


)"ds.ReadXml ("C:\test.xml

DataSet test.xml

.DataAdapter


ADO.NET

ADO.NET

.MSDN Windows Forms ADO.NET


.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

672
:

IIS

ASP.NET Web Server


Web Server Internet
Information Server .Microsoft

- IIS
.ASP.NET

Windows 2000 IIS

.Windows

IIS Add or Remove Programs

Control Panel Add/Remove Windows

Components Internet Information Services


)) (IIS .(20- 1

:1- 20 .IIS

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: (1) ASP.NET
673

IIS


Web Server
.

Internet Explorer

http://localhost

IIS
.Web Server
Microsoft .

Local Network Dial-


up Networking Bypass proxy server for
local addresses
.Internet Explorer



.URL

Virtual
Directory .

Folder

Properties Web Sharing

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

674
:

Share this folder


) Add .(2- 20

:2- 20 .
Alias

URL test

http://localhost/test

test.html
:

http://localhost/test/test.html

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: (1) ASP.NET
675

IIS
... Index.html Default.html.

IP Address :

http://999.999.999.999/test/test.html

IIS Internet

Information Services Administrative Tools Control


) Panel .(3- 20

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

676
:

:3- 20 .IIS

Properties IIS

) (4- 20
IIS .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: (1) ASP.NET
677

:4- 20 .

Web Forms
ASP.NET

Windows

Forms - Web Forms


.Browser

Windows Forms

Web Forms HTML


.

Web Forms Windows Forms

.NET Framework

Windows Windows Form

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

678
:

.aspx Web

form page 10 Web forms 10


*.aspx -
Header -Footer .

Notepad ASP.NET
)Console Windows Applications
.NET

... Application( Visual Studio

.NET .

New->Project File

) New Project (5- 20 ASP.NET Web Application


Name
Location URL )

(Virtual Directory http://localhost/test


- .Browse

:5- 20 .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: (1) ASP.NET
679

Internet Explorer
Work Offline

Internet Explorer Work Offline
.File

OK Visual Studio .NET

) (6- 20
AssemblyInfo.vb
Windows Application Styles.css

Cascading Style Sheet WebForm1.aspx Web


Form .

:6- 20 .Solution Explorer

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

680
:

(CSS) Cascading Style Sheet


.HTML
MSDN
.

Web

Form Design HTML


Visual HTML

HTML

) - 20
.(7

:7- 20 Design .HTML

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: (1) ASP.NET
681



Target Page Layout

Schema Client Script Language

Designer Defaults Project Property


) Pages .(8- 20

:8- 20 .
HTML

Page Layout Flow


Grid

HTML

Grid Windows

Forms Web
.Forms

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

682
:

Target Schema

Internet Explorer 3.03 Netscape

Navigator 3

Internet Explorer
5 .

) Client

( JScript

Internet Explorer ) (

Client Script Language .VBScript

Web Form
Windows Form Label

Button TextBox
:Click

_ Private Sub Button1_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles Button1.Click
" & TextBox1.Text " = Label1.Text
End Sub

! ASP.NET

] [F5

Internet

Explorer ) http://locahost/xxx/yyy.aspx xxx

yyy (Web Page


Button

Request
.Label

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: (1) ASP.NET
683

:9- 20 Button

.Label

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

: (1) ASP.NET
685

Machine.config processModel

:userName Attribute

"<processModel enable="true

"userName="machine" password="AutoGenerate" logLevel="Errors

>/

machine :SYSTEM
"userName="SYSTEM" password="AutoGenerate" logLevel="Errors

.ASP.NET

Configuration Files
.Assemblies

ASP.NET Web Forms


- )
.(11- 20

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

686
:

:11- 20 .
HTML Web Forms


Visual Basic .NET Requests

HTML Browser :
HTML :

Web Form
:

"<%@ Page Language="vb" AutoEventWireup="false


>Codebehind="WebForm1.aspx.vb" Inherits="test.WebForm1"%
>"<HTML dir="rtl
><HEAD
><title>WebForm1</title

></HEAD
>"<body MS_POSITIONING="GridLayout
>"<form id="Form1" method="post" runat="server

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: (1) ASP.NET
687

><asp:Label id="Label1" runat="server"></asp:Label


><asp:Button id="Button1" runat="server"></asp:Button
><asp:TextBox id="TextBox1" runat="server"></asp:TextBox
></form
></body
></HTML

HTML

ID runat

" "server
Server .Client

Web Form .aspx

:Visual Basic .NET


: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
- -

Clients Windows Forms

Message Box

HTML Client .Browser

.aspx.vb test.aspx . test.aspx.vb

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

<span id="Label1" style="font-size:Large;font;weight:bold;height:72px;width:335px;Z-INDEX: 101; LEFT: 92px


></span >"POSITION: absolute; TOP: 48px

></form
></body
></HTML


aspx

ASP.NET

@Page
:aspx

"<%@Page Language="vb" AutoEventWireup="false


>Codebehind="test.aspx.vb" Inherits="test.WebForm1"%

:Code-Behind Classes
Visual Studio .NET

) Visual Basic .NET (*.aspx.vb

.DLL aspx ASP.NET


Inherits @Page
Button .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: (1) ASP.NET
689

Visual Basic .NET Code-


.Behind
:On-Demand Compilation

DLL src

@Page :
_

"<%@ Page Language="vb" src="WebForm1.aspx.vb


>Inherits="test.WebForm1"%

aspx src

DLL

. *.aspx.vb

:Classic ASP Style


ASP

ASP

Visual Basic .NET aspx .


>:<SCRIPT RUNAT="server"> </SCRIPT

><%@ Page Language="vb"%

>"<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

PDF created with pdfFactory Pro trial version

690
:

ASP.NET

. ) Server side script ASP

... CGI Perl PHP(


.

Page
System.Windows.Forms.Form Windows Form

System.Web.UI.Page :Web Form

Public Class WebForm1


Inherits System.Web.UI.Page

End Class

Windows

Forms
.

Page

.
.@Page

dir
rtl Culture

Regional Settings .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: (1) ASP.NET
691

Exception

ASP.NET
:ErrorPage
"me.ErrorPage = "http://www.dev4arabs.com/error.aspx

IsPostBack

Submit
True .

Controls

For Each Next :


Dim ctl As Control
For Each ctl In Me.Controls

Next

) Server Response Request

HttpResponse HttpRequest



(Application Session

HttpApplicationState HttpSessionState HttpServerUtility


(2) ASP.NET .

EnableViewState :ViewState


TextBox
Submit

TextBox

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

692
:

) (Submit

EnableViewState True

Me.EnableViewState = True

EnableViewState True
False

Listbox1.EnableViewState = False

True EnableViewState

ViewState

-
:

If Me.ViewState("Counter") Is Nothing Then


)Me.ViewState("Counter") = CInt(1
Else
)Me.ViewState("Counter") = CInt(Me.ViewState("Counter") + 1
End If
))"Label1.Text = CStr(Me.ViewState("Counter

ViewState Dictionary
Collection
)(... Insert() Add .
Dictionary
MSDN .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: (1) ASP.NET
693

:SmartNavigation
Submit


ScrollBars

True SmartNavigation .

SmartNavigation
InternetExplorer .


)( MapPath Virtual

Directory )( :

))"Dim F As New System.IO.StreamReader(Me.MapPath("/test/file.txt

- )( HasControls True

Init

Load

.IsPostBack

Unload

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

694
:

ErrorPage

.Error

@Page
SmartNavigation @Page
:

><%@ Page Language="vb" smartNavigation="True"%

@Page aspx
.

@Import ) Imports

(Visual Basic .NET :aspx

><%@ Import namespace=" System.Data.OleDb"%

Implements ) Implements Visual

(Basic .NET Interface :

><%@ Implements Interface="System.IDisposable"%


aspx
aspx.vb Visual Basic .NET
Visual
!Basic .NET

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: (1) ASP.NET
695

Reference

)
:(Reference
><%@ Reference page="WebForm2.aspx" %

Web Forms

Windows Forms
Web Forms
! -

MouseMove Web Form )


( .

Web Forms Controls

Web Forms

ToolBox .Windows Forms

) (ID ) (Name

HTML BorderStyle
BorderWidth .

cssClass Class Style

CSS . Font

) ... Medium Big Small(


pt )... 20pt 10pt(.

CheckBox

RadioButton Checked True

RadioButton

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

696
:

RadioButton !

RadioButton .GroupName

HTML

HTML Table ><table


Label > <span Image > <img

HyperLink > <a Panel > <Panel ...

HTML .

HTML Forms Controls


Server HTML Forms Controls

) ( .

.NET
J Script VBScript .Java Script

HTML Toolbox

).(10- 20

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: (1) ASP.NET
697

:12- 20 HTML Forms HTML

Validation

Web Forms Toolbox


xxxValidator -
TextBox

Jscript VBScript .

RequiredFieldValidator

) ( RangeValidator

CompareValidator

CustomValidator Validation )

(.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

698
:

) (RequiredFieldValidator
Empty
. Script
Scripts
.

BaseValidator

ControlToValidate
ErrorMessage .
Submit ) .(13- 20

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: (1) ASP.NET
699

:13- 20 .RequiredFieldValidator

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

700
:

ASP.NET Applications

Web Forms .
Web Forms
ASP.NET .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

21

(2) ASP.NET
ASP.NET

Web Forms ASP.NET


ASP.NET.

ASP.NET

Application Server Response Request

Session HttpServerUtility HttpResponse HttpRequest

HttpApplicationState HttpSessionState
.NET Documentation

HttpRequest

HttpRequest Client Browser

-ReadOnly
.

HttpMethod -String GET


:POST

POST Label1.Text = Me.Request.HttpMethod ' GET

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

702
:

POST Submit
GET URL :

http://www.dev4arabs.com/test.asp?id=1&site=vb

GET

:QueryString

)"Label1.Text = "ID & = " & Me.Request.QueryString("id


)"Label 1.Text = "Site & = " & Me.Request.QueryString("site

) 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

PDF created with pdfFactory Pro trial version

: (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 :

)"></b></p >Me.Response.Write ("<p><b


)"></b></p >Me.Response.Write ("<p><b
)"Me.Response.WriteFile ("data.html

)( Redirect

End :

)"Me.Response.Redirect("http://www.dev4arabs.com/accessDenied.aspx
)(Me.Response.End

Cookies HttpCookie

Cookie Expires Cookies


:

)" " Dim userName As New HttpCookie("NAME",


)"Dim userPassword As New HttpCookie("PASSWORD", "1234
)userName.Expires = Date.Now.AddYears(1
)userPassword.Expires = Date.Now.AddYears(1
)Response.Cookies.Add(userName
)Response.Cookies.Add(userPassword

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

: (2) ASP.NET
705

:1- 21 IIS .ASP.NET Application

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

PDF created with pdfFactory Pro trial version

706
:

)( Item

HttpSessionState

HttpApplicationState HttpSessionState

HttpSessionState

) .(1- 21

:2- 21 HttpSessionState .




HttpSessionState

HttpApplicationState
HttpSessionState
:

" " = )"Me.Session("Name


"Me.Session("Password") = "123

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: (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

PDF created with pdfFactory Pro trial version

708
:

Application_Start()

Session_Start() Application_End()

HttpSessionState Session_End()

-
: -

Public Class Global


Inherits System.Web.HttpApplication

Sub Application_Start(ByVal sender As Object, ByVal _


e As EventArgs)
Me.Application("CurrentVisitors") = 0
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Me.Application.Lock()
Me.Application("CurrentVisitors") = _
CInt(Me.Application("CurrentVisitors") + 1)
Me.Application.UnLock()
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
Me.Application.Lock()
Me.Application("CurrentVisitors") = _
CInt(Me.Application("CurrentVisitors") - 1)
Me.Application.UnLock()
End Sub
End Class

Global_Error()

Error Web Form

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

: (2) ASP.NET
709

)( Global_Error

GetLastError

Server HttpUnhandledException

InnerException :

Public Class Global


Inherits System.Web.HttpApplication

)Sub Global_Error(ByVal sender As Object, ByVal e As EventArgs


Dim exp As Exception
exp = Me.Server.GetLastError.InnerException
)Response.Write(exp.Message
)(Response.End
End Sub
End Class

Security
ASP.NET
IIS Windows

Visual

Basic .NET

- .ASP.NET


Authentication

.Authorization

) ( User

Account Windows Server


Guest

.Anonymous Requests

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

710
:

IIS .

Authentication

Authorization
aspx
.

Windows IIS
Administrator
.

ASP.NET
IIS Windows
Authentication

Configuration Files .

ASP.NET

Forms Windows None .Passport

Authentication Authorization
IIS .Windows

-Windows Authentication

IIS .Authorization
) (

.Windows

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: (2) ASP.NET
711

Forms -

Authentication Authorization
.

Passport Authentication

Microsoft Passport User

Account Microsoft Messenger


Microsoft Passport )
.(http://www.passport.com


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

PDF created with pdfFactory Pro trial version

712
:

Cookies
.

Authentication

web.config authentication
:authorization

><configuration
><system.web

><authentication mode="Windows" /
><authorization
><allow users="*" /
></authorization

></system.web
></configuration

Windows Forms > <forms


:

><configuration
><system.web

>"<authentication mode="Forms
><forms loginUrl="/login.aspx" name="dev4arabs" timeout="10"/
></authentication

></system.web

> <forms loginUrl

name

Cookie
timeout -
Session .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: (2) ASP.NET
713

> <allow > <authorization > <deny


:Anonymous Request
><configuration
><system.web

>"<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

PDF created with pdfFactory Pro trial version

714
:

passwordFormat

" "Clear.

Login

loginUrl > <forms TextBox

) (3- 21
!

:3- 21 .

> <credentials
)( Authenticate
System.Web.Security.FormsAuthentication

True :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: (2) ASP.NET
715

Imports System.Web.Security

_ Private Sub Button1_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles Button1.Click
_ If FormsAuthentication.Authenticate(txtName.Text,
txtPassword.Text) Then
)FormsAuthentication.RedirectFromLoginPage(txtName.Text, True
Else
" " = Label1.Text
End If
End Sub

)( RedirectFromLoginPage True

Cookie .


: Caching
.Http Modules

Caching
ASP.NET HTML


Caching

.Server

@OutputCache

aspx -
Refresh
:VaryByParam

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

716
:

><%@ OutputCache Duration="10" VaryByParam="none"%


10 Label Button :

_ Private Sub Button1_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles Button1.Click
">Label1.Text &= Date.Now & "<br
End Sub

) 4- 21 ( @OutputCache

) 4- 21(.

VaryByParam

><%@ OutputCache Duration="10" VaryByParam="id"%

:
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

PDF created with pdfFactory Pro trial version

: (2) ASP.NET
717

:4- 21 Cached .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

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

PDF created with pdfFactory Pro trial version

: (2) ASP.NET
719

)"Dim bmp As Bitmap = Bitmap.FromFile("dev4arabs.jpg


Dim showPic As Boolean = True
'
If showPic Then
"Response.ContentType = "image/jpeg
)bmp.Save(Me.Response.OutputStream, Imaging.ImageFormat.Jpeg
End If

:5- 21 .
) (5- 21 aspx .JPG
URL

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

720
:

! GDI+

) :(6- 21

:6- 21 .
-

:GDI+

Dim bmp As New Bitmap(400, 300,


)Drawing.Imaging.PixelFormat.Format16bppRgb565
)Dim gr As Graphics = Graphics.FromImage(bmp
)Dim Font As New Font("Tahoma", 16
" " = Dim text As String
)gr.Clear(Color.LightGray
'
Dim angle As Single
For angle = 0 To 360 Step 30
)(gr.ResetTransform
)gr.TranslateTransform(200, 150
)gr.RotateTransform(angle
)gr.DrawString(text, Font, Brushes.Black, 0, 0
Next

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: (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

PDF created with pdfFactory Pro trial version

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

22

Web Services

ASP.NET

Web Services

:
Imports System.Web.Services


Visual Basic .NET )

(XML Web Service Requests

Response HTTP XML


.

Visual Basic .NET

HTTP XML Web Services


.Visual Basic .NET

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

724
:


DLL

.

- - VBNETBook )(GetUpdates


Visual Basic .NET :

Dim book As New VBNETBook


Dim x As String
)(For Each x In VBNETBook.GetUpdates
) ArabicConsole.WriteLine ( x
Next

.NET

HTTP

) XML :(1- 22

:1- 22 .

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Web Services
725

.NET


HTTP .XML


ASP.NET

ASP.NET New-

>Project File ASP.NET Web Service


) http://localhost/Exchanger .(2- 22

:2- 22 .ASP.NET Web Service

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

726
:

Internet Information Server


.

OK Visual Studio .NET

ASP.NET web.config

) global.asax (3- 22 ASP.NET.

:3- 22 .
Service1.asmx

Class Library

.HTTP

Service1.asmx

SaudiRiyals.asmx.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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

PDF created with pdfFactory Pro trial version

728
:

)( FromEG )( FromBRN


.Decimal

WebService WebMethod

- Web Service

Class .


SaudiRiyals
Internet Explorer
]) [F5 .(4- 22

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Web Services
729

:4- 22 .Internet Explorer


URL
SaudiRiyals.asmx SaudiRiyals
)( FromBRN )( FromEG
WebMethod .

ASP.NET

Reflection Classes

Visual Studio .NET


.Internet Explorer

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

730
:

.NET Framework

.

FromBRN

) .(5- 22

:5- 22 )(.FromBRN

Object Classes

Primitive

) Types ... Decimal String Long Integer( 30


amount Invoke )

6- 22 (.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Web Services
731

:6- 22 300 .

)( FromEG XML
-
.XML

Requests Responses XML

HTTP HTTP
.NET

Windows Macintosh

Linux Unix HTTP XML

Visual Basic

.NET Windows Service

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

732
:

Class Library ASP.NET Application

.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

PDF created with pdfFactory Pro trial version

: Web Services
733

:8- 22 .Add Web Reference


Add Reference

Web References

) Solution Explorer .(9- 22

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

734
:

:9- 22 .SaudiRiyals

) (9-22
Show All files .Solution Explorer

TextBox Button Click:

_ Private Sub Button1_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles Button1.Click
)(Dim test As New LocalHost.SaudiRiyals
))txtEG.Text = CDec(test.FromEG(txtSaudi.Text
))txtBRN.Text = CDec(test.FromBRN(txtSaudi.Text
End Sub

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: Web Services
735

TextBox

Button
) .(10- 22

:10- 22 .Windows Application

) Windows Application (
.

) 9- 22 ( Update Web
Reference .

735 Web Services


.NET

.Visual Basic .NET


.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

PDF created with pdfFactory Pro trial version

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

></p >: </b></p> <p><p><b


>: </b></p> <p>99</p><p><b

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

2-

:
></p >: </b></p> <p><p><b
>: </b></p> <p>99</p><p><b

>: </b>: </b></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

PDF created with pdfFactory Pro trial version

XML :
3-

<table border="1" cellpadding="0" cellspacing="0" style="bordercollapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber


2"><tr><td width="100%">
<table border="1" cellpadding="0" cellsp
acing="0" style="border-collapse: collapse" bordercolor="#111111" wid
th="100%" id="AutoNumber3"><tr><td width="100%"><table border="1"
cellpadding="0" cellspacing="0" style="border-collapse: collapse"
bordercolor="#111111" width="100%" id="AutoNumber4"><tr><td width=
"100%"> <table border="1" cellpadding="0" cellspacing="0" style
="bordercollapse:collapse"bordercolor="#111111"width="100%"id="AutoNu
mber5"><tr><td width="100%"> <table border="1" cellpadding="0"
cellspa
cing="0" style="border-collapse: collapse" bordercolor="#111111" width
="100%" id="AutoNumber6"><tr><td width="100" height="51"bordercolordar
k="#008000" bgcolor="#00FF00" align="center"><h1 dir="rtl" align="cent
er"><font face="Tahoma" size="4"color="#FFFFFF"></font></h1></td><
/tr><tr><td width="100" height="51" bordercolordark="#008000" bgcolor
="#00FF00"align="center"><b><fontface="Tahoma"size="4"color="#FFFFFF">
</font></b></td></tr><tr><td>width="100%">&nbsp;</td></tr></table
>
</td></tr></table></td></tr></table></td></tr></table></td></tr>
</table>

!!! Browser

XML
XML

PDF created with pdfFactory Pro trial version

99

88

77

w w.pdf actory.com

4-

1 :

3 :

2 :

99 :
88 :
77 :

XML
:

>? "<?xml version="1.0" encoding="utf-8


><table
><record
><ID>1</ID
></name ><name
><age>99</age
></record
><record
><ID>2</ID
></name > < name
><age>88</age
></record
><record
><ID>3</ID
></name ><name
><age>77</age
></record
></table

XML

HTML > <HTML . version


XML encoding

test.xml

XML )
(.

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: XML
5-

Elements
XML

> <xxx
.XML Elements

HTML XML case-sensitive

Capital .Small
XML :/

><test

></test

:
><test /

:
><aa
><bb
><cc /
></bb
></aa

Attributes
Attributes

X Y 10 ) 20 (:

><myelement x="10" y="20">value</myelemnt

PrimaryKey :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

6-

>? "<?xml version="1.0" encoding="utf-8


><table
><record
><ID Primarykey="True">1</ID
></name ><name
><age>99</age
></record
><record
><ID Primarykey="True">2</ID
></name > < name
><age>88</age
></record
><record
><ID Primarykey="True">3</ID
></name ><name
><age>77</age
></record
></table

Comments

Comments XML

> -- :<!--

><test
<!-

>--
></test

XML

.XML

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

SQL

.(SQL) Structured Query Language

.
SQL -MSDN

SQL SQL
SQL
.SQL

SQL
(DDF) Data Definition Language Data

.(DML) Manipulation Language DDF

Tables Fields
DML Records

DML

DDF
.DDF

SELECT

SELECT SQL
. "

" :

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

8-

] [ SELECT * FROM

] [ ] FROM [ ],[ SELECT

WHERE

"":

] [ SELECT * FROM
WHERE
'' = ][

OR AND <... LIKE > :


] [ SELECT * FROM
WHERE
'' = ][
'] LIKE '%[ AND
] < 9000[ OR

:BETWEEN
] [ SELECT * FROM
WHERE
] BETWEEN 2000 AND 10000[

:IN
] [ SELECT * FROM
WHERE
)'' ',' ','( ] IN[

:BY

)( ORDER
][ ] ORDER BY [ SELECT * FROM

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

: 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

PDF created with pdfFactory Pro trial version

10 -

DELETE
DELETE :
] [ DELETE FROM

:WHERE
] [ DELETE FROM
WHERE
] < 18[

SQL
ANSI-92 .NET Data

Providers .ADO.NET DML


DDF

w w.pdf actory.com

PDF created with pdfFactory Pro trial version

PDF created with pdfFactory Pro trial version

w w.pdf actory.com

You might also like