VB2010 Toturial

You might also like

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

http://algoharism.blogspot.

com

" Microsoft Visual Basic 2010 Express


"
Visual Basic


.


.visual basic
Microsoft Visual Studio Express 2010
:
http://www.microsoft.com/express/Downloads

:
http://algoharism.blogspot.com :
http://www.facebook.com/algoharism :
algoharism@gmail.com :


3122



.2:

.........................
................................
7
................................................................................................

.3

................................
...
9 ................................................................................................

.3 Hello world

...............................
22................................................................................................

.5

.........................
................................
26
................................................................................................


.2 Properties

................................
28.. ................................................................................................

.3 ( )

................................
33. ................................................................

.4 ( )
.5
.6

................................
............
36
................................

......................
................................
43
................................................................

.........................
................................
4:
................................................................................................


.2 Events

................................
......
52
................................................................................................

.3

................................
...........
54
................................................................................................

.4

..........................
................................
59
................................................................

.5

.........................
................................
62
................................................................................................


.2 Variables
.3

.....................
................................
64
................................................................
................................
67
.... ................................................................................................

.4
.4

......................
................................
6:
................................................................
...........................
................................
75
................................................................

.6

.........................
................................
76
................................................................................................


.2

..........................
................................
78
................................................................................................

.2.2 IfThen :

............................
79
................................................................................................

.3.2 Select Case :

.......................
................................
83
................................................................

.4 Arrays

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

.2.5 for/each :
.3.5 for/next :
.6

................................
...............
88
................................................................
.........................
................................
89
................................................................
................................
..............
91
................................................................

.7

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


.2
.2
.4
.5
.6
.7

................................
...........
96
................................................................................................
................................
..............
97
................................................................................................
................................
........
:1
................................................................................................
................................
.....
:2 ................................................................................................
................................
..........
:3
................................................................................................
................................
:5
.... ................................................................................................

.........................
................................
:8
................................................................................................

Microsoft
VB Express
2010

algoharism.blogspot.com


.Hello World

algoharism.blogspot.com

Microsoft Visual Basic 2010 Express

:.1
1. Start menu >> Programs >> Microsoft Visual Studio 2010 Express >> Microsoft Visual Basic
2010 Express
2. New Project

3. Windows Forms Application

4.

3
1

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.2
.
.

Solution Explorer

- 2


Solution Explorer - 3

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

- 4 Properties
( ...)

- 5

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

Toolbox

- 6 ( \ )

10

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.3 Hello world
Visual Basic
.

- 2 () . Toolbox
- 3 Common Controls
- 4 .

Button

Button

Double click
.Button

11

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

- 5 Double Click

