Forms and Controls Part 3 dbg --- Naming conventions, Button, Event handlers, Label.

Slides:



Advertisements
Similar presentations
CS0004: Introduction to Programming Visual Studio 2010 and Controls.
Advertisements

Chapter 2 –Visual Basic, Controls, and Events
CA 121 Intro to Programming Tariq Aziz and Kevin Jones GUI Programming in Visual Studio.NET Chapter 1 Tariq Aziz and Kevin Jones.
Using Multiple Forms. Creating a New Form ProjectAdd Windows Form.
Slide 1 ICS 012 Visual Programming I Ahmed Esmat Second.
Chapter 31 Visual Basic Controls A Form is a windows-style screen displayed by Visual Basic programs. In a form, a programmer can create objects in a form.
Compunet Corporation Programming with Visual Basic.NET GUI Week # 11 Tariq Ibn Aziz.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Copyright © 2012 Pearson Education, Inc. Chapter 2 Introduction to Visual C#
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
C# Programming: From Problem Analysis to Program Design1 Introduction to Windows Programming C# Programming: From Problem Analysis to Program Design 3.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Chapter 2 –Visual Basic, Controls, and Events
Chapter 3 Introduction to Event Handling and Windows Forms Applications.
2. Introduction to the Visual Studio.NET IDE 2. Introduction to the Visual Studio.NET IDE Ch2 – Deitel’s Book.
Slide 1 Chapter 2 Visual Basic Interface. Slide 2 Chapter 2 Windows GUI  A GUI is a graphical user interface.  The interface is what appears on the.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Visual Basic Chapter 1 Mr. Wangler.
05/09/ Introducing Visual Basic Sequence Programming.
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Programming with Microsoft Visual Basic 2012 Chapter 12: Web Applications.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
IE 411/511: Visual Programming for Industrial Applications
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
Visual Studio.NET Part 2 dbg --- Using the VS.NET Integrated Development Environment.
1 1 Lab1 Ismail M. Romi – IT Dept, PPU, Visual Basic 2005 Programming Tour.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
Chapter 3: Using GUI Objects and the Visual Studio IDE.
Power Point Presentations A Step by Step Guide. Contents The very first step Choosing slide layout Adding text boxes Custom Animation Changing slide design.
Visual Studio.NET Part 2 dbg --- Using the Integrated Development Environment.
Basic Controls & Properties Chapter 2. Overview u VB-IDE u Basic Controls  Command Button  Label  Text Box  Picture Box u Program Editor  Setting.
Copyright © 2001 by Wiley. All rights reserved. Chapter 2: Using Visual Basic to Create a First Project Getting Started with VB Development Environment.
Debugging and Menus Part07dbg --- Solving the problem, Debugging in Break time, Menus.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Tutorial 11 Five windows included in the Visual Basic Startup Screen Main Form Toolbox Project Explorer (Project) Properties.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
BIL528 – Bilgisayar Programlama II Introduction 1.
Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”
Chapter Two Creating a First Project in Visual Basic.
Controls. Adding Controls to Form -You can pick controls from the toolbox. -To add the controls from Toolbox to the Form You have be in design view. -To.
Chapter 2 – Introduction to the Visual Studio .NET IDE
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
CS130 Project 1 A simple VB application ("project" or program): user enters amount of sales then clicks the "Calculate button", the application displays.
What is Visual Basic.NET? 110 B-1 e.g. a word processor doesn’t do anything until the user clicks on a button, types text... A programming language that.
More Controls and Their Properties Part 4 dbg --- TextBox, CheckBox, RadioButton, GroupBox, ToolTips,
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.
Forms and Controls Part 3 dbg --- Naming conventions, Button, Event handlers, Label.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
Object-Oriented Application Development Using VB.NET 1 Chapter 2 The Visual Studio.NET Development Environment.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Visual Basic.Net. Software to Install Visual Studio 2005 Professional Edition (Requires Windows XP Pro) MSDN Library for Visual Studio 2005 Available.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Programming with Visual Basic.NET. Quick Links Program Code The Code Window The Event Procedure Assignment Statements Using AutoList Radio Buttons Buttons.
Chapter 2 - VB 2008 by Schneider1 Chapter 2 –Visual Basic, Controls, and Events 2.1 An Introduction to Visual Basic 2.2 Visual Basic Controls 2.3 Visual.
Chapter 7 Multiple Forms, Modules, and Menus. Section 7.2 MODULES A module contains code—declarations and procedures—that are used by other files in a.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
2-1 Chapter 2 Using VB.NET to Create a First Solution.
Chapter 8 Multiple Forms, Modules, and Menus. Introduction This chapter demonstrates how to: – Add multiple forms to a project – Create a module to hold.
Chapter 2: The Visual Studio .NET Development Environment
How to design a Windows Forms application
Chapter 3 Fundamentals of Programming in Visual Basic 3
Chapter 2 Visual Basic Interface
CIS16 Application Development Programming with Visual Basic
Simple Windows Applications
Visual programming Chapter 2: Events and Event Handling
Presentation transcript:

Forms and Controls Part 3 dbg --- Naming conventions, Button, Event handlers, Label

2 The Form as a Platform A Windows application form can act as a container for additional objects. Objects that can be contained by forms (and are coded by existing classes in the Foundation Class Library) are called controls.

