Computing with C# and the .NET Framework

Slides:



Advertisements
Similar presentations
Information System Design Lab 5&6. User Interface Design.
Advertisements

 2007 Dr. Natheer Khasawneh. Chapter 13. Graphical User Interface Concepts: Part 1.
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.
Programming Based on Events
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.
ListBoxes The list box control allows the user to view and select from multiple items in a list. CheckedListBox control extends a list box by including.
Group Boxes and Panels Arrange components on a GUI Buttons and etc. can be placed inside a group box or panel. All these buttons move together when the.
Programming Based on Events
C# Programming: From Problem Analysis to Program Design1 Introduction to Windows Programming C# Programming: From Problem Analysis to Program Design 3.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
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.
Chapter 8: Writing Graphical User Interfaces
CSCI 3328 Object Oriented Programming in C# Chapter 2: Introduction to Visual C# Programming 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg,
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
Chapter 12: Using Controls. Examining the IDE’s Automatically Generated Code A new Windows Forms project has been started and given the name FormWithALabelAndAButton.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Assignment #1 Advanced Computer Programming.
COS240 O-O Languages AUBG, COS dept Lecture 33 Title: C# vs. Java (GUI Programming) Reference: COS240 Syllabus.
Controls in C++/CLI (2) CheckBox RadioButton GroupBox ListBox.
Intro to More Controls in C#. C# Demonstration We already touched on labels and buttons Ad-hoc demo of controls – Textboxes Multiline – Checkbox – Radiobutton.
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.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
1 Chapter Ten Using Controls. 2 Objectives Learn about Controls How to create a Form containing Labels How to set a Label’s Font How to add Color to a.
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 C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Object-Oriented Application Development Using VB.NET 1 Chapter 10 VB.NET GUI Components Overview.
COMPUTER PROGRAMMING I 3.02 Apply Properties Associated with the Controls.
1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Visual Basic/ Visual Studio Brandon Large. Connecting to prior knowledge In your notes write down what the two main parts of the computer are. The “software”
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
Visual Basic Fundamental Concepts
Chapter 9 Programming Based on Events
INF230 Basics in C# Programming
Apply Procedures to Develop Menus, List Box and Combo Box Objects
C# Programming: From Problem Analysis to Program Design
Programming Based on Events
C# Programming: From Problem Analysis to Program Design
Chapter 1: An Introduction to Visual Basic 2015
Chapter Topics 15.1 Graphical User Interfaces
CSCI 3328 Object Oriented Programming in C# Chapter 2: Introduction to Visual C# Programming UTPA – Fall 2012 This set of slides is revised from lecture.
Chapter 8: Writing Graphical User Interfaces
3.01 Apply Controls Associated With Visual Studio Form
Chapter Eleven Handling Events.
Visual programming Chapter 1: Introduction
3.01 Apply Controls Associated With Visual Studio Form
Reference: COS240 Syllabus
Using Procedures and Exception Handling
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Windows Desktop Applications
Repeating Program Instructions
Visual Basic..
Programming Based on Events
Microsoft Visual Basic 2005: Reloaded Second Edition
المحاضرة الأولى Lab(1) أ.ساره الأحمدي برمجة حاسب 2.
The University of Texas – Pan American
CIS16 Application Development and Programming using Visual Basic.net
Exception Handling and Event Handling
Web Development Using ASP .NET
Chapter 15: GUI Applications & Event-Driven Programming
Visual C# - GUI and controls - 1
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.
Presentation transcript:

Computing with C# and the .NET Framework User Interfaces

Controls A control is a component with a visual representation A Form is a Control that can contain other controls Controls introduced in this chapter include Button, Label, TextBox, RadioButton, ComboBox, ListBox, PictureBox, and CheckBox

Configuring a Form .NET Framework – write code in constructor (using Visual Studio .NET – change properties, drag controls) Text = “Button Press”; // text in form’s title Size = new Size(300, 200); // size of form Controls.Add(print); // add a button Controls.Add(message); // add a label

Configuring a control print.Text = “Print”; // set button label print.Location = new Point(20, 30); //place button message.Text = “Message goes here”; // label Message.Size = new Size (message.PreferredWidth, message.PreferredHeight); // make label big enough to hold message (Using Visual Studio .NET, set properties to generate this code automatically)

Events A class may contain an event that allows it to provide notifications. A Button has a Click event that will occur when the user click the button. To make the button work, we register an EventHandler delegate with it. When the user clicks the button, the code in the registered event handler will be called

Handling a Click event private Button print = new Button() //the control print.Click += new EventHandler(Print_Click); // register Print_Click method, which must be // an EventHandler type with two parameters and no return value protected void Print_Click(Object sender, EventArgs e){ message.Text = "Hi there"; } // set message label when user clicks button

The .NET Button code Declares a Click event (inherited from Control). Associates an EventHandler delegate as the type of method needed to handle a Click event. Raises the Click event when the user clicks the button, causing calls to all registered delegates. We program a ButtonPress application --

Our ButtonPress code Declares a Print_Handler method for the Print button that fits the definition of the EventHandler delegate. Registers Print_Handler as a new delegate to handle the Click event for the Print button.

Delegates A delegate defines a class that encapsulates one or more methods To make a button work we register an EventHandler delegate that .NET has predefined as public delegate void EventHandler(Object sender, EventArgs e) Print_Click must have these same parameters and return type

TextBox A TextBox lets the user enter data By default it allows a single line Clicking EnterPrice adds value in text box to sum Clicking Average displays the average.

RadioButton and ComboBox All radio buttons in a Form belong to one group by default. Selecting one deselects the others. A ComboBox contains a list of items, showing one, and allowing the user to pop up the rest. // Add items to combo box color.Items.Add("Red"); color.Items.Add("Green"); color.Items.Add("Blue");

Example 9.4 Handle the button Click event. When the user clicks the button, we determine which radio button is check and which item is selected in the combo box.

Example 9.5 Respond to radio buttons and combo box immediately. Selecting a RadioButton generates a CheckedChanged event Selecting a ComboBox item generates a SelectedIndexChanged event.

StringBuilder A String cannot be changed. Repeated concatenation causes the allocation of new String objects. Using StringBuilder is more efficient. StringBuilder s = new StringBuilder(“The “); s.Append(animal1); s.Append(“ and “); …

PictureBox Use PictureBox to display an image private PictureBox photo = new PictureBox(); photo.Image = Image.FromFile(“gittleman.gif”);

ListBox Displays a list of items SelectionMode.One -- choose one item SelectionMode.MultiSimple – select multiple items Selecting an item generates a SelectedIndexChanged event SelectedItem property -- returns Object selected SelectedItems returns a collection of items selected. Use array notation to access each

CheckBox Can select more than one CheckBox, or none A user selection generates a CheckedChanged event Register an EventHandler delegate author.CheckedChanged += new EventHandler(Photo_Changed); Put event handling code in Photo_Changed method

Using Visual Studio .NET Create a C# Windows Application project Click on a control in Toolbox and click on Form to position the control Visual Studio .NET generates all the initialization code in the InitializeComponent method. Double-click on a control to bring up a code template for its event handler. Fill in code.