User Interface Programming in C#: Basics and Events Chris North CS 3724: HCI.

Slides:



Advertisements
Similar presentations
Graphic User Interfaces Layout Managers Event Handling.
Advertisements

 2007 Dr. Natheer Khasawneh. Chapter 13. Graphical User Interface Concepts: Part 1.
User Interface Programming in C#: Graphics
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
CA 121 Intro to Programming Tariq Aziz and Kevin Jones GUI Programming in Visual Studio.NET Chapter 1 Tariq Aziz and Kevin Jones.
Swing CS-328 Dick Steflik John Margulies. Swing vs AWT AWT is Java’s original set of classes for building GUIs Uses peer components of the OS; heavyweight.
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.
Advanced Object-Oriented Programming Features
Compunet Corporation Programming with Visual Basic.NET GUI Week # 11 Tariq Ibn Aziz.
Object-Oriented Analysis and Design
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Events in Java Swing Chris North cs3724: HCI. Typical command line program Non-interactive Linear execution program: main() { code; }
Event-based Programming Roger Crawfis. Window-based programming Most modern desktop systems are window-based. Non-window based environment Window based.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
Java Swing Chris North cs3724: HCI. AWT to Swing AWT: Abstract Windowing Toolkit import java.awt.* Swing: new with Java2 import javax.swing.* Extends.
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
Developing User Interfaces (DUI) Chris North cs3724: HCI.
DT265-2 Object Oriented Software Development 2 Lecture 3 : Windows Programming Lecturer Pat Browne
OOP Languages: Java vs C++
Written by Liron Blecher
Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Object Oriented Programming Graphical User Interfaces Dr. Mike Spann
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
CSC 298 Windows Forms.
Session 08: Architecture Controllers or Managers Graphical User Interface (GUI) FEN AK - IT Softwarekonstruktion.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
3461A Readings from the Swing Tutorial. 3461A Overview  The follow is the Table of Contents from the trail “Creating a GUI with JFC/Swing” in the “The.
COS240 O-O Languages AUBG, COS dept Lecture 33 Title: C# vs. Java (GUI Programming) Reference: COS240 Syllabus.
Carnegie Mellon University MSCF1 C#/.NET Basics 2 Some code is from “C# in a Nutshell”
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 - Graphical User Interface Concepts: Part.
Object Oriented Software Development 9. Creating Graphical User Interfaces.
Sample Application Multi Layered Architecture (n-tier): –Graphical User Interface (GUI): Forms, components, controls The Visual Designer in Visual Studio.
Introduction to Windows Programming
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
1 Visual Studio.NET.NET as a Teaching Tool John D. Haney John M. Lovely Northern Arizona University College of Business Administration.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
Introduction to Visual Studio & GUI Programming Prepared by: Ahmad Ramin Rahimee Assistant Professor ICTI.
1 CSC 222: Object-Oriented Programming Spring 2012 netBeans & GUIBuilder  netBeans IDE create/edit/run a project  GUIBuilder JFrame, JButton, JTextField,
An Introduction to Programming and Object Oriented Design using Java 3 rd Edition. Dec 2007 Jaime Niño Frederick Hosch Chapter 18 Integrating user interface.
C# GUI - Basics. Objectives.NET supports two types: WinForms, traditional, desktop GUI apps. WebForms – newer, for Web apps. Visual Studio.NET supports.
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.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
SEEM3460 Tutorial GUI in Java. Some Basic GUI Terms Component (Control in some languages) the basic GUI unit something visible something that user can.
Bill Campbell, UMB Microsoft's.NET C# and The Common Language Runtime.
Introduction to visual programming C#. Learning Outcomes In this chapter, you will learn about :  Event-Based Programming  The Event Based Model  Application.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 32 JavaBeans and Bean.
Appendix A: Windows Forms. 2 Overview Describe the structure of a Windows Forms application –application entry point –forms –components and controls Introduce.
Java - hello world example public class HelloWorld { public static void main (String args[]) { System.out.println("Hello World"); }
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
Java Swing and Events Chris North cs3724: HCI. Presentations nadine edwards, steve terhar Vote: UI Hall of Fame/Shame?
Java FX: Scene Builder.
INF230 Basics in C# Programming
Visual Basic Code & No.: CS 218
Java Swing.
Introduction to .NET Framework Ch2 – Deitel’s Book
Graphical User Interface Concepts: Part I
Reference: COS240 Syllabus
Ellen Walker Hiram College
Social Media And Global Computing Introduction to Visual Studio
Understanding the Visual IDE
Presentation transcript:

User Interface Programming in C#: Basics and Events Chris North CS 3724: HCI

GUI Development: Goals 1.General GUI programming concepts GUI components, layouts Event-based programming Graphics Direct Manipulation, Animation MVC architectures Data-driven UIs 2.C#,.NET Windows Forms Events, delegates GDI+ Threads ADO.net Goal: learn other languages quickly, same concepts VB, Xwin, Java 49, …

C# Background C# = VB + Java(best of both!) Basic statements identical to C++, Java Object-oriented only! main( ) is inside a class No global variables “interfaces” No pointers (object references only), safe No delete: automatic garbage collection Error Handling, exceptions (try, catch) GUI: Windows Forms Libraries: Data structs, databases, … Component-based: (“assembly”) reflection No.h files Visual Studio.NET: CLR, multi-language, web, XML, services, …

C# Materials MS Visual Studio.Net (2002, 2003) MSDN (integrates with VS) VS Dynamic Help Books MS Visual C#.NET, MS Press –C# language –Window Forms, GDI+ MSDN online

Getting Started Visual Studio New Application Drag-n-drop GUI builder Code editor Properties Methods Events

Visual Studio.Net controls designer Properties, events

Components API Properties Like member fields Get, set E.g. Button1.Text = “Press Me” Methods Like member functions Tell component to do something E.g. Button1.Show( ) Events Like callback functions Receive notifications from component E.g. Button1.Click(e)

Anatomy of a C# WinApp namespace MyWindowsApplication1 { public class MyForm1 : System.Windows.Forms.Form { // inherit from Form base class public MyForm1( ) // constructor, calls InitializeComponent( ) private void InitializeComponent( ) // VS auto-generated GUI code protected override void Dispose( bool disposing ) // standard method to clean up resources static void Main( ) { // App starts here! Application.Run(new MyForm1( )); // create a new MyForm1 and run the main event loop }

Adding GUI Controls public class MyForm1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; …// member variables for each GUI control private void InitializeComponent( ) // VS auto-generated GUI code // create GUI controls: this.button1 = new System.Windows.Forms.Button( ); // set properties of GUI controls: this.button1.Text = "button1"; // add controls to their parent or Form: this.Controls.AddRange( new System.Windows.Forms.Control[] {this.button1} ); }

GUI Tree Structure Panel Button Form Label GUIInternal structure containers Panel Button Form Label

GUI Layout Management Fixed position: X,Y location W,H size Anchor: Maintain distance to: Top, Left, Bottom, Right Dock: Fill space in: Top, Left, Bottom, Right, Fill AutoScroll: Scrolling control panels Z-Order: Front to back order

Layout Combinations Button TextBox

Layout Combinations Form Panel Button JTextArea Dock: top Dock: Fill x,y

Java: Layout Managers Left to right, Top to bottom c n s ew FlowLayoutGridLayout BorderLayout none, programmer sets x,y,w,h null One at a time CardLayout GridBagLayout JButton

Events

Typical command line program Non-interactive Linear execution program: main() { code; }

Interactive command line program User input commands Non-linear execution Unpredictable order Much idle time program: main() { decl data storage; initialization code; loop { get command; switch(command) { command1: code; command2: code; … }

Typical GUI program GUI program: main() { decl data storage; initialization code; create GUI; register callbacks; main event loop; } Callback1()//button1 press {code; } Callback2()//button2 press {code; } … User input commands Non-linear execution Unpredictable order Much idle time Event callback procs

GUI Events Window System event loop App1 OK Cancel App2 code: OKbtn_click() { do stuff; } CancelBtn_click() { do different stuff; } App2Form_click() { do other stuff; } mouse click input device App1 event loop App2 event loop which app? which control? App2 OK Cancel

C# WinApp C# WinApp: Class{ decl data storage; constructor(){ initialization code; create GUI controls; register callbacks; } main(){ Run(new ) } callback1(){ do stuff; } callback2(){ do stuff; } … “delegates” = callbacks Function pointers Java: Listeners

Delegates 1.Register with a control to receive events Give Control a function pointer to your callback function this.button1.Click += new EventHandler(this.button1_Click); 2.Receive events from control Control will call the function pointer private void button1_Click(object sender, EventArgs e){ Button1 Button1_click() callback click 2. button1_Click( ) 1. button1.Click += button1_click( )

GUI Topics Components* GUI layout* Events* Graphics Manipulation Animation Databases MVC