EEE-425 Programming Languages (2013) 1

Similar documents
EEE-425 Programming Languages (2013) 1

Programming. C# Programming: From Problem Analysis to Program Design 2nd Edition. David McDonald, Ph.D. Director of Emerging Technologies

CST242 Windows Forms with C# Page 1

Philadelphia University Faculty of Information Technology. Visual Programming

Chapter 12: Using Controls

Chapter 2. Ans. C (p. 55) 2. Which is not a control you can find in the Toolbox? A. Label B. PictureBox C. Properties Window D.

Programming in C# Project 1:

Dive Into Visual C# 2008 Express

Chapter 12: Using Controls

Dive Into Visual C# 2010 Express

Introductionto the Visual Basic Express 2008 IDE

Controls. By the end of this chapter, student will be able to:

Tutorial 3 - Welcome Application

Overview Describe the structure of a Windows Forms application Introduce deployment over networks

1 Dept: CE.NET Programming ( ) Prof. Akash N. Siddhpura. Working with Form: properties, methods and events

Interface Design in C#

CHAPTER 3. Writing Windows C# Programs. Objects in C#

Unit-1. Components of.net Framework. 1. Introduction to.net Framework

Using Visual Basic Studio 2008

1. Windows Forms 2. Event-Handling Model 3. Basic Event Handling 4. Control Properties and Layout 5. Labels, TextBoxes and Buttons 6.

Chapter 2. Creating Applications with Visual Basic Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of

DateTimePicker Control

Unit 3 Additional controls and Menus of Windows

Full file at Programming in Visual Basic 2010

Philadelphia University Faculty of Information Technology. Visual Programming. Using C# -Work Sheets-

Visual Studio.NET enables quick, drag-and-drop construction of form-based applications

Create your own Meme Maker in C#

#using <System.dll> #using <System.Windows.Forms.dll> #using <System.Drawing.dll>

Unit 3. Lesson Designing User Interface-2. TreeView Control. TreeView Contol

INFORMATICS LABORATORY WORK #4

SPARK. User Manual Ver ITLAQ Technologies

Lecture 1 Introduction Phil Smith

Skill Area 336 Explain Essential Programming Concept. Programming Language 2 (PL2)

Full file at

Visual C# Program: Simple Game 3

Text box. Command button. 1. Click the tool for the control you choose to draw in this case, the text box.

LESSON A. The Splash Screen Application

Menus and Printing. Menus. A focal point of most Windows applications

Lesson 04. Control Structures I : Decision Making. MIT 31043, VISUAL PROGRAMMING By: S. Sabraz Nawaz

Creating Web Applications Using ASP.NET 2.0

Microsoft Visual Basic 2005: Reloaded

1. What is the definition of a problem? 2. How to solve problems? 3. What is meant by Algorithm? 4. What is a Program testing? 5. What is Flowchart?

Information Systems Engineering. Presenting data in web pages Using ASP.NET

The first program we write will display a picture on a Windows screen, with buttons to make the picture appear and disappear.

LESSON B. The Toolbox Window

In this exercise you will gain hands-on experience using STK X to embed STK functionality in a container application created with C#.

Introduction to the Visual Studio.NET Integrated Development Environment IDE. CSC 211 Intermediate Programming

Forms/Distribution Acrobat X Professional. Using the Forms Wizard

Events. Event Handler Arguments 12/12/2017. EEE-425 Programming Languages (2016) 1

ListBox. Class ListBoxTest. Allows users to add and remove items from ListBox Uses event handlers to add to, remove from, and clear list

2 USING VB.NET TO CREATE A FIRST SOLUTION

Chapter 2 Visual Basic Interface

Introduction to the Visual Basic Express 2005IDE

Visual Basic.NET. 1. Which language is not a true object-oriented programming language?

Chapter 6 Dialogs. Creating a Dialog Style Form

Cropping an Image for the Web

INFRAGISTICS WPF 15.2 Service Release Notes September 2016

Creating Interactive PDF Forms