3 Ways to Add Controls via the Toolbox There are several ways to add a control to a form: 1.Dragging a control from the Toolbox and dropping it on the Designer View of the form. 2.Double-clicking a control icon in the Toolbox to add a that control to the upper left-hand corner of the form. 3.Clicking on a control icon in the Toolbox and “drawing” the control on the form. 4.Clicking on a control icon in the Toolbox and then clicking again on the form. As you add controls to your form via the Designer, code to create the objects and add the controls and their events to various collections is automatically added to the formname.Designer.cs file.

4 A Form with One Button Using one of the 4 described techniques, we will add a Button object to a new form. We will program a event handler method that will respond to the Click event, generated when the mouse is clicked while its pointer is positioned over the button. This event is termed a Button.Click event.

5 Programming the Click Handler Function We will create a new application project and program its single event handler method “step- by-step”. When the button is clicked, the event handler method will be executed and the form will close.

6 Double-clicking a control on the form will automatically create a default event handler skeleton and the necessary “event wiring”. A default event handler is the most likely event handler for a particular object. The Click handler is the default event handler for a button control. Programming the Click Handler Function

Naming and Renaming Strategies and Conventions

8 Object Naming for Clarity At times, we have accepted default object names, generated by the IDE, for these first examples. To avoid ambiguity and enforce clarity, it is a good idea to use a standard naming convention for all the objects that you will create for your Windows applications. We will follow some accepted conventions as we complete the next simple application project.

9 Naming Strategies Give all objects meaningful and memorable names. Use a simple three-character prefix to identify controls. Capitalize the first letter of multiple-word names; this is called camel-casing. Ex. frmOrderConfirmation btnCalcShippingCost Assign meaningful names to projects and solutions (namespaces) as well.

10 Form Class File A default class that defines the startup form is created with each new Windows application project. This class is stored in a separate file with the default name Form1.cs. Your first task in developing a new Windows application should be to rename this file.

11 Renaming the Form Class File Highlight the Form1.cs file in the Solution Explorer Window. Right-click the file and select Rename. Use the prefix frm for the new file name. Assign a meaningful name to the file, remembering to retain the original.cs file extension.

12 Renaming the Form Class As you rename the form object with a unique and meaningful name, VS2005 asks you if you want to use this new name in 3 locations? Yes. The new name will replace Form1 in 3 places: –Application.Run(new Form1()); // startup object in Main() –Form1.cs //in Solution Explorer –Form1.Designer.cs //in Solution Explorer While the Form Class file is selected in the Solution Explorer, switch to the Designer View.

13 Renaming the Form Class Select the form in the Designer and assign a meaningful name to its Name property using the Property Window. It is usually best to use the same name for the class that you assigned to the class file, including the frm prefix. No.cs extension here.

14 Add and Rename a Button Use one of the techniques described earlier to add a new Button object to the form. Select the button in the designer and assign a new Name using the Property Window; use the btn prefix.

15 Add a Default Event Handler The Click event is the default event for a Button object. We can add the default event for the Button by simply double-clicking the button in the Designer. The code view of the class will display, complete with the new default event handler method.

16 Running the Close() Method The Form class has a Close() method. Since we want to close the current object (the form) when we click the Close button, we will run the Close() method on our form by typing this.Close(); in the click handler for the Close button. The keyword this is used as a shorthand or alias for the current object.  CloseHandler

Controls for Text Output The Label

18 Text with Labels A label is a simple control that exists only to display text. Label controls are used to display headings, informational messages, and output information. In C#.NET 2005, a label is sized automatically based on the amount of text that it contains (it will resize automatically if you change the FontSize property). As a result, you can’t size a label by dragging its handles unless you change its AutoSize property to False (allowing multi- line word wrap).

19 When to Assign a Custom Name Labels that are merely used as headings or informational messages, and whose contents do not change at run time, can use the assigned default names (Label1, Label2, etc). Labels whose appearance or contents will change at run time should be assigned meaningful names that begin with the prefix, lbl.

20 Assigning Text at Design Time Text may be assigned to labels by using the Text Property at design time.  DesignTimeLabelText

21 Assign Text During Run Time Although the user can not change the text of a label directly at run time, handlers for events raised by other controls or the form itself can be programmed to change the contents of a label. Here, click handlers for two buttons and a collection of menu items are programmed to change the Text property of a label at run time.  RunTimeLabelText

22 A Plan for Designing the Solution 1.Decide which controls will be needed and which events will be needed. Use Planning Guides on next slides. 2.Draw a sketch on paper with names for controls that will have events associated with them, and those whose property values will change. Use the Designer to place controls on form. 3.Set (design-time) property values. 4.Write event handlers, which may change some property values at run-time.

23 Let’s Do One Together Create a project to display the daily specials for “your” diner. Make up a name for your diner and display it in a label at the top of the form. Add a label to display the appropriate special depending on the button that is pressed. The buttons should be: –Soup of the Day –Chef’s Special –Fish of the Day Also include an Exit button.

24 Plan First, Then Design Plan the Objects Plan the Events Object (Forms and Controls) PropertySetting (design-time) Action (pseudocode) Object (Forms and Controls) Event