C# and.NET programming – introduction 1 Introduction A course in C# and.NET programming Associated book:

Slides:



Advertisements
Similar presentations
Mobile Development Introduction to Visual Studio Development Rob Miles Department of Computer Science.
Advertisements

Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
 2007 Dr. Natheer Khasawneh. Chapter 13. Graphical User Interface Concepts: Part 1.
8 April Doors Network Configuration Parameters (Single Site Mode)
Chapter 2 –Visual Basic, Controls, and Events
Programming Based on Events
Advanced Object-Oriented Programming Features
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
C# Programming: From Problem Analysis to Program Design1 Introduction to Windows Programming C# Programming: From Problem Analysis to Program Design 3.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
DT265-2 Object Oriented Software Development 2 Lecture 3 : Windows Programming Lecturer Pat Browne
Windows Tutorial 9 Maintaining Hardware and Software
Controls General Discussion. VB Controls Visual Basic Controls A control is the generic name for any object placed on a form Controls may be images,
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
Getting Started Example ICS2O curriculum
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Microsoft Visual Basic 2005 CHAPTER 12 Cell Phone Applications and Web Services.
Getting started with Microsoft.NET Gadgeteer Comberton Village College Gadgeteer Club.
CS 2340: Programming in VB Instructor: Dr. Qi Yang Office: 213 Ullrich Phone: YangQ 1.
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
Lab 8 – C# Programming Adding two numbers CSCI 6303 – Principles of I.T. Dr. Abraham Fall 2012.
Visual Basic Chapter 1 Mr. Wangler.
CS 2340 Programming in VB.NET Instructor: Dr. Qi Yang Office: 213 Ullrich Phone: YangQ 1.
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.
Microsoft Visual Basic 2005: Reloaded Second Edition
CIS 338: Creating ActiveX Controls Dr. Ralph D. Westfall March, 2003.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Using the Actions Pane, Host Controls, and Smart Tags
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Visual Programming Fall 2012 – FUUAST Topic: Development environment.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 1B Introduction (Tutorial)
Chapter 3: Using GUI Objects and the Visual Studio IDE.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
GUI development with Matlab: GUI Front Panel Components 1 GUI front panel components In this section, we will look at -GUI front panel components -Programming.
Introduction to Visual Basic.NET Chapter 2 Introduction to Controls, Events.
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
BIL528 – Bilgisayar Programlama II Introduction 1.
Microsoft Visual Basic 2008 CHAPTER TWELVE Cell Phone Applications and Web Services.
Controls. Adding Controls to Form -You can pick controls from the toolbox. -To add the controls from Toolbox to the Form You have be in design view. -To.
Lesson No: 6 Introduction to Windows XP CHBT-01 Basic Micro process & Computer Operation.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Visual Basic CDA College Limassol Campus Lecture:Pelekanou Olga Semester C Week - 1.
1.
Microsoft Visual Basic 2012 CHAPTER ELEVEN Multiple Classes and Inheritance.
1 Visual Basic Part I - A tool for customizing your program Principles of GIS
Microsoft Visual Basic 2005 BASICS Lesson 3 Events and Code.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
Object-Oriented Application Development Using VB.NET 1 Chapter 2 The Visual Studio.NET Development Environment.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 3 Building an Application in the Visual Basic.NET Environment.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
A+ Second Edition Genetic Computer School Lesson 13 Drivers, Applications, Printers, Scanners and Printing.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
Supporting Multiple Pointing Devices in Microsoft Windows
Computing with C# and the .NET Framework
Chapter 1: An Introduction to Visual Basic 2015
Mobile Operating System
Introduction to VB6 Week 1 3/2/2004 PPCC - Introduction to VB6
An Introduction to Visual Basic
Social Media And Global Computing Introduction to Visual Studio
CIS16 Application Development Programming with Visual Basic
Visual C# - GUI and controls - 1
Presentation transcript:

C# and.NET programming – introduction 1 Introduction A course in C# and.NET programming Associated book:

2 C# and.NET programming – introduction 2 Development environment We will create Windows applications

3 C# and.NET programming – introduction 3 Design environment: Toolbar messages Properties/events window Code editor Form Solution explorer Menus

4 C# and.NET programming – introduction 4 The Form – Most important - place controls – the UI. Display by clicking Form1.cs [Design] tab Form Textbox Button Label Listbox