C# Continued. Learning Objectives:

CIS 3260 Intro. to Programming with C#

EPSON RC+ 7.0 Option. GUI Builder 7.0 EM145A2719F. Rev. 2

Layout and display. STILOG IST, all rights reserved

StarTeam Layout Designer Help

OCTAVO An Object Oriented GUI Framework

You can call the project anything you like I will be calling this one project slide show.

Welcome Application. Introducing the Visual Studio.NET IDE. Objectives. Outline

Ingegneria del Software T. Interfaccia utente

10Tec igrid for.net 6.0 What's New in the Release

Creating a nice GUI. OpenGL and Windows. Note: VS 2003 shown. Create a new Project

C# Programming: From Problem Analysis to Program Design. Fourth Edition

Forms iq Designer Training

Your First Windows Form

ViewONE User Manual. Genazim. The Friedberg Geniza Project. Daeja Image Systems. All Rights Reserved.

OhioState::OpenGLPanel. OpenGL and Windows. Public methods. OpenGLPanel : Forms::Control

VB.NET. Q.1 Explain.Net Framework Architecture. OR Components of.net Framework

Enterprise Architect. User Guide Series. Wireframe Models. Author: Sparx Systems. Date: 30/06/2017. Version: 1.0 CREATED WITH

To start we will be using visual studio Start a new C# windows form application project and name it motivational quotes viewer

C# 2008 and.net Programming for Electronic Engineers - Elektor - ISBN

Additional Controls & Objects

Code Finix Label Designer V 1.0 User Guide

Center for Faculty Development and Support Making Documents Accessible

used for US Census; Holes were made to represent information to be tabulated were punched in cards; Successful

Module 8: Building a Windows Forms User Interface

Jumping In with Both Feet: A Visual C# 2005 Programming Tour

Version 2 Users Manual

COPYRIGHTED MATERIAL. Visual Basic: The Language. Part 1

Program and Graphical User Interface Design

Chapter 2 Exploration of a Visual Basic.Net Application

Guide to WB Annotations

CST272 Getting Started Page 1

The Photo Gallery. Adding a Photo Gallery Page. Adding a Photo Gallery App

Keeping Track, Menus. CSC 330 Object-Oriented Programming 1

GUI Design and Event- Driven Programming

Understanding Events in C#

Module 9: Validating User Input

Visual C# Program: Resistor Sizing Calculator

Tutorial 2 - Welcome Application Introducing, the Visual Studio.NET IDE

In this lecture we will briefly examine a few new controls, introduce the concept of scope, random numbers, and drawing simple graphics.

Laboratorio di Ingegneria del Software

Visual BASIC Creating an Application. Choose File New Project from the menu

Transcription:

2 System.Drawing Namespace System.Windows.Forms Namespace Creating forms applications by hand Creating forms applications using Visual Studio designer Windows applications also look different from console applications User Interface: front end of a program Visual image you see when you run a program Algorithmic functionality stays behind GUI Often users of programs actually identify the interface of the program itself, when in reality, the interface is just one facet of the program. Algorithmic complexity is hidden behind GUI. 3 4 Graphical user interface (GUI) includes: Menus, labels, text boxes, list boxes, Other controls (pictures, buttons, etc.) Text in many different colors and sizes Controls are objects that can display and respond to user interaction. Controls are placed in a container, called form, which is an object as well. It is instance of a class derived from predefined class Form Windows Desktop Apps Based on.net framework Windows Forms programming with C# Three key pieces: Forms Controls Events 5 6 EEE-425 Programming Languages (2013) 1

