Sunday, August 21, 2016

STEP BY STEP APPROACH FOR VB.NET 2008 WINDOWS APPLICATION

STEP BY STEP BEGINERS GUIDE FOR VB.NET WINDOWS APPLICATION

CONTENTS

  1. INTRODUCTION
A.       Properties
B.                                                                               Methods
C.                                                                               Events
2.   FIRST SAMPLE APPLICATION
3.   ADDITION/subtract/multiply/division OF TWO VALUES
4.   ENTER ONLY NUMBERS BUT NOT STRINGS IN TEXTBOX
5.   ENTER ONLY STRINGS BUT NOT NUMBERS IN TEXT BOX
6.   ENTER BOTH STRINGS & CHAR IN TEXT BOX BUT NOT SPECIAL CHAR
7.   MOUSE CLICK EVENTS
8.   TOOL TIP CONTROL
9.   CHECK BOX
10. RADIO BUTTON
11. PROGRAM ON CHECK BOX AND RADIO BUTTON
12. LIST BOX
1.      INTRODUCTION TO WINDOWS APPLICATINS[WA]:

ü  WA are Graphical User Interface enabled applications with the help of which design and implementation of any application is very easy.
ü  WA is an application that runs on windows desktop.
ü  Working with GUI will be easy to the enduser when compared to console application.
ü  A WA by default contains “windows forms”.
ü  We can add any number of windows forms to a project.
ü  Windows form used to design the user interface and write the code.
ü  Windows form contains “two interface”  first interface is for “designing” and another is for “coding”.
ü  To switch between design and code use the shortcut ‘F7’.
ü  To design the user interface, we have to use ‘controls’ available in the toolbox.
ü  To open toolbox the shortcut key is ctrl+alt+x.
ü  Every control has its own properties, events and methods.

 The following six are the major features of windows applications:

  1. A windows form contains 2 interfaces.
  2. First is design and second is coding.
  3. To design user interface use controls in toolbox.
  4. Code in .net windows application is completely based on the events of the controls so the programing is called as “Event Driven Programming”.
  5. Windows application is collection of window forms.
  6. By default application opens only one form.

The following are the common properties events and methods for any control in the “Toolbox” of windows application.

a.            Properties : 
            A property is used to specify a characteristic feature of the control that will  determine the appearance and behavior of the control.
     The following 12 are common properties for all controls in Toolbox:
  1. Name           : Used to specify a unique name for the form code.
  2. Auto scroll    : Determines whether scroll bars will be displayed automatically
                     when a control on the form moves out of the boundary.
  1. Accept button: used to set a button as default button for the form.
  2. Cancel button        : used to set a button as cancel for the form.
  3. Background image : Displays an image in background
  4. Control box           : Displays minimize,maxmise etc., icons for the form.
  5. Enabled                : To enable or disable a option
  6. Icon                     : Displays icon in title bar
  7. Location                : left and top positions of the control
  8. Size                       :weight and height of the control
  9. Text                      : caption of the form
  10. Windows state       : state of the window at runtime ie.,maximized,resize etc.,


  1. Methods:
            To access the methods of a form we must use the keyword “me” this will refer to the current form. The following 4 are common methods for all controls in Toolbox:
  1. close( )                  :   This method is used to close the form
  2. hide( )                  : This method is used to  hide form
  3. show( )                  : This method is used to  show as non-model window
  4. show dialogue( )    : This method is used to form as a model window


  1. Events:  Events are the reaction of the control for the user made action against control. The following are the 16 common events :

  1. Click-any button
  2. Mouse click-for right or left button
  3. Double click-double click on control with any mouse button
  4. Mouse double click
  5. Enter-control enters
  6. Leave-control leaves
  7. Validating-after leave event for validations
  8. Validated-after leave but the cursor goes to next control
  9. Key down—all are keyboard events
  10. Key press
  11. Key up
  12. Mouse down-drag and drop
  13. Mouse up
  14. Mouse move
  15. Mouse enter
  16. Mouse leave



2.      FIRST SAMPLE WINDOWS APPLICATION
Step by step approach for creating vb.net windows application is as follows:
Step 1 :  Start->All programs->Microsoft visual studio 2008 or 2010->visual studio 2008 or 2010  (Figure 1).
[CODE]
[/CODE]
                                   Figure 1:open .net

Step 2:File->new ->project->other languages->visual basic-> Windows application. (Figure 2)
Step 3: Type name as “my new windows application” and press enter.
[CODE]
                           Figure 2: select windows application.
