C# Programming for Windows and Android
By John Allwork
Published by Elektor International Media B.V. (2015)
Website: www.elektor.com
Table of Contents
Introduction
Covers the introduction to the book and its scope.
Chapter 1: The Visual Studio 2015 Environment
- 1.1 Introduction
- 1.1.1 What's new in VS2015?
- 1.2 Obtaining the Visual Studio software
- 1.3 The Visual Studio development environment
- 1.3.1 The Form
- 1.3.2 The Code Editor
- 1.3.3 The Toolbox
- 1.3.4 The properties and events box
- 1.4 Your First C# Program
- 1.4.1 Hello World
- 1.4.2 Copying the project
- 1.4.3 Common errors
- 1.4.4 Properties exercises
- 1.5 The Solution Explorer
- 1.6 Program execution
- 1.7 Number conversion
- 1.8 Exercise: Simple calculator
- 1.9 A Console Application
- 1.10 Windows Presentation Foundation (WPF) applications
- 1.11 Self Assessment Exercises
- 1.12 Summary
Chapter 2: Common controls, properties and events
- 2.1 Introduction
- 2.2 The Button
- 2.3 The TextBox
- 2.3.1 Dealing with text in a TextBox
- 2.4 The ListBox control
- 2.5 The CheckedListBox
- 2.6 The CheckBox
- 2.7 The RadioButton
- 2.8 The NumericUpDown control
- 2.9 Displaying Images – the PictureBox control
- 2.10 Focus and TabIndex
- 2.11 Even more controls
- 2.12 The Web browser control
- 2.13 The Containers controls
- 2.14 Listing controls
- 2.15 Exercise: Dating registration form
- 2.16 Self Assessment Exercises
- 2.17 Summary
Chapter 3: Dialogs and forms
- 3.1 Introduction
- 3.2 User messages – The Message Box Dialog
- 3.2.1 Message Reply
- 3.3 Creating your own dialogs - Prompting for input
- 3.3.1 User input - Adding forms exercise
- 3.4 Splash forms and the Timer control
- 3.5 Accessing controls on other forms
- 3.6 Self Assessment Exercises
- 3.7 Summary
Chapter 4: The C# Language – the basics
- 4.1 Introduction
- 4.2 Declarations - Variables and data type identifiers
- 4.2.1 Naming convention
- 4.2.2 Some declaration examples:
- 4.3 Assignments and operators
- 4.3.1 Shortcuts
- 4.4 Comments
- 4.5 Converting (casting) data types
- 4.6 Characters and strings
- 4.7 Escape sequences
- 4.8 Logical operations – Boolean data type
- 4.9 Mathematical Functions
- 4.10 Date and Time
- 4.10.1 DateTime properties and methods
- 4.11 Nullable data type declaration – '?'
- 4.12 Scope
- 4.12.1 Block scope
- 4.12.2 Procedure scope
- 4.12.3 Class scope
- 4.13 Self Assessment Exercises
- 4.14 Summary
Chapter 5: The C# Language – arrays, structures and strings
- 5.1 Introduction
- 5.2 Arrays
- 5.3 Multidimensional arrays
- 5.4 Structures
- 5.4.1 The public declaration
- 5.5 Character arrays and strings
- 5.6 String manipulation
- 5.7 String conversion
- 5.8 String methods
- 5.8.1 The Contains( ) method
- 5.8.2 The Substring( ) method
- 5.8.3 The IndexOf and IndexOfAny() methods
- 5.8.4 Dealing with spaces– the Trim and Remove methods
- 5.8.5 The Replace method
- 5.8.6 The Split method - parsing strings
- 5.8.7 Upper and lower case methods
- 5.8.8 Padding strings
- 5.9 Dynamic Arrays: The ArrayList Class
- 5.10 Collections – the System.Collection.Generic namespace
- 5.11 Self Assessment Exercises
- 5.12 Summary
Chapter 6: Program Flow, Loops and Decisions
- 6.1 Introduction
- 6.2 The if statement
- 6.2.1 The if .. else statement
- 6.2.2 The if .. else shortcut
- 6.2.3 The ?? null-coalescing operator
- 6.2.4 The ?. and ?[] operators
- 6.3 The switch statement
- 6.3.1 The goto statement
- 6.3.2 Switching on a string variable
- 6.4 Looping - The for (and forr) statements
- 6.4.1 Code snippets
- 6.4.2 The foreach statement
- 6.5 The while and do-while statements
- 6.6 Exceptions. The try-catch code
- 6.7 Application.DoEvents method
- 6.8 Self Assessment Exercises
- 6.9 Summary
Chapter 7: Object oriented programming: Classes and methods
- 7.1 Introduction
- 7.2 Method declaration
- 7.3 Parameter passing
- 7.4 Pass by reference – ref and out keywords
- 7.5 Scope of a method – private and public
- 7.6 Recursive methods
- 7.7 Calling an event
- 7.8 Classes and Namespaces
- 7.9 Self Assessment Exercises
- 7.10 Summary
Chapter 8: Object oriented programming – creating objects
- 8.1 Introduction
- 8.2 Creating Objects
- 8.3 Constructors
- 8.4 The object's ToString method
- 8.5 Overriding
- 8.6 Adding Methods to a class
- 8.7 Method overloading
- 8.8 Static classes
- 8.9 Inheritance
- 8.10 Overriding methods
- 8.11 GetType methods
- 8.12 Interfaces
- 8.13 Self Assessment Exercises
- 8.14 Summary
Chapter 9: File handling and menu dialogs
- 9.1 Introduction
- 9.2 File Types – Text or Binary
- 9.2.1 Text Files
- 9.2.2 Binary Files - Typed and Untyped files
- 9.3 File Dialog Boxes and MenuStrip control
- 9.3.1 The MenuStrip control a simple RichTextBox editor
- 9.3.2 The OpenFileDialog
- 9.3.3 The SaveFileDialog
- 9.3.4 Open and Save Dialog Box properties
- 9.3.5 File error handling
- 9.4 Adding Menu items – About box
- 9.5 PrintDialog boxes
- 9.6 RichTextBox editor: cut, paste copy and find
- 9.7 File and Directory classes
- 9.8 File handling example
- 9.8.1 Using StreamWriter and StreamReader objects
- 9.8.2 Using BinaryReader and BinaryWriter objects
- 9.9 Self Assessment Exercises
- 9.10 Summary
Chapter 10: Graphics and Multimedia
- 10.1 Introduction
- 10.2 Drawing Graphics
- 10.3 The Paint event
- 10.4 Drawing on the form
- 10.5 The Pen
- 10.5.1 Line end caps
- 10.6 The Brush
- 10.7 Drawing Text
- 10.8 Basic Shapes
- 10.9 Other shapes – arcs, pies, polylines and polygons
- 10.10 Drawing Graphs and Charts
- 10.11 Multimedia applications
- 10.11.1 MediaPlayer events
- 10.12 Launching Windows applications
- 10.13 Self Assessment Exercises
- 10.14 Summary
Chapter 11: Debugging
- 11.1 Introduction
- 11.2 Writing to the Debug Window
- 11.3 Using the Debugger
- 11.3.1 Setting a breakpoint
- 11.3.2 Pausing the Program
- 11.4 Conditional Breakpoints
- 11.5 Restarting - Stepping through your code
- 11.6 The breakpoint windows
- 11.6.1 The Local and Auto windows
- 11.6.2 Watch window
- 11.6.3 The Immediate window
- 11.6.4 The Call Stack
- 11.7 Diagnostic Tool Window
- 11.8 Performance Tips (PerfTips)
- 11.9 IntelliTrace
- 11.10 Self Assessment Exercises
- 11.11 Summary
Chapter 12: Threading
- 12.1 Introduction
- 12.2 Threads
- 12.3 Writing Thread Code
- 12.4 Thread sleeping example
- 12.5 Multiple Threading example
- 12.6 Accessing form controls from threads
- 12.7 Asynchronous programming - await, async
- 12.8 Other thread considerations
- 12.9 Self Assessment Exercises
- 12.10 Summary
Chapter 13: Internet Applications
- 13.1 Introduction
- 13.2 Client-Server communication
- 13.3 TCP and UDP
- 13.4 Creating a TCP server
- 13.5 Threads
- 13.6 Creating a TCP client
- 13.7 TCP Client-Server application
- 13.8 TCP Client Code
- 13.9 UDPClient communications – A chat program
- 13.9.1 UDPClient.Send( )
- 13.9.2 UDPClient.Receive()
- 13.9.3 UDP program threads
- 13.9.4 UDP design
- 13.9.5 UDP server code
- 13.9.6 UDP client code
- 13.10 A Local Chat program
- 13.10.1 The Second Chat program
- 13.11 Remote Chat program
- 13.12 Web requests
- 13.13 E-mail communications
- 13.14 File transfer protocol
- 13.15 Self Assessment Exercises
- 13.16 Summary
Chapter 14: Introduction to Databases
- 14.1 Introduction
- 14.2 A typical database
- 14.3 Dealing with Databases
- 14.3.1 Viewing a database in C#
- 14.4 Creating a new database
- 14.4.1 Adding the database tables
- 14.5 Adding relationships – linking the tables
- 14.6 Adding data to the tables
- 14.7 Self Assessment Exercises
- 14.8 Summary
Chapter 15: Displaying databases
- 15.1 Introduction
- 15.2 The dataset, data binding and ActiveX Data Objects (ADO.NET)
- 15.3 Displaying database information
- 15.3.1 DataGridView
- 15.3.2 Details view
- 15.4 Viewing the data set
- 15.5 Structured Query Language (SQL)
- 15.6 Query Builder
- 15.7 LINQ Queries
- 15.8 Self Assessment Exercises
- 15.9 Summary
Chapter 16: Accessing a database with code
- 16.1 Introduction
- 16.2 Creating the database
- 16.3 Displaying the database
- 16.4 Accessing the database from code
- 16.4.1 Update the Database
- 16.5 A WPF database
- 16.6 Self Assessment Exercises
- 16.7 Summary
Chapter 17: Plotting and Charts
- 17.1 Introduction
- 17.2 The Chart control
- 17.3 Chart elements
- 17.4 Column Chart example
- 17.5 Plotting points
- 17.6 Drawing a graph
- 17.6.1 Adding a second plot
- 17.7 Displaying database data on a chart
- 17.8 Dynamic data display
- 17.9 Self Assessment Exercises
- 17.10 Summary
Chapter 18: Dynamic link libraries (DLL) and using Windows API
- 18.1 Introduction
- 18.2 Writing a DLL
- 18.3 Calling the DLL
- 18.4 Static Classes
- 18.5 Windows Application Program Interface (API)
- 18.6 Using Win API calls
- 18.7 MessageBox API example
- 18.8 Playing sounds
- 18.8.1 Which library?
- 18.9 Unsafe code
- 18.10 Measuring time
- 18.11 Self Assessment Exercises:
- 18.12 Summary
Chapter 19: Sound, Video and DirectX drivers
- 19.1 Introduction
- 19.2 DirectX
- 19.3 The DirectX components
- 19.3.1 The DirectSound class
- 19.3.2 The DirectInput class
- 19.3.3 Cooperative level
- 19.3.4 The Buffers
- 19.3.5 The input device
- 19.4 Playing sounds
- 19.5 Playing waveforms
- 19.6 Detecting input devices
- 19.7 Sound Capture
- 19.8 Sound capture program
- 19.9 Video Capture
- 19.9.1 Video Capture Devices
- 19.9.2 Video Capture Program
- 19.9.3 Video Capture Preview
- 19.10 Streaming Video
- 19.11 Self Assessment exercises
- 19.12 Summary
Chapter 20: Smartphone apps for Android
- 20.1 Introduction
- 20.2 Obtaining the Xamarin software
- 20.3 Your First Android Application
- 20.4 Recap
- 20.5 Show Message application
- 20.6 Deploying your application
- 20.7 Self Assessment Exercises
- 20.8 Summary
Chapter 21: Example GPS location application
- 21.1 Introduction
- 21.2 GPS example
- 21.2.1 Procedure
- 21.2.2 Permissions
- 21.2.3 The GPS Code
- 21.2.4 Emulate, deploy and run
- 21.3 SMS messaging
- 21.4 Sending an e-mail
- 21.5 Self Assessment Exercises
- 21.6 Summary
Chapter 22: Conclusion
Concluding remarks for the book.
Appendices
- Appendix A: Obtaining the Visual Studio software
- Appendix B: Installing the Xamarin Software
- Appendix C: Summary of C# Commands
Index
An index for quick reference.