Reference and import System.Windows.Forms namespace Class heading definition Includes not only the class name, but a colon followed by another class name Derived class (first class) Colon ( : ) delimiter, separator Base class (second class) public class Form1 : Form Derived classes inherit from base class Text A property for setting/getting title bar caption Can be used in constructor Windows forms/controls offer many properties including Text, Color, Font, and Location Execution begins in Main( ) method Main( ) is located in Program.cs file for the application Call to Run( ) method places application in process loop 7 8 Output generated from Windows0 application Primitive approach Manually create Win based application in C# using a text editor like Notepad, or Textpad etc Professional approach MS Visual Studio Select File Menu: New >> Project Select Visual C#, Windows and Windows Forms Application from Visual Studio Installed Templates pan Windows-based form 9 10 Select File New Project Name Windows Forms Application template Browse to location to store your work Properties Window Visual Studio New Windows application Toolbox Initial design screen Design View 11 12 EEE-425 Programming Languages (2013) 2

A Windows application form can act as a container for additional objects. Objects that can be contained by forms (and are coded by existing classes in the Foundation Class Library) are called controls. Dockable windows 13 14 This is the top-level window class This class contains all other controls Normally, your top-level form inherits from the Form class Although the class has numerous methods, most of the time you interact with it via properties and delegates Task: The application Find appropriate property and type a new value Change the following Form properties: Text BackColor Size FormBorderStyle 15 16 This namespace contains all of the controls used on the average Windows interface A control is a higher-level object composed of A window in which the control is drawn Visual parts of the control which are drawn in the window A set of delegates which are triggered when various events occur Method Activate Close Show BringToFront Hide Focus Description Activates the window and gives it focus Closes the form Makes the form visible Moves to top of stacking order Makes the form invisible Gives the form focus 17 18 EEE-425 Programming Languages (2013) 3

Properties Property value Properties window 19 20 Property Location Size Text AutoScaleDimensions BackColor ForeColor ClientSize Controls WindowState DefaultSize MinimumSize MaximumSize Description Point of to left corner Size of form in pixels Text displayed or caption DPI resolution of display it was built for. Will be scaled to look correct on other displays. Background color Foreground or drawing color Size of drawing area without borders or scrollbars A collection of controls owned by the form Whether maximized, minimized or normal Size when initially created Minimum size window can be resized to Maximum size window can be resized to Add code to respond to events, like button clicks From the Properties window, select the lightning bolt (Events) Double-click on the event name to generate code Registers the event as being of interest Adds a heading for event-handler method 21 22 Forms provide support for a large number of events You add one or more delegates to these events When the event happens, the delegates are invoked The delegates must have the signature of an event handler void EventHandler(object sender, EventArgs e) Event Load Closing Closed Shown ResizeBegin ResizeEnd Description Just before form is loaded the first time Just before the form is closed When the form is actually closed Occurs when a form is first displayed Resize operation has begun Resize operation has ended 23 24 EEE-425 Programming Languages (2013) 4

Events button selected Expand Form1.cs node to reveal the Form1.Designer.cs file Form1 events 25 Solution Explorer window 26 Code automatically added to register event this.closing += new System.ComponentModel.CancelEventHandler (this.form1_closing); Code automatically added for method heading private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { } You add statement to event-handler method body MessageBox.Show("Hope you are having fun!"); IDE separates the source code into three separate files Form1.cs: normally this is the only one you edit Form1.Designer.cs: holds the auto generated code Program.cs: contains the Main( ) method, where execution always begins Form1.cs and Form1.Designer.cs both include partial class definitions for the Form1 class 27 28 // // Printing multiple lines in a dialog Box. using System; using System.Windows.Forms; class Welcome4 { static void Main( string[] args ) { The System.Windows.Forms namespace allows the programmer to use the MessageBox class. This will display the contents in a message box as opposed to in the console window. MessageBox.Show( Welcome\nto\nC#\nprogramming!" ); } } 29 30 EEE-425 Programming Languages (2013) 5

Controls are all classes Button, Label, TextBox, ComboBox, MainMenu, ListBox, CheckBox, PictureBox, MenuStrip, RadioButton, and MonthCalendar Each comes with its own predefined properties and methods Each fires events Each is derived from the System.Windows.Forms.Control class 31 32 Dots indicate other classes are derived from the class Control class hierarchy 33 Windows Forms controls 34 Two procedures to place controls from Toolbox, double-click on control or drag and drop Move, resize, and delete controls Format controls Align controls Make same size Horizontal and vertical spacing 35 36 EEE-425 Programming Languages (2013) 6

