Visual Basic .

net
Mr. Jose Marie M. Pacia

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Visual Studio .net
• Microsoft’s Integrated Development Environment (IDE) for creating running and debugging programs (called applications) written in variety of programming languages

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Why move from VB6 to .Net?
• World of applications is changing • Has a number of unique features

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Overview of Visual Studio .net
• • Start Page – contains list of helpful links There are two buttons on the page: – Open Project – New Project To create a new project click new project

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Open Existing Project

Create New Project

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Up close…
• Variety of languages – Visual Basic Projects – Visual C# Projects – Visual C++ Projects – Setup and Deployment Projects – Visual Studio Solutions

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Visual Basic Projects
• Windows application – a program that executes inside a windows OS. – Include customized software that programmers create, example Microsoft Word, IE6 ect.

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Create Applications

Project Name

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Project Name Path

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Console Programming
• Console application – applications contain only text output • Visual Basic console applications consist of pieces called module

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Changing the default Module
• Click on Project > Console Properties • On the startup object change the startup object to your startup module

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

To run a program
• On the menu bar press Debug • Click start without debugging (F5 for shortcut key)

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Console Programming
• Printing a text – Consolse.Write(“String”) – Console.WriteLine(“The text goes here!”) • Writeline position the text in the beginning of the next line

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Example 1
• VB.net\LaboratoryExercise\PrintingText

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Variables
• Stores data or information during program execution • How to declare – Dim variable_Name as Data_Type – To insert a value: • Dim variable_Name as Data_Type = Value

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Note
• Before VB can use an object variable, it must determine its type and perform the necessary conversions, if any.

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Data Types
• Types of Variables – Numeric – Store Numbers

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Arithmetic Operators
• • • • • • • Addition - + Subtraction - Multiplication - * Division - / Division (Integer) \ Modulus - Mod Exponentiation - ^

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Example 2
• \VB.net\LaboratoryExercise\ConsoleCalculator\ConsoleCalC

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Character Variables
• You can initialize a character variable by assigning either a character or a string to it. In the latter case, only the first character of the string is assigned to the variable. – Dim string_varialble as string – Dim string_varialble as string = “Value”

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Concatenation
• • • • Joining of two or more strings Example Dim string1 as string = “a” Dim string 2 as string = “b” – String1 & string2 • ab

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Example 3
• VB.net\LaboratoryExercise\StringManipulation\StringManipulation

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Equality Operators
• • • • • • = - Equals <> - Not Equal > - Greater Than < - Less Than >= - Greater Than Equal <= - Less than equal

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

If then
If studentGrade>=60 then Console.WriteLine(“Passed”) End If

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Decision Making
• If/then – Allows a program to make a decision based on the truth or falsity of some expression – It is a condition

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Module Condition Sub Main() Dim lagyu As String Dim num1 As Integer Dim num2 As Integer Console.WriteLine("Enter first number: ") num1 = Console.ReadLine() Console.WriteLine("Enter second number: ") num2 = Console.ReadLine() If num1 > num2 Then Console.WriteLine("Number 1 is greater than number 2") Else Console.WriteLine("Number 2 is greater than number 3") End If End Sub End Module
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

If else/ elseif / else
If num1 > num2 Then Console.WriteLine("Number 1 is greater than number 2!") ElseIf (num2 > num1) Then Console.WriteLine("Number 1 is greater than number 2!") Else Console.WriteLine("Number are equal!") End If

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Example 4
• VB.net\LaboratoryExercise\IFCondition\ifCondition

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

While Repetition Structure
• A repetition structure allows the programmer to specify that an action should be repeated depending on the value of the condition

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Do while/Loop
Module WhileLoop Dim ctr As Integer Sub Main() ctr = 1 While ctr <= 10 ctr = ctr + 1 Console.WriteLine(ctr) End While End Sub End Module
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Do Until/Loop Repetition
• Test a condition for falsity for repetition to continue. Statements in the body of a are executed repeatedly as long as the loopcontinuation test evaluates to false

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Module DoWhileLoop Dim ctr As Integer Sub Main() ctr = 10 Do Until ctr < 1 Console.WriteLine(ctr) ctr = ctr - 1 Loop End Sub End Module
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Assignment Operators
+= -=
*=

C=+7 C-=7 C*=7 c/=7 c\=7 C^=7 D &= “llo”

C = c +7 C=c-7 C=c*7 C = c /7 C=c\7 C=c^7 D= D & “llo”

/= \= ^= &=
VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Module Module1 Sub Main() Dim a As Integer Dim var1 As Integer Dim sum As Integer a=1 sum = 0 While a <= 10 Console.WriteLine("Enter Number " & a & ":") var1 = Console.ReadLine() a += 1 sum = var1 + sum End While Console.WriteLine("The sum is " & sum) End Sub End Module

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