[/CODE]
Step 4:  Now design form with 3 labels, 3 text boxes and 2 buttons.
It means just drag and drop the label from toolbox on to the form and then repeat it for 2 times then 3 labels will appear on to the form.
Like wise drag and drop button on to the form. Repeat it 2 times then 2 buttons will appear on the form. In the same manner drag and drop textbox on the form do this 3 times then 3 textboxes will appear on the form.  Then the form looks like:::::::(Figure 3)
[CODE]
                        Figure 3: Windows Form Design
[/CODE]

Step 5:  Now right click on the “button1”  then select “properties” . Select “Text “  then type the word “ok” in it.

Step 6: Right click on the “button2”  then select “properties” . Select “Text “  then type the word “close” in it.

Step 7: Right click on the “Label1”  then select “properties” . Select “Text “  then type the word “Name” in it.

Step 8: Right click on the “Label2”  then select “properties” . Select “Text “  then type the word “Surname” in it.

Step 9: Right click on the “Label3”  then select “properties” . Select “Text “  then type the word “Result” in it.


Step 10: Right click on the Form select “view code” option  as shown in the (figure 4)
[CODE]
                                  Figure 4: selecting view code                                          
[/CODE]

Step 11: Select already existing default code and delete it. Then type the below code in that code window.
[CODE]


Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub
End Class
[/CODE]
Step 12:  Then to execute the application press the shortcut key ‘F6’ to build the code. If any errors then it will display messages or it will show successfully build at the end left corner of the window.

Step 13:  Press cntrl+F5 or F5 if any message is displayed press ok.
Now the output window will be opend there u enter namd and surname and press “ok” button. Result is shown in Result Text box.


3.      The addition/subtract/multiply/division of values

Step 1 :  Start->All programs->Microsoft visual studio 2008 or 2010->visual studio 2008 or 2010  (Figure 1).

Step 2: Step 2:File->new ->project->other languages->visual basic-> Windows application. (Figure 2).

Step 3: Type name as “two numbers” and press enter.

Step 4: Right click on Form select Properties ->Key preview->True
By doing this step at runtime the window will be closed simpy by pressing “Escape key” in our keyboard.
Step 5:  Drag and drop 3 Text boxes and 2 labels on to the form.
Step 6: Right click on the form select->properties
Step 7 : In properties there will be sub tabs here select “Events” option as shown in (figure 5):
[CODE]
                        Figure 5: selecting “events” inproperties tab
[/CODE]

Step 8: Double click on the option “ Key Down” and write the code as given below:
[CODE]
Select case e.keycode
Case keys.F1
Textbox3.text=val(textbox1.text)+val(textbox2.text)
Case keys.F2
Textbox3.text=val(textbox1.text)-val(textbox2.text)
Case keys.f3
Textbox3.text=val(textbox1.text)*val(textbox2.text)
Case keys.f4
Textbox3.text=val(textbox1.text)/val(textbox2.text)
Case keys.f5
Textbox2.clear( )
Textbox3.clear( )
Case keys.escape
Me.close( )
End select
End sub
[/CODE]
Step 9:  Then to execute the application press the shortcut key ‘F6’ to build the code. If any errors then it will display messages or it will show successfully build at the end left corner of the window.

Step 10:  Press cntrl+F5 or F5 if any message is displayed press ok.
Now the output window will be opend. 
If you press F1: Addition is displayed
F2:Subtraction
F3:Multiplication
F4:Division

4.      TO ENTER NUMBERS BUT NOT STRINGS IN TEXT BOXS

Step 1 :  Start->All programs->Microsoft visual studio 2008 or 2010->visual studio 2008 or 2010  (Figure 1).

Step 2: Step 2:File->new ->project->other languages->visual basic-> Windows application. (Figure 2).

Step 3: Type name as “only two numbers” and press enter.

Step 4: Right click on Form select Properties ->Key preview->True
By doing this step at runtime the window will be closed simpy by pressing “Escape key” in our keyboard.
Step 5:  Drag and drop 3 Text boxes and 2 labels on to the form.
Step 6: Right click on the form select->properties
Step 7 : In properties there will be sub tabs here select “Events” option as shown in (figure 5):
Step 8: Double click on the option “ Key Down” and write the code as given below:
[CODE]

Select case e.keycode
Case keys.F1
Textbox3.text=val(textbox1.text)+val(textbox2.text)
Case keys.F2
Textbox3.text=val(textbox1.text)-val(textbox2.text)
Case keys.f3
Textbox3.text=val(textbox1.text)*val(textbox2.text)
Case keys.f4
Textbox3.text=val(textbox1.text)/val(textbox2.text)
Case keys.f5
Textbox2.clear( )
Textbox3.clear( )
Case keys.escape
Me.close( )
End select
End sub
[/CODE]
Step 9:select TextBox1->Right click->properties->select “events”
[CODE]
 
                                  Figure 7: select events keypress
