14
12/12/2017 EEE-425 Programming Languages (2013) 1 MenuStrip Menus TreeView TabControl 2 Main menu is the control that resides upper section of the form. It provides easy access for frequently used operations. 3 Menus provide groups of related commands for Windows applications separator bars Checked menu item 4 N ew (Ctrl N) O pen (Ctrl O) C lose Save A s S ave (Ctrl S) P rint (Ctrl P) Ex it U ndo (Ctrl Z) Cut (Ctrl X) C opy (Ctrl C) P aste (Ctrl V) F ind (Ctrl F) Re place (Ctrl H) F ile Menu E dit Menu 5 Pulldown menus «MenuStrip» a way to select commands and options Normally these are in a MenuStrip across the top of the application Begin by placing a MenuStrip across the application It displays boxes into which menu items and cascading menus can be typed 6

Introduction to Programming · 2017-12-09 · 12/12/2017 EEE-425 Programming Languages (2013) 3 To create an access shortcut (or keyboard shortcut), 13 To add other shortcut keys

  • Upload
    others

  • View
    14

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Programming · 2017-12-09 · 12/12/2017 EEE-425 Programming Languages (2013) 3 To create an access shortcut (or keyboard shortcut), 13 To add other shortcut keys

12/12/2017

EEE-425 Programming Languages (2013) 1

MenuStrip

Menus

TreeView

TabControl

2

Main menu is the control that resides upper section of the form.

It provides easy access for frequently used operations.

3

Menus provide groups of related commands for Windows applications

separator bars Checked menu

item4

New (Ctrl N)

Open (Ctrl O)

Close

Save As

Save (Ctrl S)

Print (Ctrl P)

Exit

Undo (Ctrl Z)

Cut (Ctrl X)

Copy (Ctrl C)

Paste (Ctrl V)

Find (Ctrl F)

Replace (Ctrl H)

File Menu Edit Menu

5

Pulldown menus «MenuStrip» a way to select commands and options

Normally these are in a MenuStrip across the top of the application

Begin by placing a MenuStrip across the application

It displays boxes into which menu items and cascading menus can be typed

6

Page 2: Introduction to Programming · 2017-12-09 · 12/12/2017 EEE-425 Programming Languages (2013) 3 To create an access shortcut (or keyboard shortcut), 13 To add other shortcut keys

12/12/2017

EEE-425 Programming Languages (2013) 2

The MenuStrip control is essentially a ToolStrip control optimized for the display of ToolStripMenu items.

The MenuStrip control derives from ToolStrip and can host all the tool strip items described in the previous lesson. Its primary function, however, is to host ToolStripMenu items.

ToolStripMenuItem controls are the controls that provide the visual representation for items on a menu. They can appear as text, an image, or both and can execute code found in their ToolStripMenuItem

7

MainStrip is added to the form by dragging and dropping from.

8

The type here text allows new items to be added

When you click on type here a pull down appears letting you select◦ Menu item◦ ComboBox◦ Separator◦ TextBox

9

PROPERTY DESCRIPTION

AllowMerge Indicates whether this menu strip can be merged with another tool strip.

LayoutStyle Indicates how the controls on the tool strip are laid out

ShowItemToolTips Indicates whether tool tips for individual tool strip items are displayed.

TextDirection Indicates the direction of the text in controls hosted in the tool strip.

10

PROPERTY DESCRIPTION

AutoSize Determines whether the menu item is automatically sizedto fit the text.

Checked Determines whether the menu item appears as selected.

CheckOnClick Determines whether the menu item is automatically selected when clicked

CheckState Returns the CheckState value of the menu item. CheckState can be Checked, Unchecked, or Indeterminate.

DisplayStyle Determines how the tool strip menu item is displayed.

DoubleClickEnabled

Determines whether the DoubleClick event fires.

DropDownItems Contains a collection of tool strip items (usually, but notnecessarily, tool strip menu items) that appear in the

11

To create an access shortcut (or keyboard shortcut),

12

