Advanced C# Framework Topics

Lesson 1 - Print Functionality

The PrintDocument Component

Creating PrintDocument object

How Printing Works

PrintPage event

// Method to handle PrintPage event

public void PrintElipse(object sender, System.Drawing.Printing.PrintPageEventArgs e)
e.Graphics.DrawElipse(Pens.Black, e.MarginBounds);

Printing Content


myPrintPreview.Document = myPrintDocument;


Printing Configuration




Configure PageSetting at run time

Lesson 2 - Accessing and Invoking Components

.NET and COM Type Libraries

Web Service

public class AsyncDemo
WebService1 myService;

public void CallMethodAsynchronously()
myService = new WebService1();

// Create AsyncCallback delegate
System.AsyncCallback myCallback = new System.AsyncCallback(CallBack);

// Object required by method call but not
// used

myService.BeginMyMethod(myCallback, new Object());

public void CallBack(IAsynResult e)
string myString;

myString = myService.EndMyMethod(e);

Accessing Windows API

private static extern int Beep(int dwFreq, int dwDuration);

Lesson 3 Accessibility


Program Accessibility

Support Standard System Settings

High Contrast

Keyboard Access

- Document + make discoverable keyboard access to all app features 
- Provide shortcut keys to menu items 
- Set Tab order on dialogs 

Notify Keyboard Focus Location

Do not rely on sound alone

Accessibility Properties

Lesson 4 - Implementing Help

The Help Class

Help.ShowHelp(MyForm, @"C:\myHelpFile.htm", "HelpMenu");

HelpProvider Component


Lesson 5 - Globalisation and Localisation

System.Threading.Thread.CurrentThread.Currentculture = 

new System.Globalization.CultureInfo("fr-CA");
CultureInfo myCurrentculture = CultureInfo.CurrentCulture;


Label1.Text = "$500"

Whereas setting to value formatted to currency will result in 500 being displayed for en-GB - note no currency conversion takes place

Label1.Text = (500).ToString("C");


Culture-Specific Formatting

CultureInfo modJPCulture = new CultureInfo("jp-JN");

modJPCulture.NumberFormat.CurrencySymbol = "$";

Thread.CurrentThread.CurrentCulture = modJPCulture;

Right-to-left Display

Character Encodings

// Code page 932 represents Japanese chars  
Encoding myEncoding = Encoding.GetEncoding(932);
// Obtain encoding instances  
byte[] tgtData;

Encoding srcEncoding = Encoding.GetEncoding(932);
UnicodeEncoding tgtEncoding = new UnicodeEncoding();

// Convert legacy data (in mystring) to bytes
byte[] myData = srcEncoding.GetBytes(myString);

// Perform conversion
tgtData = Encoding.Convert(srcEncoding, tgtEncoding, myData);
UnicodeEncoding myEncoding = new UnicodeEncoding();

char[] myChars;

myChars = myEncoding.GetChars(myBytes);