[/CODE]
Step 10 : write the code as shown below:
[CODE]
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
if char.isletter(e.keychar)=false and e.keychar<>char(keys.back) then
e.handled=true
end if


    End Sub
[/CODE]
Step 11:  Then to execute the application press the shortcut key ‘F6’ to build the code. If any errors then it will display messages or it will show successfully build at the end left corner of the window.

Step 12:  Press cntrl+F5 or F5 if any message is displayed press ok.
Now the output window will be opend. 
If you press F1: Addition is displayed
F2:Subtraction
F3:Multiplication
F4:Division




5.      ENTER ONLY STRINGS BUT NOT NUMBERS IN TEXT BOX
Step 1 :  Start->All programs->Microsoft visual studio 2008 or 2010->visual studio 2008 or 2010  (Figure 1).

Step 2: Step 2:File->new ->project->other languages->visual basic-> Windows application. (Figure 2).

Step 3: Type name as “string manip” and press enter.

Step 4: Right click on Form select Properties ->Key preview->True
By doing this step at runtime the window will be closed simpy by pressing “Escape key” in our keyboard.
Step 5:  Drag and drop 3 Text boxes and 2 labels on to the form.
Step 6: Right click on the form select->properties
Step 7 : In properties there will be sub tabs here select “Events” option as shown in (figure 5):
Step 8: Double click on the option “ Key Down” and write the code as given below:
[CODE]
Select case e.keycode
Case keys.F1
Textbox3.text=val(textbox1.text)+val(textbox2.text)
Case keys.F2
Textbox3.text=val(textbox1.text)-val(textbox2.text)
Case keys.f3
Textbox3.text=val(textbox1.text)*val(textbox2.text)
Case keys.f4
Textbox3.text=val(textbox1.text)/val(textbox2.text)
Case keys.f5
Textbox2.clear( )
Textbox3.clear( )
Case keys.escape
Me.close( )
End select
End sub
[/CODE]
Step 9:select TextBox1->Right click->properties->select “events”
Step 10 : write the code as shown below:
[CODE]
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
if digit(e.keychar)=false and e.keychar<>char(keys.back) then
e.handled=true
end if



    End Sub
[/CODE]
Step 11:  Then to execute the application press the shortcut key ‘F6’ to build the code. If any errors then it will display messages or it will show successfully build at the end left corner of the window.

Step 12:  Press cntrl+F5 or F5 if any message is displayed press ok.
Now the output window will be opend. 
If you press F1: Addition is displayed
F2:Subtraction
F3:Multiplication
F4:Division

6.      ENTER BOTH STRINGS & CHAR IN TEXT BOX BUT NOT SPECIAL CHAR

Step 1 :  Start->All programs->Microsoft visual studio 2008 or 2010->visual studio 2008 or 2010  (Figure 1).

Step 2: Step 2:File->new ->project->other languages->visual basic-> Windows application. (Figure 2).

Step 3: Type name as “bothstring and num” and press enter.

Step 4: Right click on Form select Properties ->Key preview->True
By doing this step at runtime the window will be closed simpy by pressing “Escape key” in our keyboard.
Step 5:  Drag and drop 3 Text boxes and 2 labels on to the form.
Step 6: Right click on the form select->properties
Step 7 : In properties there will be sub tabs here select “Events” option as shown in (figure 5):
Step 8: Double click on the option “ Key Down” and write the code as given below:
[CODE]
Select case e.keycode
Case keys.F1
Textbox3.text=val(textbox1.text)+val(textbox2.text)
Case keys.F2
Textbox3.text=val(textbox1.text)-val(textbox2.text)
Case keys.f3
Textbox3.text=val(textbox1.text)*val(textbox2.text)
Case keys.f4
Textbox3.text=val(textbox1.text)/val(textbox2.text)
Case keys.f5
Textbox2.clear( )
Textbox3.clear( )
Case keys.escape
Me.close( )
End select
End sub
Step 9:select TextBox1->Right click->properties->select “events”
Step 10 : write the code as shown below:
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
if char.isletter or digit(e.keychar)=false and
e.keychar<>char(keys.back) then
e.handled =true
end if
    End Sub
[/CODE]
Step 11:  Then to execute the application press the shortcut key ‘F6’ to build the code. If any errors then it will display messages or it will show successfully build at the end left corner of the window.

Step 12:  Press cntrl+F5 or F5 if any message is displayed press ok.
Now the output window will be opend. 
If you press F1: Addition is displayed
F2:Subtraction
F3:Multiplication
F4:Division