For/Next Repetition
• Repetition structure handles the details of counter-controlled repetition.

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Module ForLoop Sub Main() Dim counter As Integer For counter = 1 To 10 Console.WriteLine(counter) Next End Sub End Module
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Using Dialog to Display Message
• On the solution explorer, right click on the reference and add System.windows.forms

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Message box
• MessageBox.Show("Text", "Title Bar caption", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Work Space
• Form – Gray rectangle which represents the Windows Applications that the programmer is creating • The form which is the visual part of the program which the user interact

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Introduction to Windows Application Program
• Messagebox
Title Bar Text

MesageboxIcon.I nformation

Message Text

MessageBox.OK

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

• • • •

MessageBoxIcon.Exclamation – Excalmation Point MessageBoxIcon.Information – Icon Containing the letter I MessageBoxIcon.Question – Icon Containing question mark MessageBoxIcon.Error – Icon containing the red x circle

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

• MessageBoxButtons.OK – OK button • MessageBoxButtons.OKCancel – OK and Cancel buttons • MessageBoxButtons.YesNo – Yes and No Buttons • MessageBoxButtons.YesNoCancel – Yes, no and cancel buttons • MessageBoxButtons.RetryCancel – Retry and Cancel Button

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Select Case Multiple-Selection Structure
Select Case variable Case <decision 1> Code Case <decision 2> Code Case Else Code End Select
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Module SelectCaseModule Sub Main() Dim choys As Integer Console.WriteLine("Enter Choice") choys = Console.ReadLine Select Case choys Case 1 Console.WriteLine(1) Case 2 Console.WriteLine(2) Case Else Console.WriteLine("Default") End Select End Sub End Module
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Exit Keyword in a Repetition
• Exit Do, Exit While, Exit For statements alter the flow of control by causing immediate exit from a repetition structure

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

• Exit Do – Exit a do while repetition • Exit for – Exit a for loop • Exit While – Exit a while repetition

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Logical Operators
• Visual Basic provides logical operators that can be used to form complex conditions by combining simple ones

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

• • • • • •

AndAlso And OrElse Or Xor Not

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

AndAlso
• • • • False + False = False False + True = False True + False = False True + True = True

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

OrElse
• • • • False + False = False False + True = True True + False = True True + True = True

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Not
• True = False • True = False

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Xor
• • • • False + False = False False + True = True True + False = True True + True = False

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Sub Procedures
Module SubProc Sub Main() Dim choys As Integer Console.WriteLine("Enter Choice") choys = Console.ReadLine Select Case choys Case 1 proc1("jpacs")
End Select

End Sub Sub proc1(ByVal name As String) Console.WriteLine(name) End Sub End Module
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Procedure
• Similar to sub procedure except that function procedures return a value Function procedure-name(parameter list) as return type Declarations and Statement End Function

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Maximum
• Get the maximum value of two number – Math.Max(val1, val2)

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Public Class frmMax Inherits System.Windows.Forms.Form Dim val1, val2, val3 As Double Private Sub cmdMax_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMax.Click val1 = txtFirst.Text val2 = txtSecond.Text val3 = txtThird.Text lblTotal.Text = Math.Max(Math.Max(val1, val2), val3) End Sub End Class

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

More Math Functions
• Abs(x) – returns absolute value of x • Ceiling(x) – rounds x to the smallest integer • Cos(x) returns the trigonometric cosine

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

• Exp(x) – returns the exponential ex • Floor(x) – rounds x to the largest integer not greater than x • Log(x) – returns the natural logarithm of x (base e) • Max(x,y) – returns the larger value of x and y • Min(x,y) – returns the smallest value of x and y
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

• • • •

Pow(x,y) – Calculates x reaised to power y(xy) Sin(x) – returns the trigonometric sine of x(x in radians) Sqrt(x) – returns the square root of x Tan(x) – returns the trigonometric tangent of x (x in radians)

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

• Random – Dim randomObject as Random = New Random() – Dim randomNumber as Integer = randomObject.Next()

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim randomObject As Random = New Random Dim randomNumber As Integer randomNumber = randomObject.Next(1, 10) lblRandom.Text = randomNumber End Sub

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Modules
• Programmers use modules to group related procedures so that they can be reused in other projects

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

How to add modules
• Goto File > Add new item • On the template select module

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Module Module1 Function reuse(ByVal lbl As Label) lbl.Text = "jpacs" End Function End Module

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Convert
• Use to convert variables or value on a desired data type • Example – Convert.ToString (val2) – Convert.ToChar(1)

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Array
• • • • Can store information and has indexes or memory address Array have the same name and same type The first element of an array is 0th Element The position on the array is called index

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Public Class Form1 Inherits System.Windows.Forms.Form Dim numarray(10) As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load numarray(0) = 1 Label1.Text = numarray(0) End Sub End Class
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

GUI
• Label – An area in which icons or un editable text is displayed • Textbox – An area in which the user inputs data from the keyboard. This can also display information • Button – An area that triggers an event when clicked • CheckBox – A component that is either selected on unselected
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

• ComboBox – A drop-down list of items from which the user can make a selection either by clicking an item in the list or by typing into a box • ListBox – An area in which a list of items is displayed. The user can make a selection from the list by clicking on any item. Multiple elements can be selected.

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

• Panel – A container in which components can be placed • Scrollbar – A component that allows the user to access a range of elements that normally cannot fit in the control’s container

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Toolbox
• Contains all the windows forms and components • To add a component on a form, select the component on the toolbox and drag it on the form

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Unload a form
• Application.exit

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Form Properties and Events
• AcceptButton – Button that is clicked when Enter is pressed • AutoScroll – Boolean value that allows or disallows scrollbars to appear when needed • CancelButton – Button that is clicked when the Escape key is pressed • FormBorderStyle – Border style for the form (e.g., none, single, 3d)

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

• Font – font of text displayed on the form, and the default font of controls added to the form • Text – Text in the form’s title bar

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Common Methods
• Close – Closes a form and releases all resources. A closed form cannot be open. • Hide – Hides form • Show – Display hidden forms

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Code
• formName.ActiveForm.Close()

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Textbox
• Passing a value: – txtEmpNoOut.Text = txtEmpNo.Text – txtEmpNameOut.Text = txtLastName.Text & " " & txtFirstName.Text

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Mathematical Operator on Text Box
• txtPhilhealth.Text = Val(txtSalaryMain.Text) * 0.05 • txtTax.Text = Val(txtSalaryMain.Text) * 0.04 • txtSSS.Text = Val(txtSalaryMain.Text) * 0.03

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Combo Box
• Adding Items on runtime – ComboBox1.Items.Add("ABC") • Clearing Items on runtime – ComboBox1.Items.Clear()

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Properties of a combo box
• DropDownStyle – Dropdownlist, Dropdown, Simple • Items - use to insert all the choices on your combo box

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Adding Items on Combo on runtime
• cmbChoice.Items.Add("ABC") Clearing the items on the combo box • cmbChoice.Items.Clear()

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Getting the items on a combo
• cmbChoice.Items.Item (index number)

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Radio Button
• Allows a user to choose a options • Properties – Check = combo box is selected (True = Selected, False = Un Selected) – Text = Text displayed on option Button

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Example GUI 1
• Calculator • Payroll System

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Picture Boxes
• A picture box displays an image. The image, set by an object of class Image, can be a bitmap, a GIF, JPEG, icon or metafile format.

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Picture Box Properties
• Image – sets the image to display in the Picture Box • SizeMode – Enumeration that controls image sizing and positioning. StretchImage, AutoSize and Center Image)

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

