The PrintManager object also exposes several methods that are not used directly in the printing process, but which can come in handy when you build your own print-enabled applications using Xceed Chart for WinForms. These are helper methods that enumerate installed printers, paper sizes, and paper sources.
Enumerating Installed Printers
The EnumerateInstalledPrinters function fills an ArrayList with the installed printers and returns the index of the default printer. If there are no installed printers, the array is empty and the returned index is -1. The following code fills a combo box with the installed printers:
VB.NET
Dim arrComboItems As ArrayList = New ArrayList() Dim nDefaultPrinter As Integer = m_ChartControl.PrintManager.EnumerateInstalledPrinters(arrComboItems) Dim i As Integer
For i = 0 To arrComboItems.Count- 1 Step i + 1 InstalledPrintersComboBox.Items.Add(CType(arrComboItems(i), String)) Next
C#
ArrayList arrComboItems = new ArrayList(); int nDefaultPrinter = m_ChartControl.PrintManager.EnumerateInstalledPrinters(arrComboItems);
for (int i = 0; i < arrComboItems.Count; i++) { InstalledPrintersComboBox.Items.Add((String)arrComboItems[i]); }
Enumerating Paper Sizes
You can enumerate the paper sizes supported by an installed printer by using the EnumeratePaperSizes function, which accepts an index of a printer and an ArrayList filled with PaperSize objects. The function returns the default paper size. The following code fills a combo box with the paper size for the selected printer index:
VB.NET
Dim arrComboItems As ArrayList = New ArrayList() Dim paperSize As PaperSize = m_PrintManager.EnumeratePaperSizes(currentPrinter, arrComboItems)
Dim i As Integer For i = 0 To arrComboItems.Count- 1 Step i + 1 If CType(arrComboItems(i) = paperSize.PaperName,String) Then selectedIndex = i End If
PaperSizeComboBox.Items.Add(CType(arrComboItems(i), String)) Next
If selectedIndex <> -1 Then PaperSizeComboBox.SelectedIndex = selectedIndex End If
C#
ArrayList arrComboItems = new ArrayList(); PaperSize paperSize = m_PrintManager.EnumeratePaperSizes(currentPrinter, arrComboItems);
for (int i = 0; i < arrComboItems.Count; i++) { if ((String)arrComboItems[i] == paperSize.PaperName) selectedIndex = i;
if (selectedIndex != -1) PaperSizeComboBox.SelectedIndex = selectedIndex;
Enumerating Paper Sources
Finally, you can enumerate the paper sources supported by a printer by using the EnumeratePaperSources function. It is similar to the EnumeratePaperSizes but fills an array with the supported paper sources and returns a PaperSource object. The following code fills a combo box with the supported paper sources:
VB.NET
Dim arrComboItems As ArrayList = New ArrayList() Dim defaultPaperSource As PaperSource = m_PrintManager.EnumeratePaperSources(currentPrinter,arrComboItems)
Dim i As Integer For i = 0 To arrComboItems.Count- 1 Step i + 1 If CType(arrComboItems(i), String) = defaultPaperSource.SourceName Then selectedIndex = i End If
PaperSourceComboBox.Items.Add(CType(arrComboItems(i), String)) Next
If selectedIndex <> -1 Then PaperSourceComboBox.SelectedIndex = selectedIndex End If
C#
ArrayList arrComboItems = new ArrayList(); PaperSource defaultPaperSource = m_PrintManager.EnumeratePaperSources(currentPrinter, arrComboItems);
for (int i = 0; i < arrComboItems.Count; i++) { if ((String)arrComboItems[i] == defaultPaperSource.SourceName) selectedIndex = i;