4
10/21/2019 EEE-425 Programming Languages (2013) 1 2 3 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. 4 Windows Desktop Apps Based on .NET framework Windows Forms programming with C# Three key pieces: Forms Controls Events 5 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 Controls are objects that can display and respond to user interaction. 6

Introduction to Programming · 10/6/2019  · Windows Desktop Apps Based on .NET framework Windows Forms programming with C# Three key pieces: Forms Controls Events 5 Controls are

  • Upload
    others

  • View
    13

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Programming · 10/6/2019  · Windows Desktop Apps Based on .NET framework Windows Forms programming with C# Three key pieces: Forms Controls Events 5 Controls are

10/21/2019

EEE-425 Programming Languages (2013) 1

2

3

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.

4

Windows Desktop Apps◦ Based on .NET framework

◦ Windows Forms programming with C#

Three key pieces:◦ Forms

◦ Controls

◦ Events

5

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

Controls are objects that can display and respond to user interaction.

6

Page 2: Introduction to Programming · 10/6/2019  · Windows Desktop Apps Based on .NET framework Windows Forms programming with C# Three key pieces: Forms Controls Events 5 Controls are

10/21/2019

EEE-425 Programming Languages (2013) 2

7

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

8

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

9

Windows-based form

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

10

11

Windows

Forms

Application

template Browse to

location

to store

your work

Select

File New

Project

Name

Visual Studio New Windows application

Properties

Window

Design ViewToolbox Initial design screen

12

Page 3: Introduction to Programming · 10/6/2019  · Windows Desktop Apps Based on .NET framework Windows Forms programming with C# Three key pieces: Forms Controls Events 5 Controls are

10/21/2019

EEE-425 Programming Languages (2013) 3

Dockable windows13 14

A Windows application form can act as a containerfor additional objects.

Objects that can be contained by forms (and are coded by existing classes in the Foundation Class Library) are called controls.

15

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

16

17

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 Description

Activate Activates the window and gives it focus

Close Closes the form

Show Makes the form visible

BringToFront Moves to top of stacking order

Hide Makes the form invisible

Focus Gives the form focus

18

Page 4: Introduction to Programming · 10/6/2019  · Windows Desktop Apps Based on .NET framework Windows Forms programming with C# Three key pieces: Forms Controls Events 5 Controls are

10/21/2019

EEE-425 Programming Languages (2013) 4

19

PropertiesProperty value

Properties window

20

21

Property Description

Location Point of to left corner

Size Size of form in pixels

Text Text displayed or caption

AutoScaleDimensions DPI resolution of display it was built for. Will be scaled to

look correct on other displays.

BackColor Background color

ForeColor Foreground or drawing color

ClientSize Size of drawing area without borders or scrollbars

Controls A collection of controls owned by the form

WindowState Whether maximized, minimized or normal

DefaultSize Size when initially created

MinimumSize Minimum size window can be resized to

MaximumSize Maximum size window can be resized to

22