• Normal places the image in top-left corner of picture box • CenterImage puts the image in middle (both truncate image if it is too large) • StretchImage resizes image to fit in PictureBox. • AutoSize resizes PictureBox to hold image
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Loading Picture on Runtime
• picOne.Image = Image.FromFile("D:\VB.net\LaboratoryExercise\Picture Swapper\Pictures\Pic2.jpg")

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Selecting the Current directory or Path
• .fromfile (directory.GetCurrentDirectory)

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Example GUI 2
• Picture Swapper

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

List Box
• Allows the user to view and select from multiple items in a list

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

List Box Properties
• Items – Collection of an item in a listbox • SelectedIndex – Returns the index of the selected item. If selected multiple items, the property returns arbitrary returns one of the selected indeces. If no items are selected, the property returns to -1

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

• SelectedIndeces – Returns a collection containing the indeces for all selected items • SelectedItem – Returns a reference to the selected item (If multiple items are selected, it returns the items with the lowest number of index) • SelectedItems – Returns a collection of selected items

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

• SelectionMode – Determines the number of items that can be selected – Values(None, One, Multiple) • Sorted – Indicates whether items are sorted alphabetically

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Adding of Item
• listOrder.Items.Add(“Item to Add”)

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Removing of items
• listOrder.Items.Clear()

• Counting of items on a list – listOrder.Items.Count

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

CheckedListBoxes
• Control derives from Listbox but contains checkbox before each item

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Properties
• CheckedItems – Contains the collection of items that are checked • CheckedIndeces – Returns all indexes for checked items • SelectionMode – Determines how many items can be checked. One(Multiple) and None(Does not allow)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