7.      MOUSE CLICK EVENTS
Step 1 :  Start->All programs->Microsoft visual studio 2008 or 2010->visual studio 2008 or 2010  (Figure 1).

Step 2: Step 2:File->new ->project->other languages->visual basic-> Windows application. (Figure 2).

Step 3: Type name as “MOUSE EVENTS” and press enter.

Step 4: Right click on Form select Properties ->events->mouse click (Figure 8)
[CODE]
              Figure 8: mouse click event
[/CODE]

Step 5: Double click and enter the following code:
Private Sub Form1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseClick
select case e.button
case windows.forms.mousebuttons.left
msbox(“left buttonclicked”)
case windows.forms.mousebuttons.right
msgbox(“right click”)
case windows.forms.mousebutton.middle
msgbox(“middle button click”)
end slect
    End Sub


Step 11:  Then to execute the application press the shortcut key ‘F6’ to build the code. If any errors then it will display messages or it will show successfully build at the end left corner of the window.

Step 12:  Press cntrl+F5 or F5
Now the output window will be opend.  If you click mouse then message will be displayed.


8.      TOOLTIP CONTROL : This control is used to show message when cursor placed on control

Step 1 :  Start->All programs->Microsoft visual studio 2008 or 2010->visual studio 2008 or 2010  (Figure 1).

Step 2: Step 2:File->new ->project->other languages->visual basic-> Windows application. (Figure 2).

Step 3: Type name as “TOOLTIP” and press enter.
Step 4: place “tooltip” control draga and drop from toolbox on to the form
Step 5: drag and drop 3 textboxes(figure 9)
[CODE]


              Figure 9: 3 textboxes
[/CODE]

Step 6: select textbox1->right click->properties->tooltip->”enter the first number please”
Step 7: select textbox3->right click->properties->tooltip->”enter the second number please”
Step 8: select textbox3->right click->properties->tooltip-> ”enter the third number please”
Step 9:  Then to execute the application press the shortcut key ‘F6’ to build the code. If any errors then it will display messages or it will show successfully build at the end left corner of the window.

Step 10:  Press cntrl+F5 or F5
Now the output window will be opend. 

---after executing the program if u place mouse on txtbx1 then it shows the msg u entered in the tooltip likewise on textbox2 and textbox3 also message will be displayed.


9.checkbox : This control is used to select more than one option at a time

Properties of check box are :
  1. Appearance
  2. Checked
  3. Check state
a.checked
b.unchecked
c.intermediate
   Events of check box are:
  1. checked changed
  2. checked state changed


10. Radio button: This control restricts to select only one option.
Properties of radio button are:
  1. Appearance
  2. Checked
Events of check box are:
  1. checked changed



11. program ON Both Radio buttons and Check box

Step 1 :  Start->All programs->Microsoft visual studio 2008 or 2010->visual studio 2008 or 2010  (Figure 1).

Step 2: Step 2:File->new ->project->other languages->visual basic-> Windows application. (Figure 2).

Step 3: Type name as “radiocheck” and press enter.
Step 4: Drag and drop one “label button”, three “check boxes” and three “radio buttons” from toolbox on to the form
[CODE]


[/CODE]
Step 5: Now double click on the checkbox1:
[CODE]
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Dim f as font
If checkbox1.checked then
F=new font(label1.font,font style.bold)

Else
F=new font(label1.font,fontstyle.regular)
End if
Label1.font=f

    End Sub
[/CODE]
Step 6:Now double click on checkbox2:
[CODE]
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged

    End Sub
[/CODE]


Step 7:Now double click check box3:
[CODE]
Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
Dim f as font
If checkbox1.checked then
F=new font(label1.font,font style.italic)

Else
F=new font(label1.font,fontstyle.regular)
End if
Label1.font=f

    End Sub
[/CODE]

Step 8: Now double click on radio button1
[CODE]
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
Label1.forecolor=color.green

    End Sub
[/CODE]
Step 9 Radiobutton2::
[CODE]
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
Label1.forecolor=color.red

    End Sub
[/CODE]
Step 10:Radio3:
[CODE]
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
Label1.forecolor=color.blue
    End Sub
[/CODE]
Step 11: execute program press ctrl+F5.

12. LIST BOX:

PROPERTIES:
1.Items
2. Multicolumn
3. Selection mode-one item to be selected or multiple items

At runtime list box properties of form
  1. selected index
  2. selected indices
  3. selected item
  4. selected items


The Query for  add,remove your list item is as follows:

listbox1.items.add(“item”)
listbox1.items.insert(index,”items)
listbox1.items.addrange(listbox1.items)
listbox1.items.remove(“item”)
listbox1.items.removeat(index)
listbox1.items(clear)
-------------THE END-------------

No comments:

Post a Comment