30
Part V Programming with Visual Basic .NET MELJUN CORTES MELJUN CORTES

MELJUN CORTES VB.NET Programming with Visual Basic.NET

Embed Size (px)

DESCRIPTION

MELJUN CORTES VB.NET Programming with Visual Basic.NET

Citation preview

Page 1: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Part V

Programming with Visual Basic .NET

MELJUN CORTESMELJUN CORTES

Page 2: MELJUN CORTES VB.NET Programming with Visual Basic.NET

OverviewV.1: Using Visual Basic Console Application Printing a Line of Text Adding Integers Performing Comparisons with Equality and Relational Operators Problems

V.2: Using Visual Basic Windows Application Introduction to Windows Application

Windows Forms Benefits of Windows Applications Introduction to Windows Forms

Using Windows Forms Working with Controls Working with Data Binding Applications Creating Multilingual Applications

Printing a Line of Text Using the Graphical User Interface Flash Card Addition (Finding the Value of Z) Temperature Conversion Problems

Page 3: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Using Visual Basic .NET Console Application

Applications that contain only text groups Text output in Console Application is

displayed in a command window (also called a console window)MS Windows 95/98 – command windowMS Windows NT/2000/XP – command prompt

Page 4: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Printing a Line of Text

Page 5: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Common Console Methods

Write method writes the specified information to the

standard output stream. Writeline method writes the specified data,

followed by the current line terminator, to the standard

output stream. Read method reads the next character from the

standard input stream.

Readline method reads the next line of characters from the standard input stream.

Page 6: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Adding Integers

Page 7: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Performing Comparisons with Equality and Relational Operators 1/2

Page 8: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Performing Comparisons with Equality and Relational Operators 2/2

Page 9: MELJUN CORTES VB.NET Programming with Visual Basic.NET

PROBLEMS

Write a program that will add, subtract, multiply and divide two integers.

Diamond (For/Next)

Square (For/Next)

Page 10: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Solution (for Problem 1)

Page 11: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Solution (for Problem 2)

Page 12: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Solution (for Problem 3)

Page 13: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Using Visual Basic Windows Application

A program that executes inside the Windows OS

It includes customized software, that programmers create, as well as software products like MS Word, MS Internet Explorer and Visual Studio .NET

Page 14: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Windows Forms Provide a great way to build Windows – applications. Provide many ready-to-use controls in addition to the

infrastructure for developing your own controls. The .NET Framework provides many controls with increased built-in functionality that greatly speeds up the development process.

Enable developers building Windows based applications to take full advantage of Windows operating system features.

Take advantage of many new technologies, including a common language runtime (CLR), an extensive class library, integrated security , and object-oriented design capabilities.

Offer full support for quick and easy connection to XML Web Services and building data-aware applications based on the Microsoft ADO.NET data model.

Page 15: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Benefits of Windows Applications

Based on the .NET Framework classes Language-independent Fast response time Powerful drawing / graphics capabilities Time-saving development features Advanced data-binding Simple deployment Richer UI

Page 16: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Introduction to Windows Forms 1/2 The form is the primary object used for user

interaction. A form is an item of screen real estate, usually rectangular, that you can use to present information to and accept input from the user.

Types of Windows FormsStandard windowsMultiple document interface (MDI)

windowsDialog boxesDisplay for graphical routines

Page 17: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Introduction to Windows Forms 2/2 Forms expose properties, methods, and

eventsForms are objects that expose properties,

methods, and events.Properties define the appearance of forms.Methods define their behavior.Events define their interaction with the user.By setting the properties of the form and

writing code to respond to its events, you customize the form object to meet the requirements of your application.

Page 18: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Working with Controls 1/2 New control features

Docking, anchoring, menu editor, etc. New controls

LinkLabel - provides linking to a specified URL, similar to linking through Hypertext Markup Language (HTML). Text displayed by using this control will appear as underlined, and the cursor will change to a hand symbol as the mouse moves over it, firing an event when clicked.

NotifyIcon – enables developers to create applications that you can manage from an icon in the status notification area on the task bar, similar to the SQL ServerTM Service Manager.

PrintPreviewControl – Windows Forms offer a printing framework that makes printing simple.

Page 19: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Working with Controls 2/2 Create your own controls

Enhance existing controls Create from scratch

Add controls to a form by: Dragging and dropping from the Toolbox Writing code to add controls dynamically at run time

Example:Private Sub CreateControl()

Dim MyText as New TextBox MyText.Location = New Point(25, 25) Me.Controls.Add (MyText)End Sub

Page 20: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Working with Data Binding Applications 1/2

Set properties by using data binding You can bind any property of any control to the data source.

With the .NET Framework, you have the option of setting other properties through binding. Some of the functions of data binding include:

Setting the graphic of an image control Setting the background color of one or more controls Setting the size of controls

Two types of data binding: Data binding becomes an automatic way of setting any runtime-

accessible property of any control on the form.

1. Simple – a single value within a data set is bound to something such as a property of a control or a form. Any property of a component can be bound to any value in a dataset.

Page 21: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Working with Data Binding Applications 2/2

Example: Binding the Text property of a TextBox control to the LastName column of customer’s DataTable.

Dim t As DataTable = DataSet1.Tables(“Suppliers”)Dim Text1 As New TextBoxText1.DataBindings.Add (“Text”, t, “CompanyName”)

2. Complex – means that components are able are able to bind to a dataset. Components that can take advantage of this include the DataGrid control and the ComboBox Control. Example: Binding a DataTable to a ComboBox Control.

Dim t As DataTable = DataSet1.Tables(“Suppliers”)Dim Combo1 As New ComboBoxCombo1.DataSource = tCombo1.DisplayMember = “CompanyName”

Page 22: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Creating a Multilingual Applications 1/2

A multilingual application is aware of the operating system’s default local culture installed on the client computer. This enables the application to change the information displayed to the user with buttons and menus depending on their machine setup.

Page 23: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Creating a Multilingual Applications 2/2

Steps to create multilingual forms1. Design your form based on the default language, including

all menus, buttons, text values, and other display elements.2. Set the Localizable property of the form to true.3. Select an alternate language from the Language property.4. Change each control’s text property for the new language.

You can also change any other property of the control for each language; this commonly includes the Size property to allow for wider text values in button controls.

5. Repeat steps three and four for each new language.6. Compile and test your application with your default

language. Test other languages by changing the Regional and Language Options from the Control Panel and restarting the application. The new language version should display automatically.

Page 24: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Printing a Line of Text Using the GUI

Page 25: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Flash Card Addition (Finding the Value of Z) 1/2

Page 26: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Flash Card Addition (Finding the Value of Z) 2/2

Page 27: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Temperature Conversion 1/2

Convert Celsius to Fahrenheit

Formula: F = (9 / 5) + 32

Page 28: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Temperature Conversion 2/2

Page 29: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Problems 1/2

Using the GUI, write a program that will add, subtract, multiply and divide two integers.

Page 30: MELJUN CORTES VB.NET Programming with Visual Basic.NET

Problems 2/2

Write a program that will show the profile of an athlete.