Provide descriptive text or labels for other controls Instantiate object Label labelname = new Label( ); Add control to Form this.controls.add(labelname); Set property values (some from Control class) Text; TextAlign; Font; Location 37 38 Add Label objects to Form object Use options on FORMAT menu Formatting Label objects Properties set for the Form container 39 40 Add Label objects, then set their properties using the Properties window (View Properties window) Used to enter data or display text during run time Used for both input and output Instantiate object TextBox textboxname = new TextBox( ); Add control to Form this.controls.add(textboxname); Interesting properties MultiLine, ScrollBars, MaxLength, PasswordChar, CharacterCasing 41 42 EEE-425 Programming Languages (2013) 7

This is a single line or multi-line text editor Multiline get/set Boolean to make multiline AcceptsReturn in a multiline box, if true then pressing Return will create a new line. If false then the button referenced by the AcceptButton property of the form, will be clicked. PasswordChar if this is set to a char, then the box becomes a password box ReadOnly if true, the control is grayed out and will not accept user input ScrollBars determines which scrollbars will be used: ScrollBars.None, Vertical, Horizontal, Both TextAlign get/set HorizontalAlignment.Left, Center, or Right TextChanged event raised when the text is changed 43 44 Enables user to click button to perform task Add TextBox objects, then set their property values If button has event-handler method and is registered as an event to which your program is planning to respond, event-handler method is called automatically when button clicked Button object s properties, methods, and events Inherits from Control Text, Enabled, Focused, TabIndex 45 46 Add Button objects, then set their property values Events 47 48 EEE-425 Programming Languages (2013) 8