Page 3: Introduction to Programming · 2017-12-09 · 12/12/2017 EEE-425 Programming Languages (2013) 3 To create an access shortcut (or keyboard shortcut), 13 To add other shortcut keys

12/12/2017

EEE-425 Programming Languages (2013) 3

To create an access shortcut (or keyboard shortcut),

13

To add other shortcut keys (e.g., <Ctrl>-F9)

14

You can add a separator to any submenu at design time by choosing Separator from the drop-down box in the menu item design interface.

Using “-”

15

Click Generated when an item is clicked or a

shortcut key is used. This is the default event

when the menu is double clicked in the

designer

DropDownOpened Occurs when Dropdown hasoOpened

Slide 16

All controls that can display a context menu expose a ContextMenuStrip property that represents the context menu associated with that control

A context menu is invoked when the user right-clicks a control.

You can set this property at design time in the Properties window.

17

with ContextMenuStrip into Form

18

Page 4: Introduction to Programming · 2017-12-09 · 12/12/2017 EEE-425 Programming Languages (2013) 3 To create an access shortcut (or keyboard shortcut), 13 To add other shortcut keys

12/12/2017

EEE-425 Programming Languages (2013) 4

ContextMenuStrip menu◦ menu item “Remove”

menu item

19

ContextMenu with ListBox◦ ListBox

ContextMenuStrip = ContextMenuStrip1

context

menu

20

Click menu item

21

Demo

Context Menu

with user

ListBox

22

Alignment Property

AutoSize Property

BorderStyle Property

Icon Property

Style Property

ToolTipText Property

23

Buttons Property

ButtonClick Event

ImageList Property

SendToBack() Method

ShowToolTips Property

24

Page 5: Introduction to Programming · 2017-12-09 · 12/12/2017 EEE-425 Programming Languages (2013) 3 To create an access shortcut (or keyboard shortcut), 13 To add other shortcut keys

12/12/2017

EEE-425 Programming Languages (2013) 5

Checked – if true displays check mark CheckOnClick – check state changes when

clicked CheckState – one of ◦ CheckState.Checked◦ CheckState.Unchecked◦ CheckState.Indeterminate

ShortcutKeys – a member of the Shortcut enumeration indicating the shortcut key

25

Click – event which is raised when the menu item is clicked

Menu items are similar to buttons and are handled in the same way

* see MenuDemo

26

27

You can use a ComboBox as a menu item Use the designer to add a set of Items to

the combo box You can then select a value The click event is raised only when you click

on the selected value, not when you change the selection

If you have nothing selected, the selected item will be null

Presents a hierarchical tree view of the data

Nodes can be ◦ Selected◦ Expanded and collapsed

Text of nodes can be edited Nodes can be added or deleted

programmatically

28

All nodes in the tree are instances of TreeNode

Constructors◦ TreeNode(string displayText)

Properties◦ Nodes – get TreeNodeCollection of all children of

this node

29

◦ Text – the displayed text◦ Checked – true if the node is checked◦ FullPath – the labels of all nodes from the root to

this node separated by “\\”◦ NextNode – returns next sibling◦ PrevNode – returns previous sibling

Methods◦ Collapse – collapses the node

30

Page 6: Introduction to Programming · 2017-12-09 · 12/12/2017 EEE-425 Programming Languages (2013) 3 To create an access shortcut (or keyboard shortcut), 13 To add other shortcut keys

12/12/2017

EEE-425 Programming Languages (2013) 6

◦ Expand – expands the node

◦ ExpandAll – expands all children of this node

◦ GetNodeCount – returns the number of child nodes

31

This is the actual control Properties◦ Nodes – get TreeNodeCollection of all children of

this node◦ CheckBoxes – if true, displays checkboxes beside

tree nodes◦ SelectedNode – the selected node◦ LabelEdit – if true, node text can be edited

32

Events◦ AfterSelect – after a node is selected

◦ AfterExpanded – after a node is expanded

◦ AfterCollapsed – after a node is collapsed

◦ AfterEdited – after a node is edited

