Chapter 9 Programming Based on Events

Slides:



Advertisements
Similar presentations
Lists, Loops, Validation, and More
Advertisements

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1 STARTING OUT WITH Visual Basic 2008 FOURTH EDITION Tony Gaddis.
Microsoft Expression Web-Illustrated Unit J: Creating Forms.
Mobile Development Introduction to Visual Studio Development Rob Miles Department of Computer Science.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Excel Project 7 Using Macros and Visual Basic for Applications (VBA) with Excel.
Microsoft Visual C#.NET: From Problem Analysis to Program Design1 Chapter 9 Programming Based on Events Microsoft Visual C#.NET: From Problem Analysis.
C# Programming: From Problem Analysis to Program Design1 9 Programming Based on Events.
C# Programming: From Problem Analysis to Program Design1 Programming Based on Events C# Programming: From Problem Analysis to Program Design 3 rd Edition.
Compunet Corporation Programming with Visual Studio.NET GUI Week 13 Tariq Aziz and Kevin Jones.
Programming Based on Events
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 3-1 of…
Graphical User Interface (GUI) A GUI allows user to interact with a program visually. GUIs are built from GUI components. A GUI component is an object.
Programming Based on Events
CA 121 Intro to Programming Tariq Aziz and Kevin Jones GUI Programming in Visual Studio.NET Chapter 3 Tariq Aziz and Kevin Jones.
1 Windows Printing. 2 Objectives You will be able to Output text and graphics to a printer. Print multipage documents. Use the standard Windows print.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
1 Graphical User Interfaces Part 2 Outline ListBoxes and CheckedListBoxes ListBoxes CheckedListBoxes ComboBoxes.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
Chapter 12: Using Controls. Examining the IDE’s Automatically Generated Code A new Windows Forms project has been started and given the name FormWithALabelAndAButton.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
ListBox, ComboBox, Menu Chapter 5.4, ComboBox Control: Properties & Methods u Combines TextBox features with a short drop- down list  cboOne.AddItem(string)
Intro to More Controls in C#. C# Demonstration We already touched on labels and buttons Ad-hoc demo of controls – Textboxes Multiline – Checkbox – Radiobutton.
1 Chapter Eleven Handling Events. 2 Objectives Learn about delegates How to create composed delegates How to handle events How to use the built-in EventHandler.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
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.
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.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
AdditionalControls 1. The MenuStrip 2 Double-click Let’s begin to design the menu bar for VB! Let’s begin to design the menu bar for VB! 3.
Unit 6 Repetition Processing Instructor: Brent Presley.
1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
Lecture Set 7 Procedures and Event Handlers Part B - The Structure of an Application Event Handlers.
Appendix A: Windows Forms. 2 Overview Describe the structure of a Windows Forms application –application entry point –forms –components and controls Introduce.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
Module 3: Creating Windows-based Applications. Overview Creating the Main Menu Creating and Using Common Dialog Boxes Creating and Using Custom Dialog.
Dive Into® Visual Basic 2010 Express
Chapter 2: The Visual Studio .NET Development Environment
INF230 Basics in C# Programming
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Computing with C# and the .NET Framework
Programming Based on Events
C# Programming: From Problem Analysis to Program Design
Chapter 1: An Introduction to Visual Basic 2015
3.01 Apply Controls Associated With Visual Studio Form
Chapter Eleven Handling Events.
CHAPTER FIVE Decision Structures.
3.01 Apply Controls Associated With Visual Studio Form
Using Procedures and Exception Handling
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Windows Desktop Applications
Repeating Program Instructions
Variables and Arithmetic Operations
Custom dialog boxes Unit objectives
Programming Based on Events
Microsoft Visual Basic 2005: Reloaded Second Edition
Delegates & Events 1.
CIS16 Application Development and Programming using Visual Basic.net
Lecture Set 10 Windows Controls and Forms
Module 8: Creating Windows-based Applications
Web Development Using ASP .NET
Chapter 13: Handling Events
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
GUI Programming in Visual Studio .NET
Presentation transcript:

Chapter 9 Programming Based on Events Austin Joseph

Topics in Chapter 9 Delegates Event Handling List Box Control Combo Box Control Menu Strip Control CheckBox Control RadioButton Control We will review the bolded topics in one session

Delegates What is a Delegate? Delegates are pretty much pointer functions. They are references toward methods.