When you double-click on event, an eventhandler method is created: private void btncompute_click(object sender, System.EventArgs e) { } AND registers click event: this.btncompute.click += new System.EventHandler (this.btncompute_click); private void btncompute_click(object sender, System.EventArgs e) { string invalue; double purchaseamt, percent, ans; invalue = txtpurchase.text; purchaseamt = Int32.Parse(inValue); invalue = label5.text; //invalue previously declared as string invalue = invalue.remove(invalue.length-1, 1); percent = double.parse(invalue) / 100; percent = (double.parse(label5.text.remove(label5.text.length-1,1))) / 100; ans = (purchaseamt * percent) + purchaseamt; txttotaldue.text = String.Format("{0:C}",ans).ToString(); } 49 50 Using one of the 4 described techniques, we will add a Button to a new form. We will program a handler function that will respond to the Click event, generated when the mouse is clicked while its pointer is positioned over the button. This event is termed a Button.Click event. Tax calculator output 51 52 CheckBox GroupBox RadioButton Panel TextBox ListBox Labeled boxes which can be checked or unchecked Checked get/set Boolean to determine if box is checked CheckedChanged delegate called when the box is checked or unchecked 53 54 EEE-425 Programming Languages (2013) 9

Displays a border around a group of controls Can have optional label controlled by Text property Controls can be added by Placing them within the group box in the designer Adding to the Controls list programmatically Radio buttons are similar to checkboxes, but Appear slightly different Allow buttons to be grouped so that only one can be checked at a time A group is formed when the radio buttons are in the same container usually a group box or panel 55 56 Checked get/set Boolean indicating if the button is checked CheckedChanged delegate invoked when the button is checked or unchecked The ListBox presents a list of items which can be selected A scrollbar is displayed if needed MultiColumn displays list as multiple columns SelectedIndex index of selected item SelectedIndices collection of selected indices SelectedItem the selected item 57 58 SelectedItems collection of selected items SelectionMode how items can be selected None no selection One single selection MultiSimple each click selects additional item MultiExtended uses shift and control keys Sorted if true the items will be sorted alphabetically Items a collection of items in the list box ClearSelected method to clear selection GetSelected returns true if the parameter passed is selected SelectedIndexChanged event when selection changes 59 60 EEE-425 Programming Languages (2013) 10

Any object can be placed into a ListBox The display is generated by ToString() for(int i = 0; i < 50; i++) { listbox1.items.add( "Item " + i.tostring()); } Example 61 62 A combo box is like a list but lets you displays a selected value. The list pulls down when a selection is being made. Options allow the selected text to be editable or to require it to be selected from the drop-down list DropDownStyle Simple text is editable & list always visible DropDown default indicating text is editable & user must click to see list DropDownList value is not editable & user must click to see list Items the collection of items in the list 63 64 MaxDropDownItems max number of items in pulldown before scrollbar used SelectedIndex index of selection SelectedItem selected item Sorted whether entries are sorted SelectedIndexChanged event raised when selection changes 65 66 EEE-425 Programming Languages (2013) 11

This allows the selection of an integer from a limited range Also called a spinner Minimum smallest selectable value Maximum largest selectable value Increment size of increment per click Value the selected value ValueChanged event raised when the value changes A DomainUpDown control allows users to provide a spin (up/down) interface to move through pre-defined strings using up and down arrows. In this tutorial, we will see how to create a DomainUpDown control and use it in a Windows Forms application. 67 68 A panel is like a group box but does not have a text label It contains a group of controls just like group box BorderStyle get/set border style as BorderStyle.Fixed3D BorderStyle.FixedSingle BorderStyle.None The file dialog allows you to navigate through directories and load or save files This is an abstract class and you use OpenFileDialog SaveFileDialog You should create the dialog once and reuse it so that it will remember the last directory the user had navigated to 69 70 InitialDirectory string representing the directory to start in Filter a string indicating the different types of files to be displayed A set of pairs of display name and pattern separated by vertical bars Windows Bitmap *.bmp JPEG *.jpg GIF *.gif FilterIndex the filter to use as an origin 1 index FileName the name of the file selected ShowDialog a method to show the dialog and block until cancel or OK is clicked if (opendialog.showdialog() == DialogResult.OK) { Image img = Image.FromFile(openDialog.FileName); picturebox1.image = img; } 71 72 EEE-425 Programming Languages (2013) 12

An abstract class that can store an image Several concrete classes are used for image types such as BMP, GIF, or JPG FromFile(string fname) loads any supported image format from a file FromStream(stream) loads an image from a stream Height image height Width image width This displays an image Image assigned an Image object to display SizeMode determines what to do if the image does not fit into the window Normal StretchImage AutoSize CenterImage Zoom 73 74 These are the small pop-up boxes which explain the purpose of a control To use Create a new tooltip in the designer Drop the tooltip onto the form The tooltip will appear on a tray below the form After the tooltip appears in the tray, a new tooltip property appears for every component This can be assigned different text for each component That text will be displayed when the mouse hovers over that component 75 76 A control which displays a calendar for the selection of a range of dates MinDate the first selectable date MaxDate the last selectable date SelectionStart DateTime of start of selection SelectionEnd DateTime of end of selection DateChanged event raised when date is changed Similar to a month calendar but Calendar pulls down and selection displayed More configurable Selects a single value, not a range Properties/methods Format Long, Short, Time, Custom Value DateTime value selected ValueChanged event which fires when date or time changes 77 78 EEE-425 Programming Languages (2013) 13

homepage.divms.uiowa.edu Questions? Prof. Roger Crawfis http://www.cse.ohiostate.edu/~crawfis/cse459_csharp/index.html Programming C#, 4th Edition - Jesse Liberty Chapt. 5 Pls listen the podcast about the chapter 5 (Roger Crawfis) These slides are changed and modified 80 Write a game program that Create a class Takes a number from user, Compares this number with generated random value between two given positive numbers User tries maximum3 times then if user knows says «You Win» OR You lost Write a program as a calculator with (*, /, +, -, % ) operators by using methods Check the values that are not 0(zero) or none numeric Write the result on screen with variables and operator 81 EEE-425 Programming Languages (2013) 14