33 34

: http://eembdersler.wordpress.com◦ Choose the EEE-425Programming Languages (Fall)

Textbook reading schedule

Pdf lecture notes

Updated class syllabus

Midterm and final exams grades

Answers of Midterm and Final Exam

35

Texts and Other Course Materials◦ Programming C#, 4th Edition - Jesse Liberty (You may down this

version the book from Internet - It is your responsibility to download it or buy the book from http://www.amazon.com/Programming-C-Jesse-Liberty/dp/B00006AVR5)

◦ Beginning.C.Sharp.3.0.An.Introduction◦ Internet Materials

Grading :◦ Assignments 20%◦ Midterm 20%

◦ Final : 20%◦ Project : 40% ( Presentation, code and short report)◦ Bonus : 10% ( If you follow all course –no exception, you will get◦ extra 10% of your grade)

Total 110%

36

Page 7: Introduction to Programming · 2017-12-09 · 12/12/2017 EEE-425 Programming Languages (2013) 3 To create an access shortcut (or keyboard shortcut), 13 To add other shortcut keys

12/12/2017

EEE-425 Programming Languages (2013) 7

This course contains material that

demands intense mental work and an

unusual amount of time commitment.

Student dedication is advised.

37 38

Instructor’s expectations:◦ Homework. Read chapters prior to class from the textbook◦ Expect 2-4 hours outside classroom activities; Reading◦ Participate. Ask questions. Contribute. Actively participate

in the exercises. Consider the classroom to be a mental gymnasium where it’s ok to run, fall, and get up again

◦ Take notes. Why let any idea get away? Taking notes will help you concentrate and organize your

thoughts Notes allow you to take a refresher any time in the future.

◦ Enjoy yourself. Start relaxed and you’ll leave refreshed, inspired, and recharged Forget about what’s happening at home or at work This is your time. Get all you can out of this course and have a

good time◦ Excessive Late assignments: 10% penalty from the grade

assigned for each day ( maximum 2 days)

39

Refer to the syllabus for details regarding◦ Academic dishonesty

NOCHEATHING is allowed for all materials.

Given and taken person will be punished with less notes( 0)

◦ Attendance : 70% of Lectures

◦ Special attention for the class

Covers (most of) the C# language and some of the most useful .NET API’s.

Should not be your first programming class.◦ Assume you know C++ and basic object-oriented

programming.

Requires (lots of) practice / reading.◦ C# and .NET cannot be learned thoroughly in this

brief course.

40

Require◦ do all assignments

Assignments are ◦ You will not be given a detailed grade

◦ Show me that you understand the concepts, and can write C# code

Do a project that related with technical EEE by using C# ( It is important to apply your knowledge to oneproblem-Database projects are NOT accepted)

Note : Pls dont just directly copy the code from Internet or somewhere as your project- If we know that is copiedsomewhere we will penalty its grade as 0 (zero)

41

Missing class sessions Failure to do homework Poor sleeping, drinking, eating, and physical exercise habits

Failure to follow textbook Failure to prioritize and budget time for study, work, and social activities

Copying other people’s homework, quiz, or exam (Read “AcademicIntegrity”)

42

Page 8: Introduction to Programming · 2017-12-09 · 12/12/2017 EEE-425 Programming Languages (2013) 3 To create an access shortcut (or keyboard shortcut), 13 To add other shortcut keys

12/12/2017

EEE-425 Programming Languages (2013) 8

To do well in this class, you have to

work really hard.

You need to be prepared to dedicate a

significant amount of time and

mental effort on this class.

43

can determine your grade in this class

can make the choice to be successful

can choose how you use your time

can do the work of learning

44

1. What is Computer Programming?

2. Your First C# Program

3. What is .NET Framework?

4. What is Visual Studio?

5. What is MSDN Library?

45 46

Computer programming: creating a sequence of instructions to enable the computer to do something

47

Programmers do not use machine language when creating computer programs. Instead, programmers tend to use high-level programming languagesEach high-level language has its own syntax and limited set of vocabulary that is translated into machine code by a compiler