Example: Delegate delgate string ReturnSimpleString(); { public static string Aheading(); return “Your age will be”; } public static string StringMethod(); return “in 10 Years” The string method with the delegate both return strings, both have zero parameters. The delegate just simply specifies what the signature should be

Making Delegate Instances Associate the delegate with the method. A delegate instance is defined using the method name as the argument inside the parenthesis. After the instantiation, the delegate identifier saying3 references the EndStatement( ) method. Saying3( ) calls the EndStatement( ) method. ReturnSimpleString saying3 = new ReturnSimpleString(stringMethod);

Your age will be 28 in 10 Years delegate string ReturnSimpleString(); class delegateExample { static void Main( int age = 18; ReturnSimpleString saying1 = new ReturnSimpleString(AHeading); ReturnSimpleString saying2 = new ReturnSimpleString((age + 10).ToString); ReturnSimpleString saying3 = new ReturnSimpleString(StringMethod); MessageBox.Show(saying1() + saying2() + saying3()); } static string AHeading() (Output of the program) return “Your age will be”; } static string stringMethod() { return “in 10 years”; Your age will be 28 in 10 Years OK

Event Handling You might be surprised, but you have actually dealt with Event Handling before in one of the Chapter 8 Programs. Remember Program 3? It asked to create event-handler methods that retrieve the values, perform the calculations, and display the result of the calculations on a Label object. That's part of Event Handling.

Event Handling Example Event Wiring - While creating a forms design, you've probably added a button on the design. Two thing happened when you double clicked the button. The button click event was registered and an event handler method was created. Example this.button1.Click += new System.EventHandler(this.button1_Click); (You'll find this code above in the Form Designer) And the code above is generated when you double click the button in Form Designer. This is a delegate Type. Button1_click method is associated with that delegate private void button1_Click(object sender, System.EventArgs e) { }

So how are delegates and Events related? Assumingly you understand what a delegate is by now. When you double click the button in the forms and it shows the event handler method (Above) but the code above the event handler is also registered in the Form Designer. The System.EventHandler is the delegate which associates the method Button One Click. This same idea will continue on with, List Box Control, Combo Box Control and Menu Strip Control. But with different naming standards

ListBox Control Regular List How to make a list Go to properties 1.) Make sure the List is shown 2.) Scroll down and find Items - After finding items, enter in the items which you will want

Code for ListBox The Code found In Form Designer this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged); Code Found in Forms private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { } this.txtBoxResult.Text = this.listBox1.SelectedItem.ToString();

Making a list box, but with multiple items being selected Go back to properties, and change Selection Mode into MultiExtended. This allow users to make selections using the Ctrl Key and clicking the mouse Once editing the properties is done, the event handler has to be edited. private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { string result = ""; foreach (string activity in listBox1.SelectedItems) result += activity + " "; } this.textBox1.Text = result;

Adding Items to a list Add( ) method (More of these types can be used, example Sorted Property) } private void button1_Click(object sender, EventArgs e) { listBox1.Items.Add(textBox2.Text);

Combo Box Similar to the List Box. Only difference, Combo Box has a dropdown style Properties - Different types of Drop Downs DropDown DropDownList (Disables new text entering in ComboBox)

Combo Box Regular ComboBox Example private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { this.textBox1.Text = this.comboBox1.SelectedItem.ToString(); }

Adding on Items to a ComboBox Register a KeyPress Event KeyPress() Very Simple Concept (The Bottom Code will automatically register in Form Designer) this.flowerBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.comboBox1_KeyPress);

foreach (int item in listBox1.SelectedIndices) private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e) { this.textBox1.Text = ""; foreach (int item in listBox1.SelectedIndices) this.textBox1.Text += this.listBox1.Items[item] + ""; } this.textBox1.Text = flowerBox.Text; private void comboBox1_KeyPress(object sender, KeyPressEventArgs e) private void ADDbutton_Click(object sender, EventArgs e) flowerBox.Items.Add(textBox1.Text);

Menu Strips Left Side of screen, can be found in ToolBox Can be found on Page 505

Assignments (Refer back to Page 575 in book if needed) Program 1 (5 Pointer) – Make a program in which the user enters its name, email address, and phone number. Use a menu strip to display a show box with the three statements, a clear entire strip and an exit strip Program (10 Pointer) (Not in book) – Tax Calculator User enters salary 3.07% state tax 3.05% city tax 15 % federal income tax Find out total contribution MenuStrip - Exit Option and clear textbox