Appendix A: Windows Forms. 2 Overview Describe the structure of a Windows Forms application –application entry point –forms –components and controls Introduce.

Slides:



Advertisements
Similar presentations
 2007 Dr. Natheer Khasawneh. Chapter 13. Graphical User Interface Concepts: Part 1.
Advertisements

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.
Create Windows ® Applications with.NET Allan Knudsen.NET Developer Evangelist Microsoft.
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.
1 Web Services Visual C# 2008 Step by Step Chapter 30.
Event-based Programming Roger Crawfis. Window-based programming Most modern desktop systems are window-based. Non-window based environment Window based.
DT265-2 Object Oriented Software Development 2 Lecture 3 : Windows Programming Lecturer Pat Browne
Getting Started Example ICS2O curriculum
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Neal Stublen Practice Solution  Create a new solution  Add a WinForms project  Add a Class Library project  Reference the library.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Microsoft Visual Basic 2005: Reloaded Second Edition
1- Date TimePicker 2- Month Calendar 3- User Defined Controls.
Object Oriented Programming Graphical User Interfaces Dr. Mike Spann
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,
Chapter 3 Introducing Visual Basic.NET. 3.1 Visual Basic.NET Windows Programming -Used to create Windows, Web, and Console applications -Uses predefined.
Week 2: WINDOWS PROGRAMMING Chapter 15 in “Beginning Visual C# 2010” ebook Chapter 4 in “”MCTS_Self-Paced_Training_Kit” ebook.
Virtual techdays INDIA │ Nov 2010 Developing Office Biz Application using WPF on Windows 7 Sarang Datye │ Sr. Consultant, Microsoft Sridhar Poduri.
CSC 298 Windows Forms.
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.
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling.
COS240 O-O Languages AUBG, COS dept Lecture 33 Title: C# vs. Java (GUI Programming) Reference: COS240 Syllabus.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 - Graphical User Interface Concepts: Part.
Visual C# 2012 How to Program 1. 2  A graphical user interface (GUI) allows a user to interact visually with a program.  Figure 14.1 shows a Visual.
Fundamentals of.NET NYU-SCPS. Session 7 MS Certification Exams in brief MS Certification Exams in brief Custom Attributes Custom Attributes More on Collections.
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.
Create Windows ® Applications with.NET Carlotta Eaton ( Associate Professor of IST New River Community College Slides by Microsoft.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
XML Web Service. Overview of XML Web Service ASP.NET XML Web services enable you to remotely access the properties and methods of classes across a network.
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.
Understanding Desktop Applications Lesson 5. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understanding Windows Forms Applications Understand.
 2002 Prentice Hall. All rights reserved. 1 Outline Mouse Event Handling Keyboard Event Handling Graphical User Interface Concepts:
Lecture Set 7 Procedures and Event Handlers Part B - The Structure of an Application Event Handlers.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Understanding Desktop Applications Lesson 5. Understanding Windows Forms Applications Windows Forms applications are smart client applications consisting.
User Interface Programming in C#: Basics and Events Chris North CS 3724: HCI.
1 15. Building Applications with Windows Forms Why Use Windows Forms? Structure of Windows Forms Using Windows Forms Using Controls Code Samples.
 2007 Pearson Education, Inc. All rights reserved Graphical User Interface Concepts: Part 1.
Chapter 1: An Introduction to Visual Basic .NET
Chapter 9 Programming Based on Events
Computing with C# and the .NET Framework
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.
Object Oriented Programming
Graphical User Interface Concepts: Part I
Chapter Eleven Handling Events.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface Developing a Simple Graphical User Interface (GUI)
Programming Based on Events
The University of Texas – Pan American
Creating a Windows Forms User Interface
Windows Controls Child Window Controls
Web Development Using ASP .NET
Chapter 14 Graphical User Interfaces with Windows Forms: Part 1
Visual C# - GUI and controls - 1
Chapter 13: Handling Events
Visual Programming COMP-315
Week 2: WINDOWS PROGRAMMING
Presentation transcript:

Appendix A: Windows Forms

2 Overview Describe the structure of a Windows Forms application –application entry point –forms –components and controls Introduce deployment over networks

3 Windows Forms Windows Forms are classes for building UIs –forms, controls, dialogs, etc. –part of the.NET Framework Library –core classes in System.Windows.Forms namespace Possible uses include: –stand-alone Windows applications –web services front-ends –intranet “smart clients”

4 Visual Studio Visual Studio.NET provides development environment –starter templates, drag-and-drop editing, property grid, etc.

5 Application Structure Windows Forms application has three main pieces –the application itself –forms in the application –controls and components on the forms myForm label1 button1 Label "Hello, World!" Button "OK" Application mainForm

6 Application Application class represents the application itself –Run method processes UI events delivered by Windows –provides access to application environment ExecutablePath, CommonAppDataPath, UserAppDataPath, etc. –no instances, all members are static class MyApp { public static void Main() { MyForm form = new MyForm(); Application.Run(form); } start application

7 Form Form class represents window, provides appropriate services –properties: Size, Location, Controls, ShowInTaskbar –methods: Show, Close, SetDesktopLocation –events: Load, Click, Closing Common to derive from Form to create custom form class MyForm : Form { public MyForm() { this.ShowInTaskbar = false; this.Location = new Point(10, 10); this.Size = new Size(100, 100); } define custom form set properties

8 Form border Forms can look like windows, dialogs, or tools –controlled using FormBorderStyle property –set ShowInTaskbar property to false for tool windows –window border styles show the icon from the Icon property

9 Form properties Form has many properties –used to customize appearance and behavior public class Form : ContainerControl { public IButtonControl AcceptButton { get; set; } public IButtonControl CancelButton { get; set; } public bool HelpButton { get; set; } public Icon Icon { get; set; } public String Text { get; set; } public Size MaximumSize { get; set; } public Size MinimumSize { get; set; } public MainMenu Menu { get; set; } public bool ShowInTaskbar { get; set; } public FormBorderStyle FormBorderStyle { get; set; }... } properties

10 class MyForm : Form { Button button1 = new Button(); Label label1 = new Label (); public MyForm() {... this.Controls.Add(button1); this.Controls.Add(label1 ); }... } myForm Form as container Form manages a list of controls –stored in Controls collection property Controls button1label1 all forms inherit Controls collection add to collection

11 Form layout Form determines layout for controls it manages –recalculates as needed, such as when user resizes form –tries to accommodate control preferences for size and location –uses Anchor and Dock property of each control –can override OnLayout method to do custom layout resize

12 Controls Controls are visual components derived from Control class –common controls supplied ScrollableControl Object Component Control ButtonBase Button CheckBox RadioButton ContainerControl Form PropertyGrid UserControl Panel TabPage ListControl ComboBox ListBox MonthCalendar PictureBox ProgressBar Splitter StatusBar DataGrid DateTimePicker GroupBox Label

13 Control properties Controls supply many properties –used to customize appearance and behavior public class MyForm : Form { private Button button1; public MyForm() { button1 = new Button(); button1.Name = "OK button"; button1.Text = "OK";... } set properties

14 Control events Controls offer events –click –mouse or keyboard activity –property value change –paint –etc. public class Control : Component... { public event EventHandler Click; public event EventHandler Enter; public event EventHandler TextChanged; public event KeyPressEventHandler KeyPress; public event MouseEventHandler MouseDown; public event PaintEventHandler Paint;... } events

15 Event handlers Several types of event handler delegates –generic EventHandler used for many events –specific types for some events such as mouse and keyboard Event handlers have two arguments –control that generated event –event details in EventArgs or derived object the control that generated the event event details delegate void MouseEventHandler (object sender, MouseEventArgs e); delegate void EventHandler (object sender, EventArgs e); delegate void KeyPressEventHandler(object sender, KeyPressEventArgs e);

16 EventArgs Event handlers pass event details to handler –passed in EventArgs or derived class object class MouseEventArgs : EventArgs { public MouseButtons Button { get; } public int Clicks { get; } public int X { get; } public int Y { get; }... } public class EventArgs { } generic base class so no event data class KeyPressEventArgs : EventArgs { public char KeyChar { get; }... } info specific to mouse event info specific to keyboard event

17 Event registration Clients can register for events –define method with signature required by delegate –create delegate instance and add to event public class MyForm : Form { private Button button1; void button1_Click(object sender, EventArgs args) {... } public MyForm() {... button1.Click += new EventHandler(this.button1_Click);... } register define method

18 Components Components are non-visual elements useful in UI –e.g. Timer, FileSystemWatcher, EventLog, etc. –extend System.ComponentModel.Component shown in component tray when added to form components in toolbox

19 Threading Control should only be accessed by the creating thread –messages from different threads subject to interleaving –resulting race conditions can lead to inconsistent behavior Control class provides methods for thread-switching –see docs for InvokeRequired, Invoke, BeginInvoke

20 No-touch deployment Windows forms applications can be deployed automatically –client uses browser to access executable –needed assemblies downloaded and stored in download cache –program runs locally –executable downloaded only if changed since last run GET /App.exe HTTP/1.1 Client App.exe Server cache App.exe

21 Summary Windows Forms supports UI development –applications, forms, controls –integration with designer –no-touch deployment over networks