Define a task/problem

Plan your solution◦ Find suitable algorithm to solve it

◦ Find suitable data structures to use

Write code

Fix program error (bugs)

Make your customer happy

48

= Specification

= Design

= Implementation

= Testing & Debugging

= Deployment

Page 9: Introduction to Programming · 2017-12-09 · 12/12/2017 EEE-425 Programming Languages (2013) 3 To create an access shortcut (or keyboard shortcut), 13 To add other shortcut keys

12/12/2017

EEE-425 Programming Languages (2013) 9

Wikipedia.org definition for C#.◦ Object-oriented.

◦ Primarily imperative or procedural.

LINQ (Language Integrated Query) adds some functional programming language capabilities.

◦ Structured (as opposed to monolithic).

◦ Strongly typed.

◦ ISO(International Organization for Standardization)and ECMA(European Computer ManufacturersAssociation) standardized.

49 50

Sample C# Console Application program:

using System;

namespace ConsoleApplication;class HelloCSharp{

static void Main(string[] args){

Console.WriteLine("Hello, C#");}

}

51 52

using System;

class HelloCSharp{

static void Main(){

Console.WriteLine("Hello, C#");}

}

Include the standard

namespace "System"

Define a class called

"HelloCSharp"

Define the Main() method – the

program entry point

Print a text on the console by

calling the method "WriteLine" of the class "Console"

53

using System;

class HelloCSharp{

static void Main(){

Console.WriteLine("Hello, C#");}

}