5 C# and.NET programming – introduction 5 The Toolbox – Grouped by task Contains controls Common controls are: Buttons, Textboxes, Labels, Radio buttons etc.

6 C# and.NET programming – introduction 6 The Properties / Events window Properties Each control has properties – e.g. Name Position (top and left) Size (height and width) Text Description of property

7 C# and.NET programming – introduction 7 The Properties / Events window Events Events – happen to controls e.g: Button click KeyPress MouseMove MouseDown Others – Form load

8 C# and.NET programming – introduction 8 The Code Editor – where you enter your code Double-click object to enter code Some added for you – do not delete

9 C# and.NET programming – introduction 9 Your First C# Program Run C#, start a new Project, > Windows Application and call it ‘Hello world’ Save the project. Select File>Save All. Display the form (click form1.cs[Design] tab). Add button (drag and drop) from Toolbox to form

10 C# and.NET programming – introduction 10 Change the button’s text display (a property). Display the properties window, Scroll to the Text property, type in ‘Hello world’

11 C# and.NET programming – introduction 11 Place TextBox and label to form Change label’s caption property to ‘My First C# Program’. Form looks like:

12 C# and.NET programming – introduction 12 Run program – not much happens. Close it. Double-click button to add code for button click Add code: textBox1.Text="Hello world";

13 C# and.NET programming – introduction 13 Run program, click button. ‘Hello World’ is displayed – Your first C# program ! Note use dot notation to access property C# is case sensitive

14 C# and.NET programming – introduction 14 Summary Free software from Microsoft Development environment Form, Code editor, Toolbox, properties/event window Drag/drop controls (buttons) to form Double-click to add code First program

15 C# and.NET programming – OOP Topics Adding methods to class Static classes – available to all objects Overriding default methods Inheritance Protected declaration

16 C# and.NET programming – OOP Methods Add method Move Move Point one place in X and Y direction Code: public void Move( )// declare public { _x++; // move X by one _y++;// move Y by one } // end move Use: myPoint.Move( );

17 C# and.NET programming – OOP Method overloading Add second Move method – pass distance to move public void Move(int Xdistance, int Ydistance) { _x = _x + Xdistance; _y = _y + Ydistance; } Use both: myPoint.Move(12,34);// pass X and Y myPoint.Move( ); // one unit in X and Y

18 C# and.NET programming – OOP IntelliSense knows about both:

19 C# and.NET programming – OOP Static Classes - don’t have to be instantiated. ‘Distance from Origin’ example of this – available to all objects Code: class Calculate // pass x,y return distance { public static double DistanceToOrigin(int x, int y) { return Math.Sqrt(x * x + y * y); } Use: distance = Calculate.DistanceToOrigin (myPoint.X, myPoint.Y);

20 C# and.NET programming – OOP More useful ToString method ? - Override default ToString method Add code: public override string ToString( ) { return "My Point Object is at : " + _x + “," + _y; } Use: MessageBox.Show(MyPoint.ToString( )); Displays: ‘My Point Object is at : 123,456’

21 C# and.NET programming – OOP Inheritance Take a class and extend Seen this when we create our Form: public partial class Form1 : Form Let’s create Circle Class from our Point Class Can add radius and area Code: public Circle : Point

22 C# and.NET programming – OOP Add new class Circle: (Project > Add class) Call it Circle, code: class Circle : Point { } Can now create a circle: Circle smallcircle = new Circle( ); Because we are using existing code, it’s more reliable

23 C# and.NET programming – OOP Extend – define radius Constructors: class Circle : Point { private double _radius;// internal – private public Circle( ) { } public Circle(int xValue, int yValue, double radius) { _x = xValue; // _x and _y now declared protected in Point class // still private to outside world _y = yValue; _radius = radius; }

24 C# and.NET programming – OOP // add property - radius – use get and set public double radius { get { return _radius; } set { if (value >= 0) _radius = value; }

25 C# and.NET programming – OOP Extend further Add method – Area: // method Area public double area( ) { return Math.PI * _radius * _radius; }

26 C# and.NET programming – OOP Override ToString method: public override string ToString() { return "Circle at x,"+_x+" y,"+_y+ "radius,"+_radius; }

