Self Study GUI Properties & Events

Slides:



Advertisements
Similar presentations
Copyright © 2012 Pearson Education, Inc. Chapter 11 MORE WINDOWS CONTROLS & STANDARD DIALOG BOXES.
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.
GUI-Labels, TextBoxes and Buttons Label- displays read-only text Common properties:  Font – font used by the text of label  Text – text to appear on.
Compunet Corporation Programming with Visual Studio.NET GUI Week 13 Tariq Aziz and Kevin Jones.
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
Events. Events Single Event Handlers Click Event Mouse Events Key Board Events Create and handle controls in runtime Outline.
CS0004: Introduction to Programming Events. Review  Event Procedure  A set of instructions to be executed when a certain event happens.  Many event-driven.
Chapter 3 Introduction to Event Handling and Windows Forms Applications.
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.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
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.
Dr Dat Tran - Week 4 Lecture Notes 1 MenuStrip Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences &
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
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,
CSC 298 Windows Forms.
Intro to MFC. Open VS and create new project 1)Open MS Visual Studio 2008 Professional (It must be the Professional Edition, the Express Edition will.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Assignment #1 Advanced Computer Programming.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
Session 08: Architecture Controllers or Managers Graphical User Interface (GUI) FEN AK - IT Softwarekonstruktion.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
1 Working with Menus and Dialog Boxes. 2 Objectives You will be able to Create and edit menus for Windows Forms applications. Write code to handle menu.
Dr Dat Tran - Week 4 Lecture Notes 1 ToolStrip Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences &
Copyright © 2014 Pearson Education, Inc. Chapter 2 Creating Applications with Visual Basic.
BIL528 – Bilgisayar Programlama II Introduction 1.
Sample Application Multi Layered Architecture (n-tier): –Graphical User Interface (GUI): Forms, components, controls The Visual Designer in Visual Studio.
COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling.
Introduction to Windows Programming
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
OBJECTIVES: To open an existing Project called HelloWorld. To learn how set properties using the property window and how to set them in the code. Chapter.
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.
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.
Chapter 3 - VB.NET by Schneider1 Chapter 3 – Fundamentals of Programming in VB.NET Part I VB.NET Controls VB.NET Events.
Forms and Controls Part 3 dbg --- Naming conventions, Button, Event handlers, Label.
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
Introduction to Windows Forms Application By N Hanumantha Rao MCA By N Hanumantha Rao MCA.
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
Simple Clicker App WPF App using C#. App Requirement Need a ‘counter’ display, which starts at 0 Need a ‘clicker’ button ! Pressing the clicker every.
CPSC 481 – Week #7 Sowmya Somanath
1 Printing a Document. 2 Objectives You will be able to print a real multipage document.
Forms and Controls Part 3 dbg --- Naming conventions, Button, Event handlers, Label.
Visual Basic. The Close Method The Close method is used to close a form. To close a form use the keyword Me to refer to the form. Me.Close()
Lecture Set 7 Procedures and Event Handlers Part B - The Structure of an Application Event Handlers.
Graphical User Interface Components Version 1.1. Obectives Students should understand how to use these basic Form components to create a Graphical User.
1 Windows Forms II Chapter RadioButton / GroupBox Controls Used to solicit a multiple choice input. Radio buttons work as a group. Selecting one.
Dr. Abraham Professor UTPA Graphical User Interface.
Windows form programming. namespace MyNamespace { public class MyForm : System.Windows.Forms.Form { public MyForm() { this.Text = "Hello Form"; }
Computing with C# and the .NET Framework
Object Oriented Programming
Chapter 8: Writing Graphical User Interfaces
GUI Programming using Windows Form
Reference: COS240 Syllabus
Windows Desktop Applications
Visual programming Chapter 3: GUI (Graphical User Interface) Part I
Visual Basic Properties, Methods and Events
Chapter#9: A Deeper Look In Controls
How to Add Images Using an 'openFile' Dialog
Programming Based on Events
Simple Windows Applications
Copyright © 2006 Thomas P. Skinner
Visual programming Chapter 2: Events and Event Handling
Control Structures Part C – Groups of Controls
Chapter 13: Handling Events
GUI Programming in Visual Studio .NET
Presentation transcript:

Self Study GUI Properties & Events CS1S467 GUI Programming Self Study GUI Properties & Events

Visual Studio Controls (Button, CheckBox, Label,…) Properties (colour, position, visible,…) Events (clicked, dragged, changed,…)

Changing Properties/Events Via Visual Studio GUI (simple to do) Controls (Button, CheckBox, Label,…) Properties (colour, position, visible,…) Events (clicked, dragged, changed,…) Programmatically (a bit more tricky)

PART 1: Properties

Changing Properties Programmatically Simple OiO Constructors OiO Properties 3 Groups of Properties Simple, direct (e.g. ProgressBar value > int, Button visible > boolean) Using Object-in-Object Constructors (fonts, points) Using Object-in-Object Properties (colour, text position)

Changing Properties Programmatically Simple OiO Constructors OiO Properties Copying a Boolean Property Setting directly private void visible_cBx _CheckedChanged(object sender, EventArgs e) { button1.Visible = visible_cBx.Checked; } button1.Visible = true; button1.Visible = false;

Changing Properties Programmatically Simple OiO Constructors OiO Properties Using Object-in-Object Constructors GUI Controls are made from many sub-objects (lines, areas, fonts, …) Constructors create new objects (note the keyword 'new') These new objects can then be used to replace existing objects (e.g. an old font by a new font)

Changing Properties Programmatically Simple OiO Constructors OiO Properties Using Object-in-Object Constructors (here: the 'Font' constructor) private void bold_cBx_CheckedChanged(object sender, EventArgs e) { if (bold_cBx.Checked) button1.Font = new Font(button1.Font.Name, button1.Font.Size+4, FontStyle.Bold); } else button1.Font = new Font(button1.Font.Name, button1.Font.Size-4 ,FontStyle.Regular);

Changing Properties Programmatically Simple OiO Constructors OiO Properties Using Object-in-Object Constructors (here: the 'Point' constructor) private void xPos_UpDown_ValueChanged(object sender, EventArgs e) { button1.Location = new Point( (int) xPos_UpDown.Value, 77); }

Changing Properties Programmatically Simple OiO Constructors OiO Properties Using Object-in-Object Properties (here: properties of the 'Color' class) private void backColour_comboBx_SelectedIndexChanged(object sender, EventArgs e) { if (backColour_comboBx.SelectedIndex == 0) button1.BackColor = Color.Red; if (backColour_comboBx.SelectedIndex == 1) button1.BackColor = Color.Green; if (backColour_comboBx.SelectedIndex == 2) button1.BackColor = Color.Blue;   }

Changing Properties Programmatically Simple OiO Constructors OiO Properties Copying Object-in-Object Properties private void textColourBtn_Click(object sender, EventArgs e) { // Show the colour dialog. DialogResult result = colorDialog1.ShowDialog(); // See if user pressed ok or cancel. if (result == DialogResult.OK) // Set button text colour to the selected color. button1.ForeColor = colorDialog1.Color; } Although dragged onto Form … …….… it will appear here

Changing Properties Programmatically Simple OiO Constructors OiO Properties Using Object-in-Object Properties (here: properties of the 'ContentAlignment' class) private void radioButton1_CheckedChanged(object sender, EventArgs e) { button1.TextAlign = ContentAlignment.BottomLeft; }   private void radioButton2_CheckedChanged(object sender, EventArgs e) button1.TextAlign = ContentAlignment.MiddleCenter; private void radioButton3_CheckedChanged(object sender, EventArgs e) button1.TextAlign = ContentAlignment.TopRight;

PART 2: Events

Control Events When double-clicking on a Control the default event handler method stub will be created: private void button1_Click(object sender, EventArgs e) {   } once an event handler has been created you can't change the control name any more without an unwanted side effect: control name changes event handler name doesn't private void button1_Click(..

Control Events Therefore Give EVERY control a MEANINGFUL name immediately after creation: private void SortButton_Click(object sender, EventArgs e) {   }

Control Events When double-clicking on a Control usually the 'Click' event handler gets created: but not always: private void button1_Click(object sender, EventArgs e) {   } private void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejected… e) {   }

Control Events To set other Event Handlers double-click on the correct event private void maskedTextBox1_ModifiedChanged(object sender, EventArgs e) {   }

Drag Event Handling Controls Events Form1 label1 label2 MouseDown MouseMove MouseUp

Drag Event Handling private Point MouseDownLocation; // stores starting X and Y position   private void label1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) MouseDownLocation = e.Location; Cursor.Current = Cursors.Hand; } private void label1_MouseMove(object sender, MouseEventArgs e) label1.Left = e.X + label1.Left - MouseDownLocation.X; label1.Top = e.Y + label1.Top - MouseDownLocation.Y; label2.Text = "Dragging"; private void label1_MouseUp(object sender, MouseEventArgs e) label2.Text = "Dropped";