The { symbol should be alone on a new line.

The block after the {symbol should be

indented by a TAB.The } symbol should

be under the

corresponding {.

Class names should useHelloCsharpand start with a CAPITAL letter.

54

using System

;

class HelloCSharp {static

void Main( ) { Console. WriteLine ("Hello, C#" ) ;Console.

WriteLine ( "Hello again") ;}}

Such formatting makes the source code

unreadable.

Page 10: Introduction to Programming · 2017-12-09 · 12/12/2017 EEE-425 Programming Languages (2013) 3 To create an access shortcut (or keyboard shortcut), 13 To add other shortcut keys

12/12/2017

EEE-425 Programming Languages (2013) 10

using

◦ like import in Java: bring in namespaces

namespace

◦ disambiguation of names◦ like Internet hierarchical names and C++ naming

class

◦ like in C++ or Java◦ single inheritance up to object

static void Main()◦ Defines the entry point for an assembly.◦ Four different overloads – taking string

arguments and returning int’s. Console.WriteLine(Write)◦ Takes a formatted string: “Composite

Format”◦ Indexed elements: e.g., {0}

can be used multiple times only evaluated once

◦ {index [,alignment][:formatting]}

Programming language

◦ A syntax that allow to give instructions to the computer

C# features:

◦ New cutting edge language

◦ Extremely powerful

◦ Easy to learn

◦ Easy to read and understand

◦ Object-oriented

57 58

Environment for execution of .NET programs

Powerful library of classes

Programming model

Common execution engine for many programming languages◦ C#

◦ Visual Basic .NET

◦ Managed C++

◦ ... and many others

59

Page 11: Introduction to Programming · 2017-12-09 · 12/12/2017 EEE-425 Programming Languages (2013) 3 To create an access shortcut (or keyboard shortcut), 13 To add other shortcut keys

12/12/2017

EEE-425 Programming Languages (2013) 11

61

Operating System (OS)

Common Language Runtime (CLR)

Base Class Library (BCL)

ADO.NET, LINQ and XML (Data Tier)

WCF and WWF (Communication and Workflow Tier)

ASP.NETWeb Forms, MVC, AJAXMobile Internet Toolkit

WindowsForms

WPF Silverlight

C# C++ VB.NET J# F# JScript Perl Delphi …

Building blocks of .NET Framework

62

FCL

CLR

The common classes that are used in many programs◦ System.Console.WriteLine◦ XML, Networking, Filesystem, Crypto, containers◦ Can inherit from many of these classes

Many languages run on .NET framework◦ C#, C++, J#, Visual Basic◦ even have Python (see IronPython)

Common Language Runtime (CLR)◦ Managed execution environment

Executes .NET applications

Controls the execution process

◦ Automatic memory management (garbage collection)

◦ Programming languages integration

◦ Multiple versions support for assemblies

◦ Integrated type safety and security

65

CLR

Class Loader

MSIL to NativeCompilers (JIT)

CodeManager

GarbageCollector (GC)

Security Engine Debug Engine

Type Checker Exception Manager

Thread Support COM Marshaler

Base Class Library Support

From MSDN

Page 12: Introduction to Programming · 2017-12-09 · 12/12/2017 EEE-425 Programming Languages (2013) 3 To create an access shortcut (or keyboard shortcut), 13 To add other shortcut keys

12/12/2017

EEE-425 Programming Languages (2013) 12

CLR via C#, Jeffrey Richter

68

CLR is actually an implementation by Microsoft of the CLI (Common Language Infrastructure) .

CLI is an open specification.

CLR is really a platform specific implementation.

Framework Class Library (FCL)

◦ Provides basic functionality to developers:

Console applications

WPF(Windows Presentation Framework) and

Silverlight rich-media applications

Windows Forms GUI applications

Web applications (dynamic Web sites)

Web services, communication and workflow

Server & desktop applications

Applications for mobile devices

69 70

71

Visual Studio – Integrated Development Environment (IDE)

Development tool that helps us to:◦ Write code

◦ Design user interface

◦ Compile code

◦ Execute / test / debug applications

◦ Browse the help

◦ Manage project's files

72

Page 13: Introduction to Programming · 2017-12-09 · 12/12/2017 EEE-425 Programming Languages (2013) 3 To create an access shortcut (or keyboard shortcut), 13 To add other shortcut keys

12/12/2017

EEE-425 Programming Languages (2013) 13

Single tool for:

◦ Writing code in many languages (C#, VB, …)

◦ Using different technologies (Web, WPF, …)

◦ For different platforms (.NET CF, Silverlight, …)

Full integration of most development activities (coding, compiling, testing, debugging, deployment, version control, ...)

Very easy to use!

73 74

1. File New Project ...2. Choose C# console application3. Choose project directory and name

75

4. Visual Studio creates some source code for you

76

Namespace not required

Class name should be

changed

Some imports are not required

The process of compiling includes:◦ Syntactic checks

◦ Type safety checks

◦ Translation of the source code to lower level language (MSIL)

◦ Creating of executable files (assemblies)

You can start compilation by◦ Using Build->Build Solution/Project

◦ Pressing [F6] or [Shift+Ctrl+B]

77

The process of running application includes:

◦ Compiling (if project not compiled)

◦ Starting the application

You can run application by:

◦ Using Debug->Start menu

◦ By pressing [F5] or [Ctrl+F5]

78

Page 14: Introduction to Programming · 2017-12-09 · 12/12/2017 EEE-425 Programming Languages (2013) 3 To create an access shortcut (or keyboard shortcut), 13 To add other shortcut keys

12/12/2017

EEE-425 Programming Languages (2013) 14

The process of debugging application includes:◦ Spotting an error

◦ Finding the lines of code that cause the error

◦ Fixing the code

◦ Testing to check if the error is gone and no errors are introduced

Iterative and continuous process

79

Visual Studio has built-in debugger

It provides:◦ Breakpoints

◦ Ability to trace the code execution

◦ Ability to inspect variables at runtime

80

Live Demo-Example 01-01, 01-02

81

Questions?

82

1. Create console application that prints your first and last name.

2. Write a program to print the numbers 1, 101 and 1001.

3. Create a console application that prints the current date and time.

4. Create a console application that calculates and prints the square

of the number 1234.

5. Write a program that prints the first 10 members of the sequence:

2, -3, 4, -5, 6, -7, ...

6. Write a program to read your age from the console and print how

old you will be after 10 years.

83