vb.net lecture
Post on 07-Apr-2015
422 Views
Preview:
TRANSCRIPT
Visual Basic .net
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Visual Studio .netMicrosoft’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 changingHas 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”
Create New Project
Open Existing Project
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Up close…Variety of languages
Visual Basic ProjectsVisual C# ProjectsVisual C++ ProjectsSetup and Deployment ProjectsVisual Studio Solutions
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Visual Basic ProjectsWindows 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”
Project Name
Create Applications
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Project Name
Path
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Console ProgrammingConsole application – applications contain
only text outputVisual Basic console applications consist of
pieces called module
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Changing the default ModuleClick on Project > Console PropertiesOn the startup object change the startup
object to your startup module
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
To run a programOn the menu bar press DebugClick start without debugging (F5 for
shortcut key)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Console ProgrammingPrinting 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 1VB.net\LaboratoryExercise\PrintingText
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
VariablesStores data or information during program
executionHow to declare
Dim variable_Name as Data_TypeTo insert a value:
Dim variable_Name as Data_Type = Value
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
NoteBefore 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 TypesTypes 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 OperatorsAddition - +Subtraction - -Multiplication - *Division - /Division (Integer) \Modulus - ModExponentiation - ^
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 VariablesYou 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 stringDim string_varialble as string = “Value”
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
ConcatenationJoining of two or more stringsExampleDim string1 as string = “a”Dim string 2 as string = “b”
String1 & string2ab
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Example 3VB.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 thenIf studentGrade>=60 then
Console.WriteLine(“Passed”)End If
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Decision MakingIf/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 4VB.net\LaboratoryExercise\IFCondition\
ifCondition
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
While Repetition StructureA 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/LoopModule 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 RepetitionTest a condition for falsity for repetition to
continue. Statements in the body of a are executed repeatedly as long as the loop-continuation 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 = c +7
-= C-=7 C = c - 7
*= C*=7 C = c * 7
/= c/=7 C = c /7
\= c\=7 C = c \ 7
^= C^=7 C = c ^ 7
&= D &= “llo” 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 RepetitionRepetition 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 MessageOn the solution explorer, right click on the
reference and add System.windows.forms
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Message boxMessageBox.Show("Text", "Title Bar
caption", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Work SpaceForm – 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 ProgramMessagebox
MesageboxIcon.Information
MessageBox.OK
Title Bar Text
Message Text
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 buttonMessageBoxButtons.OKCancel – OK and Cancel
buttonsMessageBoxButtons.YesNo – Yes and No ButtonsMessageBoxButtons.YesNoCancel – Yes, no and
cancel buttonsMessageBoxButtons.RetryCancel – Retry and
Cancel Button
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Select Case Multiple-Selection StructureSelect Case variableCase <decision 1>
CodeCase <decision 2>
CodeCase Else
CodeEnd 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 RepetitionExit 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 repetitionExit for – Exit a for loopExit While – Exit a while repetition
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Logical OperatorsVisual 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”
AndAlsoAndOrElseOrXorNot
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
AndAlsoFalse + False = FalseFalse + True = FalseTrue + False = FalseTrue + True = True
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
OrElseFalse + False = FalseFalse + True = TrueTrue + False = TrueTrue + True = True
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
NotTrue = FalseTrue = False
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
XorFalse + False = FalseFalse + True = TrueTrue + False = TrueTrue + True = False
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Sub ProceduresModule 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 SubEnd Module
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
ProcedureSimilar to sub procedure except that
function procedures return a valueFunction procedure-name(parameter list) as
return typeDeclarations and Statement
End Function
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
MaximumGet 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 SubEnd Class
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
More Math FunctionsAbs(x) – returns absolute value of xCeiling(x) – rounds x to the smallest integerCos(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 xTan(x) – returns the trigonometric tangent of
x (x in radians)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
RandomDim 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”
ModulesProgrammers 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 modulesGoto File > Add new itemOn 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 FunctionEnd Module
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
ConvertUse to convert variables or value on a
desired data typeExample
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 typeThe first element of an array is 0th ElementThe position on the array is called index
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Public Class Form1Inherits System.Windows.Forms.FormDim 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 SubEnd Class
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
GUILabel – An area in which icons or un editable
text is displayedTextbox – 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”
ToolboxContains all the windows forms and
componentsTo 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 formApplication.exit
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Form Properties and EventsAcceptButton – Button that is clicked when Enter is
pressedAutoScroll – Boolean value that allows or disallows
scrollbars to appear when neededCancelButton – Button that is clicked when the
Escape key is pressedFormBorderStyle – 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 MethodsClose – Closes a form and releases all
resources. A closed form cannot be open.Hide – Hides formShow – 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”
TextboxPassing a value:
txtEmpNoOut.Text = txtEmpNo.TexttxtEmpNameOut.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 BoxAdding 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 boxDropDownStyle – Dropdownlist, Dropdown,
SimpleItems - 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 runtimecmbChoice.Items.Add("ABC")
Clearing the items on the combo boxcmbChoice.Items.Clear()
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Getting the items on a combocmbChoice.Items.Item (index number)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Radio ButtonAllows a user to choose a optionsProperties
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 1CalculatorPayroll System
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Picture BoxesA 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 PropertiesImage – sets the image to display in the
Picture BoxSizeMode – 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 2Picture Swapper
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
List BoxAllows the user to view and select from
multiple items in a list
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
List Box PropertiesItems – Collection of an item in a listboxSelectedIndex – 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 selectedValues(None, One, Multiple)
Sorted – Indicates whether items are sorted alphabetically
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Adding of ItemlistOrder.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 listlistOrder.Items.Count
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
CheckedListBoxesControl derives from Listbox but contains
checkbox before each item
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
PropertiesCheckedItems – Contains the collection
of items that are checkedCheckedIndeces – Returns all indexes
for checked itemsSelectionMode – 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 itemtmp = 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 itemlistOrder.Items.RemoveAt(ctr - 1)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Example GUI 3Font BrowserPOS
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Creating ShapesImport System.Drawing on your program
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Imports System.DrawingPublic 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 SubEnd Class
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Ellipsemygraphics.DrawEllipse(color of pen, x, y,
height, width)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Tree ViewDisplays nodes hierarchically in a tree.Nodes are objects that contain values and
can refer to other nodesParent node can contain child nodesA 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 nodeTwo child nodes are called siblings node
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Properties of Tree ViewCheckboxes – Indicates whether a
checkboxes appear next to nodeImageList – Specifies ImageList containing
the node iconNodes – List the collection of TreeNode, in
the control
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Methods on Treeview.NodeAdd (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”
CodePublic 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 SubEnd Class
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Font PropertiesNew Font(Font,Size,Font Style)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
CodeLabel1.Font = New Font("Comic Sans
Serif", 14, FontStyle.Italic, GraphicsUnit.Pixel)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Checked boxSmall 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 checkboxChecked – Indicates whether the checkbox
is checked or markedCheckState – Indicates whether the
checkbox is checked or uncheckedText – Specifies the text displayed to the
right of the Checkbox called label
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
CodeIf 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 BoxA 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”
OpenFileDialogOpenFileDialog 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 StreamsCreate Directory contains information
about a directoryAppendText – 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.netAdo.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.netsimplify the code you writeallow you to bind graphical controls to
DataSets
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Primary Library of ADO.netSystem.dataSystem.data.OleDbSystem.Data.SqlClientSystem.Data.Dataset
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Data Setuses the DataSet to store disconnected
data
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Adding OledbAdapterClick on Tools > Choose Toolbox Items Click on .Net Framework ComponetsSelect OledbAdapter and Click OK
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
oleDbConnectionThe oleDbConnection object uses OLE DB
to connect to a data source. ADO.NETalso 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 = connStringmyConn.Open()
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Example DatabaseDbase 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 WizardNew Connection
Data Source – Database ConnectionDatabase File Name – File Name of the
databaseChange the Datasource
Microsoft Access Database FileClick OkFind the Access FileTest the connection
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
ContinuationClick OKChoose Use SQL StatementsInsert your SQL Click Finish
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
More…You will be returned at the design tabThere 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 SetClick once on the form. Notice that on the menu bar, a new menu
item has appeared: DataSetDrag the DataSet on the formSelect untype data sets
top related