27 C# and.NET programming – OOP Use: Circle smlCircle = new Circle( ); Circle largeCircle = new Circle(12, 34, 56); smlCircle.X = 98; smlCircle.Y = 87; smlCircle.Radius = 10; MessageBox.Show(smlCircle.ToString( )); MessageBox.Show(largeCircle.ToString( )); MessageBox.Show (smlCircle.area( ).ToString( ));

28 C# and.NET programming – OOP Summary: Adding methods Static classes – available to all objects Overriding default methods Inheritance – extend class Protected declaration

29 C# and.NET programming – Hardware 29 Topics: Serial port Parallel port API DLLs USB USB Module

30 C# and.NET programming – Hardware 30 Serial Port control Non-visual control. Properties: BaudRate: 9600, DataBits: 8, Parity: None, PortName: COM1, StopBits: One. Main event: DataReceived Occurs when data is received from the port

31 C# and.NET programming – Hardware 31 Needs: using System.IO.Ports; Set properties serialPort1.BaudRate = 9600; serialPort1.DataBits = 8; serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), "None"); serialPort1.StopBits = (StopBits)Enum.Parse(typeof(StopBits), "One"); Open device serialPort1.Open();

32 C# and.NET programming – Hardware 32 Send and receive data serialPort1.WriteLine(textBox1.Text); listBox1.Items.Add(serialPort1.ReadLine()); Or use DataReceived event

33 C# and.NET programming – Hardware 33 e.g: private void serialPort1_DataReceived (object sender, SerialDataReceivedEventArgs e) { listBox1.Items.Add(serialPort1.ReadLine()); }

34 C# and.NET programming – Hardware 34 Parallel interface. One way of getting digital I/O. Data register: Bits 0-7 data Status Register: Bits: 0-2 not used, 3-Error, 4-Select, 5- paper out, 6-acknowledge, 7 busy. Control Register: Bits: 0 strobe, 1-Auto-feed, 2-initialise, 3-select, 4-IRQ enable, 5-7 not used Base address (data register) is at 0x378 Status and control at 0x379 and 0x37A. Eight outputs Only status register bits are guaranteed inputs

35 C# and.NET programming – Hardware 35 Accessing the parallel port Use inpout32.dll - Lake View Research ( Provides direct read and write of the I/O [DllImport("inpout32.dll", EntryPoint = "Out32")] public static extern void Output(int adress, int value); [DllImport("inpout32.dll", EntryPoint = "Inp32")] public static extern int Input(int address); Use: Output(port, data); // writes data to port temp = Input(port); // read port, puts data in temp

36 C# and.NET programming – Hardware 36 USB interfacing Most popular way of interfacing to the PC. Complete design involves: Hardware / USB interface PC drivers Understanding protocol and hardware limitations Difficult

37 C# and.NET programming – Hardware 37 The USB interface - 1 USB 2.0 three modes of operation: High speed (480 Mbits/s), Full speed (12 Mbits/s) and Low speed (1.5 Mbits/s). Device indicates its speed by pulling D+ or D- data line high. Power can be taken from USB bus – but strict limitations

38 C# and.NET programming – Hardware 38 The USB interface – 2 The host controls the bus - initiates & controls all messages Up to 127 devices on the bus - a device may not run at its full speed. USB Connectors: The A-type is exclusively for a host B-types are for connection to slaves. Smaller B-type for small devices such as mobile phones and digital cameras.

39 C# and.NET programming – Hardware 39 USB interfacing Many manufacturers make USB / I/O modules One is from DLP design: DLP-245PB-G

40 C# and.NET programming – Hardware 40 The module features - 1: USB 1.0 and 2.0 compatible – communication at up to 2Mbits/s 18 digital I/O lines (6 as A/D inputs) Programmable Microchip 16F877A PIC Pre-programmed code to interface to USB

41 C# and.NET programming – Hardware 41 The module features - 2: Code provides access to: I/O (analogue and digital) EEPROM and external digital temperature sensors Access to the PIC data bus for further expansion. No in-depth knowledge of USB hardware or software is required 40-pin DIL pin-out: further expansion is easy.

42 C# and.NET programming – Hardware 42 Using the module Install drivers and DLL – can then use from C# Can read and write directly to I/O Need to understand protocol

43 C# and.NET programming – Hardware 43

44 C# and.NET programming – Hardware 44 Summary Serial port Parallel port API DLLs USB USB Module