To get checked item
tmp = listOrder.GetItemChecked(ctr - 1) If tmp = True Then listOrder.Items.RemoveAt(ctr - 1) End If

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Remove item
• listOrder.Items.RemoveAt(ctr - 1)

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Example GUI 3
• Font Browser • POS

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Creating Shapes
• Import System.Drawing on your program

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Imports System.Drawing Public Class frmShapes Dim mygraphics As Graphics = MyBase.CreateGraphics Dim mypen As New Pen(Color.DarkRed) Private Sub cmbShapes_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbShapes.SelectedIndexChanged If cmbShapes.Text = "Ellipse" Then mygraphics.Clear(Color.White) mygraphics.DrawEllipse(mypen, 100, 100, 100, 10) End If End Sub End Class
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Ellipse
• mygraphics.DrawEllipse(color of pen, x, y, height, width)

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Tree View
• • • • Displays nodes hierarchically in a tree. Nodes are objects that contain values and can refer to other nodes Parent node can contain child nodes A child node can be a parent node to other nodes

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

• First node on the tree is the root node • Two child nodes are called siblings node

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Properties of Tree View
• Checkboxes – Indicates whether a checkboxes appear next to node • ImageList – Specifies ImageList containing the node icon • Nodes – List the collection of TreeNode, in the control

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Methods on Treeview.Node
• Add (Adds a tree node object) • Clear (Clears the entire collection of tree node) • Remove (Delete a specific node)

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Code
Public Class frmTree Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim StudName As String StudName = txtLName.Text + ", " + txtFName.Text + " " + txtMI.Text If cmbCourse.Text = "ACT" Then treeStudents.Nodes(0).Nodes(0).Nodes.Add(StudName) End If End Sub End Class
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Font Properties
• New Font(Font,Size,Font Style)

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Code
• Label1.Font = New Font("Comic Sans Serif", 14, FontStyle.Italic, GraphicsUnit.Pixel)

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Checked box
• Small white square that either is blank or contains a checkmark. When a checkbox is selected, a blank checkmark appears in the box.

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Properties of a checkbox
• Checked – Indicates whether the checkbox is checked or marked • CheckState – Indicates whether the checkbox is checked or unchecked • Text – Specifies the text displayed to the right of the Checkbox called label

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Code
If chkBold.CheckState = CheckState.Checked Then txtOutput.Font = New Font(cmbFonts.Text, 12, FontStyle.Bold) Else txtOutput.Font = New Font(cmbFonts.Text, 12, FontStyle.Regular) End If

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Common Dialog Box
• A rather tedious, but quite common, task in nearly every application is to prompt the user for filenames, font names and sizes, or colors to be used by the application

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

OpenFileDialog
• OpenFileDialog Lets users select a file to open. It also allows the selection of multiple files, for applications that must process many files at once (change the format of the selected files, for example).

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Files and Streams
• Create Directory contains information about a directory – AppendText – Returns a StreamWriter that appends to an existing file or creates a file if one does not exist

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Database Programming using ADO.net
• Ado.net object model provides an API for accessing database systems programmatically. • Was created for the .NET framework and is the next generation of ActiveX Data Objects (ADO), which was designed to interact with Microsoft’s Components Object Model (COM) framework

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

ADO.net
• simplify the code you write • allow you to bind graphical controls to DataSets

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Primary Library of ADO.net
• • • • System.data System.data.OleDb System.Data.SqlClient System.Data.Dataset

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Data Set
• uses the DataSet to store disconnected data

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Adding OledbAdapter
• Click on Tools > Choose Toolbox Items • Click on .Net Framework Componets • Select OledbAdapter and Click OK

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

oleDbConnection
• The oleDbConnection object uses OLE DB to connect to a data source. ADO.NET • also includes a new type of connection: SQLConnection

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

• • • • • •

Dim connString As String = _ “Provider= SQLOLEDB.1;Data Source=localhost;” & _ “uid=sa;pwd=;Initial Catalog=northwind;” Dim myConn As New oleDbConnection() myConn.ConnectionString = connString myConn.Open()

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Example Database
• Dbase Application

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

• The End!!!!

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Data Adapter Wizard
• New Connection – Data Source – Database Connection – Database File Name – File Name of the database • Change the Datasource – Microsoft Access Database File – Click Ok – Find the Access File – Test the connection

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Continuation
• • • • Click OK Choose Use SQL Statements Insert your SQL Click Finish

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

More…
• You will be returned at the design tab • There are two components that has been added:


oleDbDataAdapter1 oleDbConnection1

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

• The oleDbConnection1 control describes the database connection; • The oleDbDataAdapter1 control describes your actual query • In VB.NET, the object you use to store data is called a DataSet.

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Data Set
• Click once on the form. • Notice that on the menu bar, a new menu item has appeared: DataSet • Drag the DataSet on the form • Select untype data sets

VB .net

© COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”

Sign up to vote on this title
UsefulNot useful