1 / 86

Introduction to Visual Basic .NET

Introduction to Visual Basic .NET. A version of the Hello World program in Visual Basic .NET. Objective. Our main objective is to become familiar with the VB .NET Integrated Development Environment (IDE or environment for short)

yamal
Télécharger la présentation

Introduction to Visual Basic .NET

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Visual Basic .NET A version of the Hello World program in Visual Basic .NET

  2. Objective • Our main objective is to become familiar with the VB .NET Integrated Development Environment (IDE or environment for short) • To accomplish this task, let us design an interface and write the associated program that has the user enter his or her name, then click a button and view a message welcoming him or her.

  3. Start/Programs/Microsoft Visual Studio .NET/Microsoft Visual Studio .NET

  4. After a splash screen, one sees the Start Page. Click the New Project button

  5. New Project Dialog Box: Choose Visual Basic as the Project Type

  6. New Project Dialog Box: Choose Windows Application as the Template

  7. New Project Dialog Box: Give your project a name

  8. New Project Dialog Box: Click Browse to choose a location for your project

  9. Project Location Dialog Box: Use the Look in: drop-down box to select a folder

  10. Project Location Dialog Box: Use the Create New Folder button (if you want)

  11. New Folder Dialog Box: Enter the name of the new folder, then click OK

  12. Project Location Dialog Box: Click Open

  13. New Project Dialog Box: Click OK

  14. HelloWorld: Form1.vb (Design)

  15. Click the Save All button to see what we have so far

  16. Windows Explorer Folder we made Folder Visual Studio made

  17. What is a form? • A simple answer is that it’s a window – a surface upon which we will build a graphical user interface (GUI). • A more complex answer is that there are a number of things called forms • A Form base class – all of the generic code for a window provided by Visual Studio • A specific, programmer-designed class Form1 – the programmer adds specific features for the particular project • A form object – an instantiation of the above

  18. “Form1” in four places • “Form1” appears in four places • It is the name of the class we are making • Form1.vb is the name of the file containing the code for the class • “Form1” is the default value of the text property, which corresponds to what is written at the top of the window • It is the start-up object

  19. Change the name of the class: click on the form then find the (Name) property in the Properties Window Properties Window (Name) property

  20. Next change the name of the startup object • If you change the name of the class, you must change the name of the startup object. • The startup object is a property of the project that tells it where to start. • The only other option we would have for the startup object at this time is Sub Main

  21. Right click on the project (one level down) found in the Solution Explorer and choose Properties

  22. On the HelloWorld Property Pages, use the drop-down list to choose FrmHello as the Startup object and click OK

  23. Return to the Properties Window, find the Text property and change it

  24. One can list the properties by category or alphabetically Click here to alphabetize

  25. Categorizing the properties Click here to categorize

  26. Right click on the file in the Solution Explorer and choose Rename

  27. It’s traditional (though in VB not strictly necessary) to give the file and the class the same name

  28. Change the BackColor property of FrmHello • Click in the box to the right of BackColor in the Properties Window • A drop-down arrow will appear • Use the tab to select the palette from which you can choose the color

  29. Palettes

  30. FrmHello after BackColor chosen

  31. Customize the form with some controls • A control is an object (typically visible) that one places on a form to facilitate interaction with a user. It may be • A label to display a message • A textbox for the user to enter text • A button for a user to click • Etc. • The standard controls are in the toolbox.

  32. Place the mouse over the hammer and wrench icon on the left.

  33. Click on the tack icon at the top of the toolbox

  34. Click on the label button on the toolbox, it will appear depressed. Move the cursor over to the form it will appear as a crosshairs and a letter A

  35. Place the crosshairs where you want the upper left-hand corner of the label, drag across to where you want the lower right-hand corner and release. Upper left: begin drag here Lower right: end drag here

  36. Click on the plus sign to the left of the label’s Font property. Make sure Label1 appears in the drop-down box of the Properties Window

  37. This shows all of the individual properties related to the label’s font.

  38. Change the Font Size to 28.

  39. Use the drop-down list to make the Font Bold property True.

  40. Use the drop-down list to select the alignment of the text, choose MiddleCenter (vertical/horizontal)by clicking on the square

  41. Result of Label Text Alignment

  42. Change the label’s text property to “Welcome”

  43. Change the (Name) property of the label to lblWelcome.

  44. Hungarian notation • The naming of the form as FrmHello and the label as lblWelcome follow a naming convention known as Hungarian notation. • Hungarian notation consists of a standard (three-letter) prefix that identifies the type of object followed by a name that starts with a capital letter and has some meaning within the project.

  45. Search for list of Hungarian notation prefixes

  46. Choose link concerned with VB

  47. Hungarian notation (this reference is for version 6.0, but most of the prefixes are still useful)

  48. Add a second label, lblName, that prompts the user to enter his or her name

  49. Add a textbox, click on the Textbox button on the toolbox, use the crosshairs icon to drag the textbox into the desired location

  50. Name the textbox, txtName

More Related