- 6
)"! Hello World "(MessageBox.Show

12

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

- 7 Debug

Debug
.
F5 .Debug

- 8 Button 1 .

- 9 X

13

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

- : File >> Save All

- 21

.Save

14

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.4
3 Buttons (
) ( ) .
.
Hello World .

15

Microsoft
VB Express
2010

algoharism.blogspot.com

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.1 Properties

.

Button
.

17

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

- 1 :Location
()
X : X( Y
Y )(
.

18

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

X= 81

Y= 94

- 2 :Text
.

19

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

- 3 :Backcolor

- 4 :Forecolor

- 5 :Font

20

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

- 6 ):(Name

.

BtnOk

OK
.

21

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.2 ( )
.

Button

()
label
TextBox

22

Microsoft Visual Basic 2010 Express

Radio button
List Box
Combo Box

algoharism.blogspot.com





ListBox Textbox

: " ":
.2 :
Text box

Labels

Combo Box

List box

Radio Box

Check Box

Button

.3 .Combo box
Combo box

Edit items

23

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

( ):

List Box

24

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.3 (
)
menu ToolBox
.

25

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com



Ctrl+S

:
Menu strip
Status Strip
Tool Strip




: " " :Menu strip
- 2 Menu Strip

- 3 Type Here
- 4 4 :

26

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

- 5 MenuStrip1

- 6 Right Click Insert Standard Items


27

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

28

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

: " " :tool Strip


- 2 Tool Strip

- 3
- 4 :

- 5 ()
:

29

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

: " " :Status Strip


- 2 Status Strip

- 3 Status Strip .

30

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

( List Box , Combo Box , Menu Strip ,


)....Status strip

Edit Items .

31

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.4


( ).
:
- 2 " ":

Text Boxes

Labels

Buttons

Labels
Buttons
( . ).

.

32

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

- 3 (
button "" " ")
.
- 4
( button
).


:
:Tab key- 2
Tab Text Boxes
.
Tab :
- 2 Debug
F5 .
- 3 :

( )

33

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

- 4 Tab ( | )
:

- 5 view Tab order

34

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

Tab order tools Settings expert settings


view tab order
- 6

35

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

- 7 .

:LayoutToolbar- 3
.
layout view toolbars layout

36

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

Layout Toolbar :

Aligns left - 2
- :

Ctrl
.

37

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

Aligns right - 3
Aligns top - 4

: .
: .

38

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.5

( credit card )
(.)Tab order

39

Microsoft
VB Express
2010

algoharism.blogspot.com


Events Events

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.1 Events
( )
Visual Basic Express " " Event Driven
.Programs
Event
.
: " "Hello World :

- 2 Double Click Button 1 :

- 3 :

- Events

41

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com
:Button 1 Button 1

: Click ( )

Public Class
End Class
Method

Private Sub End Sub


Code Block

(Click )
Button 1

: Method Public
class End Class
Code Block
Button1_Click
( Click )Event Button 1 Show
MessageBox ( Hello World Response ) Click

F7 Shift+F7

( ) .
- :

- Events

42

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.2

.

properties


Events

Events Properties
.

- Events

43

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

- Event

Events

Double Click

( Button 1 " TextBox1 !"):


- 2 :

- Events

44

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com


Lesson03

- 3 :

Button
1
TextBox 1

- Events

45

Microsoft Visual Basic 2010 Express

- 4 :

algoharism.blogspot.com


Click
Button1

text
TextBox1
" !"

Click Button1 text TextBox1


- 5 Debug

- Events

46

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

- :

" "




()
. Event

- Events

47

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.3
.
- 2 :
( )
.
" " :



.
:

- Events

48

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

( ) http:// : .
- 3 :
.
:
Tools >> Options :

1
2

:
- Events

49

algoharism.blogspot.com

50

Microsoft Visual Basic 2010 Express

Events -

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.4
-2 events button Button1
:
)MessageBox.show("Name of Event
:

Click
Enter
Leave
MouseHover

Event Event F1 .

-3 textbox :
)MessageBox.show("Name of Event
Events:

keyPress
KeyDown
KeyUp
TextChanged

- Events

51

Microsoft
VB Express
2010

algoharism.blogspot.com


...

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.1 Variables
Variable
( )


.
:
.2
.3
.4
.5

() A,B, ..Y,Z or a,b,.,y,z :


().... : !
End , Byte
.

Data types

2 byte
4 byte
1 byte
4 byte
8 byte
8 byte
1 byte
8 byte



Integer

Long
\
true 2 false 1
Boolean

Single

double

Currency


String

Date
....

Object

variant

:
Dim VariableName As DataType

53

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

:


\

Data types
Integer
Boolean
double
String

Dim myIntegr As Integer = 3


Dim myBoolean As Boolean = true
Dim myDouble As Double = 3.14
Dim myString As String = Algoharism

Variable . String " ". capital smallmyIntegr=myintegr

:
Lesson04 - :

Double Click Button 1 - :

54

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

String string " "



:

hello hello world

55

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.2
.
:

Button1 :

56

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

39 :43
' Example 2
Dim firstTextBox As String = TextBox1.Text
Dim secondTextBox As String = TextBox2.Text
Label1.Text = firstTextBox & " " & secondTextBox

firstTextBox String
Text TextBox1
secondTextBox String
Text TextBox2
Label1 :Text
( firstTextBox )Textbox1
( + &) ( )
+ secondTExtBox
Debug
F5 :

33: 37

57

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

" "2
2 "
"3 3
Button1

58

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.3
(
)
.
- .


.
:
Implicity- 2 :
o
.
o .
Explicity- 3 :
o .
o
.
:

: :Implicit
- 2
- 3 :

59

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

46 myValue ( Integer 3 )
: 47 myOtherValue ( Double 9 )
4.25
: 48 myOtherValue ( myValue
9 3)
:4: myValue 3( Integer)
2 (String) Show MessageBox String

33
myOtherValue myValue
)Double (8 Bytes) Integer(2 bytes
- 4 Debug

MessageBox.Show 39
)myValue(message
)Integer (2Bytes)String (1Byte

Button 1 ""4 4.25 " "4 Double


( ) ( Integer
)
Implicit .

60

algoharism.blogspot.com

Double
3.14
(8 Bytes)
Integer
3
(2bytes)

61

Microsoft Visual Basic 2010 Express

: Integer Line 37
3
(2 bytes)
String
Line 39
4
(1 byte)

Microsoft

:
Visual
Basic
2010Express

:Explicit
algoharism.blogspot.com

- 2
- 3 :

52 53 54 4 Integer 56 : 57 firstTextBox TextBox1 secondTextBox


59 : 5: result (firstTextbox ( SecondTextBox + )Integer ) Integer
Label1 result
- 4 Debug

textbox1 textbox2 integer


string

62

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

- :

" "five Integer

63

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.4
:
statement expression :
:
Dim x As Integer
x + 3

Expression
.Statement
:
Expression

:
2<3 .....

Statement


Dim x as Integer
MyInteger=3

MessageBox.ShowHello world

:Expression (
) expression
). (data type

64

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.5
OK

.
Text box

Labels

Combo Box
( )
List box
( - - -)

Radio Box

Check Box

Button
ok cancel

65

Microsoft
VB Express
2010

algoharism.blogspot.com

statements

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.1
Statements
Statements .
- Statements Expressions

:
Branching Statements .2 .
Recursion Statements .3 .
Arrays .4 .
Recursion Statements
Branching Statements



expression

:
:
For Each .2
If.Then .2
For Next .3
Select Case .3
Do WhileLoop .4
. :lesson5
ComboBox
( )

ListBox
( -)

TextBox

Button

statements

67

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.1.2 IfThen :

.expression
Button1

IfThen "" ComboBox1


" " "" Then End If
statement VB .If..Then
: IFThen
- "":

statements

68

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

( expression ) :
""
""

If..Then :

statements

69

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

ComboBox1.text
ComboBox1

""
>< If Combox1.text
>< :

else

then

" "

""

= Messagebox.show

=If ComboBox2.text

else

then

" "
= Messagebox.show

statements

" "
= Messagebox.show

70

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

" "
"" " " "
".

statements

71

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.2.2 Select Case :


. If..Then
:

listbox )( ListBox1.SelectedItem.ToString .

"" ListBox1 " "


"" " ".


.

statements

72

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.3 Arrays

( )
Array .
array :

45

Dim:
myArray(2): myArray:
(2):
( ) As String:

(2 myArray(0): )2
=
46 myArray(1):34748
myArray(2):4
49
MEssageBox.Show(myArray(2)) 4

statements

73

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com


)myArray(2

String

()

4(2)

myArray

myArray
)myArray(1

)myArray(0

""

""

)myArray(2
3
""

3 4 1

statements

74

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

debug :4

statements

75

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com


} { debug
.4

statements

76

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.1.4 for/each :

:

myArray person
61
for each person
:

( ) ( )
.

statements

77

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.2.4 for/next :

:

:67 i integer . 1
68 :69 i 1 6
6 1 6
:6: .
:for/next
Var1


counter
Var2


counter

Counter


integer

For Counter = Var1 To Var2 Step Var3


Statements
Next

Var3

counter

statements

78

algoharism.blogspot.com

Microsoft Visual Basic 2010 Express

......

79

statements

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.5

for/next :if then

:82 myArray .
:84 i integer
:85 i for/next 1
( 2 )myArray.length
.
Arrays myArray )( myArray ( )2

86 :87 for/next ifthen


() )myArray(i ""
" ".
Exit for :88
.if..next

statements

80

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

89 :8: if .for

:)dont debug
for
if

i
= myArray 1
myArray 2
= 1 ( = )2-5 1 4
:
"" myArray i
: for
if 2
""

if 3
""

4
if
""
:

)myArray(i

0
)myArray(0
1
)myArray(1
2
)myArray(2

debug 2
( ) 1 2 1
2 3 .
( )Visual Basic .

statements

81

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

for/next select case

button1 i 1
listbox1 2

( listbox1 )Ctrl
button1 .

statements

82

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.6
2 :
:2 textboxes listbox 2 : : listbox textbox
:
+

*
/

.
-3 Dvd Array
4
label label
.

statements

83

Microsoft
VB Express
2010

algoharism.blogspot.com

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.1
.
Start menu
programs Microsoft Visual Basic 2010 Express
New Project Windows Forms Application MyFirstVBApp

85

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.2
.2 Toolbox Containers
TableLayoutPanels

Toolbox

86

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.3 properties
TableLayoutPanel1

Dock properties None


fill
:

TableLayoutPAnel .
TableLayoutPanel

.4
TableLayoutPAnel
Edit
Columns and Rows :

87

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

Column and Row Styles Column1


%26 column2 %96 Row1 %:1 Row2 %21 ok

.5 Toolbox ( PictureControl
) .
PictureControl
Dock in Parent Container

dock Properties Fill ColumnSpan


3 BorderStyle Fixed3d .

88

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.6 checkbox toolbox
(
.)picturebox
text " ".
.7 toolbox containers
FlowLAyoutPanel Dock in
parent container
FlowLayoutPanel
5
.

.8

:
FlowLayoutPanel toolbox 5( button1
button2 button3 )button4 . FlowLayoutPanel
text property " " "
" " " " ".
flowdirection
FlowlayoutPanel RightToLeft .
"" Ctrl
4
properties autosize
True .

89

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.3

"" ) (Name
closeButton " " showButton "
" clearButton " " . backgroundButton

90

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.4
DialogBoxes
.
- 2 toolbox Dialogs OpenFileDialog
ColorDialog :

OpenfileDialog1 properties Filter :


* (*.*)|*. | (*.bmp)|*.bmp (*.png)|*.png|BMP (*.jpg)|*.jpg|PNG JPEG

:Title
OpenFileDialog Paint file
open


filter

91

algoharism.blogspot.com

Microsoft Visual Basic 2010 Express

.5
:
showButton - 2
: " " showButton

OK OpenFileDialog
.PictureBox1
" " clearButton - 3
:
Private Sub clearButton_Click() Handles clearButton.Click
' Clear the picture.
PictureBox1.Image = Nothing
End Sub

.
:" " backgroundButton - 4
Private Sub backgroundButton_Click() Handles backgroundButton.Click
' Show the color dialog box. If the user clicks OK, change the
' PictureBox control's background to the color the user chose.
If ColorDialog1.ShowDialog() = DialogResult.OK Then
PictureBox1.BackColor = ColorDialog1.Color
End If
End Sub

92

algoharism.blogspot.com

Microsoft Visual Basic 2010 Express

.ColorDialog1
:" "closeButton - 5
Private Sub closeButton_Click() Handles closeButton.Click
' Close the form.
Close()
End Sub

: checkbox - 6
Private Sub CheckBox1_CheckedChanged() Handles CheckBox1.CheckedChanged
' If the user selects the Stretch check box, change
' the PictureBox's SizeMode property to "Stretch". If the user
' clears the check box, change it to "Normal".
If CheckBox1.Checked Then
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
Else
PictureBox1.SizeMode = PictureBoxSizeMode.Normal
End If
End Sub

.
F5

93

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com

.6

.
Build Publish

94

Microsoft Visual Basic 2010 Express

algoharism.blogspot.com



Project Properties

95



algoharism.blogspot.com

96

.3114/3113
Visual Basic - .3112
Visual Basic Express 2005 -
.3121 - http://msdn.microsoft.com/en-us/beginner/bb308891.aspx
MSDN http://msdn.microsoft.com/en--
.3121 us/library/dd492135%28VS.100%29.aspx
-
http://knowledge.moe.gov.eg/NR/rdonlyres/327B0AF2-677C-459F-B6C7.3121 - 6F2A6708E9DD/15719/1672009.ppt

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

http://algoharism.blogspot.com/search/label/

http://store.ovi.com/content/94223

http://twitter.com/algoharism

Twitter

http://algoharism.blogspot.com/search/label/

http://www.facebook.com/algoharism

http://algoharism.blogspot.com/search/label/

114

You might also like