PrinterSettings.Kind

   
 

using System;
using System.Drawing.Printing;

class MainClass {
    static void Main(string[] args) {
        foreach (string printerName in PrinterSettings.InstalledPrinters) {
            Console.WriteLine("Printer: {0}", printerName);

            PrinterSettings printer = new PrinterSettings();
            printer.PrinterName = printerName;
            if (printer.IsValid) {
                Console.WriteLine("Supported Paper Sizes:");

                foreach (PaperSize size in printer.PaperSizes) {
                    if (Enum.IsDefined(size.Kind.GetType(), size.Kind)) {
                        Console.WriteLine("  {0}", size);
                    }
                }
            }
        }
    }
}

    


Printer Caps 6

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury,
Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using System.Drawing.Printing;
using System.Drawing.Drawing2D;

namespace PrinterCaps6
{
public class PrinterCaps6 : System.Windows.Forms.Form
{
//Saved PageSettings Object
private PageSettings oPageSettings;

private int m_nCurrPrinter;
private int m_nCurrPage;

private System.Drawing.Printing.PrintDocument printDoc;
private System.Windows.Forms.PrintPreviewDialog ppDialog;
private System.Windows.Forms.Button btnPrint;
private System.Windows.Forms.PrintDialog oPrintDialog;
private System.Windows.Forms.PageSetupDialog oPageSetup;
private System.Windows.Forms.Button btnSetup;
private System.ComponentModel.Container components = null;

public PrinterCaps6()
{
InitializeComponent();

//Create PageSettings object to store page information
oPageSettings = new PageSettings();
}

///

/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///

/// Required method for Designer support – do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
// System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(PrinterCaps6));
this.printDoc = new System.Drawing.Printing.PrintDocument();
this.ppDialog = new System.Windows.Forms.PrintPreviewDialog();
this.btnPrint = new System.Windows.Forms.Button();
this.oPrintDialog = new System.Windows.Forms.PrintDialog();
this.oPageSetup = new System.Windows.Forms.PageSetupDialog();
this.btnSetup = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// printDoc
//
this.printDoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDoc_PrintPage);
//
// ppDialog
//
this.ppDialog.AutoScrollMargin = new System.Drawing.Size(0, 0);
this.ppDialog.AutoScrollMinSize = new System.Drawing.Size(0, 0);
this.ppDialog.ClientSize = new System.Drawing.Size(400, 300);
this.ppDialog.Enabled = true;
// this.ppDialog.Icon = ((System.Drawing.Icon)(resources.GetObject(“ppDialog.Icon”)));
this.ppDialog.Location = new System.Drawing.Point(326, 19);
this.ppDialog.MaximumSize = new System.Drawing.Size(0, 0);
this.ppDialog.Name = “ppDialog”;
this.ppDialog.Opacity = 1;
this.ppDialog.TransparencyKey = System.Drawing.Color.Empty;
this.ppDialog.Visible = false;
//
// btnPrint
//
this.btnPrint.Location = new System.Drawing.Point(52, 44);
this.btnPrint.Name = “btnPrint”;
this.btnPrint.TabIndex = 0;
this.btnPrint.Text = “Print”;
this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
//
// oPrintDialog
//
this.oPrintDialog.AllowSomePages = true;
this.oPrintDialog.PrintToFile = true;
//
// btnSetup
//
this.btnSetup.Location = new System.Drawing.Point(52, 8);
this.btnSetup.Name = “btnSetup”;
this.btnSetup.TabIndex = 1;
this.btnSetup.Text = “Page Setup”;
this.btnSetup.Click += new System.EventHandler(this.btnSetup_Click);
//
// PrinterCaps6
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(176, 86);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnSetup,
this.btnPrint});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = “PrinterCaps6”;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = “Printer Caps”;
this.ResumeLayout(false);

}
#endregion

///

/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new PrinterCaps6());
}

private void printDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
PrinterSettings pSettings = new PrinterSettings();
Font printFont = new Font(“Arial”, 12);

//Use the Margins
int nTextPosY = e.MarginBounds.Top;
int nTextPosX = e.MarginBounds.Left;
int nHeight = (int)printFont.GetHeight(e.Graphics);

//Height of a printer block
int nBlockHeight = 9 * nHeight;

if(e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages)
{
while(m_nCurrPage < e.PageSettings.PrinterSettings.FromPage) { //Move printer to next page block m_nCurrPrinter += (int)(e.MarginBounds.Height / nBlockHeight); m_nCurrPage++; if(m_nCurrPrinter > PrinterSettings.InstalledPrinters.Count)
return;
}

if(m_nCurrPage > e.PageSettings.PrinterSettings.ToPage)
{
//Don't print anything more
return;
}
}

//Print Background Graphic
LinearGradientBrush aBrush =
new LinearGradientBrush(e.MarginBounds,Color.FromArgb(100,Color.LightBlue),
Color.FromArgb(100,Color.Blue),LinearGradientMode.ForwardDiagonal);
e.Graphics.FillRectangle(aBrush,e.MarginBounds);

//Loop through using indexor now
//Start with the previous index in m_nCurrPrinter
for(int x = m_nCurrPrinter;x< PrinterSettings.InstalledPrinters.Count; x++)//each(string sPtr in PrinterSettings.InstalledPrinters) { pSettings.PrinterName = PrinterSettings.InstalledPrinters[x]; if(pSettings.IsValid) { //Ensure this printer block can fit on the page if(nTextPosY + nBlockHeight < e.MarginBounds.Bottom) { //Print the caps of the printer e.Graphics.DrawString(PrinterSettings.InstalledPrinters[x], printFont,Brushes.Black, nTextPosX, nTextPosY + 5); e.Graphics.DrawString("Can Duplex: " + pSettings.CanDuplex.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight)); e.Graphics.DrawString("Is Default: " + pSettings.IsDefaultPrinter.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*2)); e.Graphics.DrawString("Is Plotter: " + pSettings.IsPlotter.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*3)); e.Graphics.DrawString("Landscape Angle: " + pSettings.LandscapeAngle.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*4)); e.Graphics.DrawString("Maximum Copies: " + pSettings.MaximumCopies.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*5)); e.Graphics.DrawString("Maximum Page: " + pSettings.MaximumPage.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*6)); e.Graphics.DrawString("Minimum Page: " + pSettings.MinimumPage.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*7)); e.Graphics.DrawString("Supports Color: " + pSettings.SupportsColor.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*8)); nTextPosY = nTextPosY + ((5 + nHeight*8) + nHeight); //Draw line after each e.Graphics.DrawLine(System.Drawing.Pens.Black,nTextPosX,nTextPosY,e.MarginBounds.Right - 10,nTextPosY); e.Graphics.FillEllipse(System.Drawing.Brushes.Black,e.MarginBounds.Right - 10,nTextPosY-5,10,10); } else { //Couldn't fit block on the page - need more pages m_nCurrPrinter = x; e.HasMorePages = true; return; } } } //Last page if we reached here e.HasMorePages = false; m_nCurrPrinter = 0; return; } private void btnPrint_Click(object sender, System.EventArgs e) { //Set to defaults m_nCurrPrinter = 0; m_nCurrPage = 1; oPrintDialog.Document = printDoc; if (oPrintDialog.ShowDialog() == DialogResult.OK) { try { //Ensure the correct PrinterSettings object is used oPageSettings.PrinterSettings = printDoc.PrinterSettings; //Assign PageSettings object to all pages printDoc.DefaultPageSettings = oPageSettings; ppDialog.Document = printDoc; ppDialog.ShowDialog(); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } } } private void btnSetup_Click(object sender, System.EventArgs e) { oPageSetup.PageSettings = oPageSettings; if(oPageSetup.ShowDialog() == DialogResult.OK) { oPageSettings = oPageSetup.PageSettings; } } } } [/csharp]

Printer Caps 5

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury,
Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using System.Drawing.Printing;
using System.Drawing.Drawing2D;

namespace PrinterCaps5
{
public class PrinterCaps5 : System.Windows.Forms.Form
{
private int m_nCurrPrinter;
private int m_nCurrPage;

private System.Drawing.Printing.PrintDocument printDoc;
private System.Windows.Forms.PrintPreviewDialog ppDialog;
private System.Windows.Forms.Button btnPrint;
private System.Windows.Forms.PrintDialog oPrintDialog;
private System.ComponentModel.Container components = null;

public PrinterCaps5()
{
InitializeComponent();
}

///

/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///

/// Required method for Designer support – do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
// System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(PrinterCaps5));
this.printDoc = new System.Drawing.Printing.PrintDocument();
this.ppDialog = new System.Windows.Forms.PrintPreviewDialog();
this.btnPrint = new System.Windows.Forms.Button();
this.oPrintDialog = new System.Windows.Forms.PrintDialog();
this.SuspendLayout();
//
// printDoc
//
this.printDoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDoc_PrintPage);
//
// ppDialog
//
this.ppDialog.AutoScrollMargin = new System.Drawing.Size(0, 0);
this.ppDialog.AutoScrollMinSize = new System.Drawing.Size(0, 0);
this.ppDialog.ClientSize = new System.Drawing.Size(400, 300);
this.ppDialog.Enabled = true;
// this.ppDialog.Icon = ((System.Drawing.Icon)(resources.GetObject(“ppDialog.Icon”)));
this.ppDialog.Location = new System.Drawing.Point(142, 13);
this.ppDialog.MaximumSize = new System.Drawing.Size(0, 0);
this.ppDialog.Name = “ppDialog”;
this.ppDialog.Opacity = 1;
this.ppDialog.TransparencyKey = System.Drawing.Color.Empty;
this.ppDialog.Visible = false;
//
// btnPrint
//
this.btnPrint.Location = new System.Drawing.Point(52, 28);
this.btnPrint.Name = “btnPrint”;
this.btnPrint.TabIndex = 0;
this.btnPrint.Text = “Print”;
this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
//
// oPrintDialog
//
this.oPrintDialog.AllowSomePages = true;
//
// PrinterCaps5
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(176, 86);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnPrint});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = “PrinterCaps5”;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = “Printer Caps”;
this.ResumeLayout(false);

}
#endregion

///

/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new PrinterCaps5());
}

private void printDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
PrinterSettings pSettings = new PrinterSettings();
Font printFont = new Font(“Arial”, 12);

//Use the Margins
int nTextPosY = e.MarginBounds.Top;
int nTextPosX = e.MarginBounds.Left;
int nHeight = (int)printFont.GetHeight(e.Graphics);

//Height of a printer block
int nBlockHeight = 9 * nHeight;

if(e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages)
{
while(m_nCurrPage < e.PageSettings.PrinterSettings.FromPage) { //Move printer to next page block m_nCurrPrinter += (int)(e.MarginBounds.Height / nBlockHeight); m_nCurrPage++; if(m_nCurrPrinter > PrinterSettings.InstalledPrinters.Count)
return;
}

if(m_nCurrPage > e.PageSettings.PrinterSettings.ToPage)
{
//Don't print anything more
return;
}
}

//Print Background Graphic
LinearGradientBrush aBrush =
new LinearGradientBrush(e.MarginBounds,Color.FromArgb(100,Color.LightBlue),
Color.FromArgb(100,Color.Blue),LinearGradientMode.ForwardDiagonal);
e.Graphics.FillRectangle(aBrush,e.MarginBounds);

//Loop through using indexor now
//Start with the previous index in m_nCurrPrinter
for(int x = m_nCurrPrinter;x< PrinterSettings.InstalledPrinters.Count; x++)//each(string sPtr in PrinterSettings.InstalledPrinters) { pSettings.PrinterName = PrinterSettings.InstalledPrinters[x]; if(pSettings.IsValid) { //Ensure this printer block can fit on the page if(nTextPosY + nBlockHeight < e.MarginBounds.Bottom) { //Print the caps of the printer e.Graphics.DrawString(PrinterSettings.InstalledPrinters[x], printFont,Brushes.Black, nTextPosX, nTextPosY + 5); e.Graphics.DrawString("Can Duplex: " + pSettings.CanDuplex.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight)); e.Graphics.DrawString("Is Default: " + pSettings.IsDefaultPrinter.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*2)); e.Graphics.DrawString("Is Plotter: " + pSettings.IsPlotter.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*3)); e.Graphics.DrawString("Landscape Angle: " + pSettings.LandscapeAngle.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*4)); e.Graphics.DrawString("Maximum Copies: " + pSettings.MaximumCopies.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*5)); e.Graphics.DrawString("Maximum Page: " + pSettings.MaximumPage.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*6)); e.Graphics.DrawString("Minimum Page: " + pSettings.MinimumPage.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*7)); e.Graphics.DrawString("Supports Color: " + pSettings.SupportsColor.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*8)); nTextPosY = nTextPosY + ((5 + nHeight*8) + nHeight); //Draw line after each e.Graphics.DrawLine(System.Drawing.Pens.Black,nTextPosX,nTextPosY,e.MarginBounds.Right - 10,nTextPosY); e.Graphics.FillEllipse(System.Drawing.Brushes.Black,e.MarginBounds.Right - 10,nTextPosY-5,10,10); } else { //Could nto fit block on the page - need more pages m_nCurrPrinter = x; e.HasMorePages = true; return; } } } //Last page if we reached here e.HasMorePages = false; m_nCurrPrinter = 0; return; } private void btnPrint_Click(object sender, System.EventArgs e) { //Set to defaults m_nCurrPrinter = 0; m_nCurrPage = 1; oPrintDialog.Document = printDoc; if (oPrintDialog.ShowDialog() == DialogResult.OK) { try { ppDialog.Document = printDoc; ppDialog.ShowDialog(); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } } } } } [/csharp]

Printer Caps 4

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury,
Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using System.Drawing.Printing;
using System.Drawing.Drawing2D;

namespace PrinterCaps4
{
public class PrinterCaps4 : System.Windows.Forms.Form
{
private int m_nCurrPrinter;

private System.Drawing.Printing.PrintDocument printDoc;
private System.Windows.Forms.PrintPreviewDialog ppDialog;
private System.Windows.Forms.Button btnPrint;
private System.ComponentModel.Container components = null;

public PrinterCaps4()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
}

///

/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///

/// Required method for Designer support – do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
// System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(PrinterCaps4));
this.printDoc = new System.Drawing.Printing.PrintDocument();
this.ppDialog = new System.Windows.Forms.PrintPreviewDialog();
this.btnPrint = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// printDoc
//
this.printDoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDoc_PrintPage);
//
// ppDialog
//
this.ppDialog.AutoScrollMargin = new System.Drawing.Size(0, 0);
this.ppDialog.AutoScrollMinSize = new System.Drawing.Size(0, 0);
this.ppDialog.ClientSize = new System.Drawing.Size(400, 300);
this.ppDialog.Enabled = true;
// this.ppDialog.Icon = ((System.Drawing.Icon)(resources.GetObject(“ppDialog.Icon”)));
this.ppDialog.Location = new System.Drawing.Point(195, 22);
this.ppDialog.MaximumSize = new System.Drawing.Size(0, 0);
this.ppDialog.Name = “ppDialog”;
this.ppDialog.Opacity = 1;
this.ppDialog.TransparencyKey = System.Drawing.Color.Empty;
this.ppDialog.Visible = false;
//
// btnPrint
//
this.btnPrint.Location = new System.Drawing.Point(52, 28);
this.btnPrint.Name = “btnPrint”;
this.btnPrint.TabIndex = 0;
this.btnPrint.Text = “Print”;
this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
//
// PrinterCaps4
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(176, 86);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnPrint});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = “PrinterCaps4”;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = “Printer Caps”;
this.ResumeLayout(false);

}
#endregion

///

/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new PrinterCaps4());
}

private void printDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
PrinterSettings pSettings = new PrinterSettings();
Font printFont = new Font(“Arial”, 12);

//Use the Margins
int nTextPosY = e.MarginBounds.Top;
int nTextPosX = e.MarginBounds.Left;
int nHeight = (int)printFont.GetHeight(e.Graphics);

//Height of a printer block
int nBlockHeight = 9 * nHeight;

//Print Background Graphic
LinearGradientBrush aBrush =
new LinearGradientBrush(e.MarginBounds,Color.FromArgb(100,Color.LightBlue),
Color.FromArgb(100,Color.Blue),LinearGradientMode.ForwardDiagonal);
e.Graphics.FillRectangle(aBrush,e.MarginBounds);

//Loop through using indexor now
//Start with the previous index in m_nCurrPrinter
for(int x = m_nCurrPrinter;x< PrinterSettings.InstalledPrinters.Count; x++)//each(string sPtr in PrinterSettings.InstalledPrinters) { pSettings.PrinterName = PrinterSettings.InstalledPrinters[x]; if(pSettings.IsValid) { //Ensure this printer block can fit on the page if(nTextPosY + nBlockHeight < e.MarginBounds.Bottom) { //Print the caps of the printer e.Graphics.DrawString(PrinterSettings.InstalledPrinters[x], printFont,Brushes.Black, nTextPosX, nTextPosY + 5); e.Graphics.DrawString("Can Duplex: " + pSettings.CanDuplex.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight)); e.Graphics.DrawString("Is Default: " + pSettings.IsDefaultPrinter.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*2)); e.Graphics.DrawString("Is Plotter: " + pSettings.IsPlotter.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*3)); e.Graphics.DrawString("Landscape Angle: " + pSettings.LandscapeAngle.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*4)); e.Graphics.DrawString("Maximum Copies: " + pSettings.MaximumCopies.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*5)); e.Graphics.DrawString("Maximum Page: " + pSettings.MaximumPage.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*6)); e.Graphics.DrawString("Minimum Page: " + pSettings.MinimumPage.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*7)); e.Graphics.DrawString("Supports Color: " + pSettings.SupportsColor.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*8)); nTextPosY = nTextPosY + ((5 + nHeight*8) + nHeight); //Draw line after each e.Graphics.DrawLine(System.Drawing.Pens.Black,nTextPosX,nTextPosY,e.MarginBounds.Right - 10,nTextPosY); e.Graphics.FillEllipse(System.Drawing.Brushes.Black,e.MarginBounds.Right - 10,nTextPosY-5,10,10); } else { //Could nto fit block on the page - need more pages m_nCurrPrinter = x; e.HasMorePages = true; return; } } } //Last page if we reached here e.HasMorePages = false; m_nCurrPrinter = 0; return; } private void btnPrint_Click(object sender, System.EventArgs e) { //Set to defaults m_nCurrPrinter = 0; try { ppDialog.Document = printDoc; ppDialog.ShowDialog(); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } } } } [/csharp]

Printer Caps 3

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury,
Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using System.Drawing.Printing;

namespace PrinterCaps3
{
public class PrinterCaps3 : System.Windows.Forms.Form
{
private int m_nCurrPrinter;

private System.Drawing.Printing.PrintDocument printDoc;
private System.Windows.Forms.PrintPreviewDialog ppDialog;
private System.Windows.Forms.Button btnPrint;
private System.ComponentModel.Container components = null;

public PrinterCaps3()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
}

///

/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///

/// Required method for Designer support – do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
// System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(PrinterCaps3));
this.printDoc = new System.Drawing.Printing.PrintDocument();
this.ppDialog = new System.Windows.Forms.PrintPreviewDialog();
this.btnPrint = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// printDoc
//
this.printDoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDoc_PrintPage);
//
// ppDialog
//
this.ppDialog.AutoScrollMargin = new System.Drawing.Size(0, 0);
this.ppDialog.AutoScrollMinSize = new System.Drawing.Size(0, 0);
this.ppDialog.ClientSize = new System.Drawing.Size(400, 300);
this.ppDialog.Enabled = true;
// this.ppDialog.Icon = ((System.Drawing.Icon)(resources.GetObject(“ppDialog.Icon”)));
this.ppDialog.Location = new System.Drawing.Point(195, 22);
this.ppDialog.MaximumSize = new System.Drawing.Size(0, 0);
this.ppDialog.Name = “ppDialog”;
this.ppDialog.Opacity = 1;
this.ppDialog.TransparencyKey = System.Drawing.Color.Empty;
this.ppDialog.Visible = false;
//
// btnPrint
//
this.btnPrint.Location = new System.Drawing.Point(52, 28);
this.btnPrint.Name = “btnPrint”;
this.btnPrint.TabIndex = 0;
this.btnPrint.Text = “Print”;
this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
//
// PrinterCaps3
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(176, 86);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnPrint});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = “PrinterCaps3”;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = “Printer Caps”;
this.ResumeLayout(false);

}
#endregion

///

/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new PrinterCaps3());
}

private void printDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
PrinterSettings pSettings = new PrinterSettings();
Font printFont = new Font(“Arial”, 12);

//Use the Margins
int nTextPosY = e.MarginBounds.Top;
int nTextPosX = e.MarginBounds.Left;
int nHeight = (int)printFont.GetHeight(e.Graphics);

//Height of a printer block
int nBlockHeight = 9 * nHeight;

//Loop through using indexor now
//Start with the previous index in m_nCurrPrinter
for(int x = m_nCurrPrinter;x< PrinterSettings.InstalledPrinters.Count; x++)//each(string sPtr in PrinterSettings.InstalledPrinters) { pSettings.PrinterName = PrinterSettings.InstalledPrinters[x]; if(pSettings.IsValid) { //Ensure this printer block can fit on the page if(nTextPosY + nBlockHeight < e.MarginBounds.Bottom) { //Print the caps of the printer e.Graphics.DrawString(PrinterSettings.InstalledPrinters[x], printFont,Brushes.Black, nTextPosX, nTextPosY + 5); e.Graphics.DrawString("Can Duplex: " + pSettings.CanDuplex.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight)); e.Graphics.DrawString("Is Default: " + pSettings.IsDefaultPrinter.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*2)); e.Graphics.DrawString("Is Plotter: " + pSettings.IsPlotter.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*3)); e.Graphics.DrawString("Landscape Angle: " + pSettings.LandscapeAngle.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*4)); e.Graphics.DrawString("Maximum Copies: " + pSettings.MaximumCopies.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*5)); e.Graphics.DrawString("Maximum Page: " + pSettings.MaximumPage.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*6)); e.Graphics.DrawString("Minimum Page: " + pSettings.MinimumPage.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*7)); e.Graphics.DrawString("Supports Color: " + pSettings.SupportsColor.ToString(), printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*8)); nTextPosY = nTextPosY + ((5 + nHeight*8) + nHeight); } else { //Could nto fit block on the page - need more pages m_nCurrPrinter = x; e.HasMorePages = true; return; } } } //Last page if we reached here e.HasMorePages = false; m_nCurrPrinter = 0; return; } private void btnPrint_Click(object sender, System.EventArgs e) { //Set to defaults m_nCurrPrinter = 0; try { ppDialog.Document = printDoc; ppDialog.ShowDialog(); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } } } } [/csharp]

Printer Caps 2


   

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

//Need this namespace to access the Printing functionality
using System.Drawing.Printing;

namespace PrinterCaps2
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class PrinterCaps2 : System.Windows.Forms.Form
    {
        private System.Drawing.Printing.PrintDocument printDoc;
        private System.Windows.Forms.PrintPreviewDialog ppDialog;
        private System.Windows.Forms.Button btnPrint;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public PrinterCaps2()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
//          System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(PrinterCaps2));
            this.printDoc = new System.Drawing.Printing.PrintDocument();
            this.ppDialog = new System.Windows.Forms.PrintPreviewDialog();
            this.btnPrint = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // printDoc
            // 
            this.printDoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDoc_PrintPage);
            // 
            // ppDialog
            // 
            this.ppDialog.AutoScrollMargin = new System.Drawing.Size(0, 0);
            this.ppDialog.AutoScrollMinSize = new System.Drawing.Size(0, 0);
            this.ppDialog.ClientSize = new System.Drawing.Size(400, 300);
            this.ppDialog.Enabled = true;
//          this.ppDialog.Icon = ((System.Drawing.Icon)(resources.GetObject("ppDialog.Icon")));
            this.ppDialog.Location = new System.Drawing.Point(195, 22);
            this.ppDialog.MaximumSize = new System.Drawing.Size(0, 0);
            this.ppDialog.Name = "ppDialog";
            this.ppDialog.Opacity = 1;
            this.ppDialog.TransparencyKey = System.Drawing.Color.Empty;
            this.ppDialog.Visible = false;
            // 
            // btnPrint
            // 
            this.btnPrint.Location = new System.Drawing.Point(52, 28);
            this.btnPrint.Name = "btnPrint";
            this.btnPrint.TabIndex = 0;
            this.btnPrint.Text = "Print";
            this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
            // 
            // PrinterCaps2
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(176, 86);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.btnPrint});
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.Name = "PrinterCaps2";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Printer Caps";
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new PrinterCaps2());
        }

        private void printDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            PrinterSettings pSettings = new PrinterSettings();
            Font printFont = new Font("Arial", 12);
   
            //Use the Margins
            int nTextPosY = e.MarginBounds.Top;
            int nTextPosX = e.MarginBounds.Left;
            int nHeight = (int)printFont.GetHeight(e.Graphics);

            foreach(string sPtr in PrinterSettings.InstalledPrinters)
            {
                pSettings.PrinterName = sPtr;
                if(pSettings.IsValid)
                {
                    e.Graphics.DrawString(sPtr, printFont,Brushes.Black, nTextPosX, nTextPosY + 5);
                    e.Graphics.DrawString("Can Duplex: " + pSettings.CanDuplex.ToString(), 
                        printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight));
                    e.Graphics.DrawString("Is Default: " + pSettings.IsDefaultPrinter.ToString(), 
                        printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*2));
                    e.Graphics.DrawString("Is Plotter: " + pSettings.IsPlotter.ToString(), 
                        printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*3));
                    e.Graphics.DrawString("Landscape Angle: " + pSettings.LandscapeAngle.ToString(), 
                        printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*4));
                    e.Graphics.DrawString("Maximum Copies: " + pSettings.MaximumCopies.ToString(), 
                        printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*5));
                    e.Graphics.DrawString("Maximum Page: " + pSettings.MaximumPage.ToString(), 
                        printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*6));
                    e.Graphics.DrawString("Minimum Page: " + pSettings.MinimumPage.ToString(), 
                        printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*7));
                    e.Graphics.DrawString("Supports Color: " + pSettings.SupportsColor.ToString(), 
                        printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*8));
                    nTextPosY = nTextPosY + ((5 + nHeight*8) + nHeight);
                }

            }

        }


        private void btnPrint_Click(object sender, System.EventArgs e)
        {
            try
            {   
                ppDialog.Document = printDoc;
                ppDialog.ShowDialog();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}

           
          


Printer Caps 1

   

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/
using System.Drawing.Printing;

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

//Need Printing namespace
using System.Drawing.Printing;

namespace PrinterCaps1
{
    public class PrinterCaps1 : System.Windows.Forms.Form
    {

        private System.ComponentModel.Container components = null;

        public PrinterCaps1()
        {
            InitializeComponent();
        }

        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            // 
            // PrinterCaps1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Name = "PrinterCaps1";
            this.Text = "Printer Caps";
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.PrinterCaps1_Paint);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new PrinterCaps1());
        }


        private void PrinterCaps1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            PrinterSettings pSettings = new PrinterSettings();
            Font printFont = new Font("Arial", 10);
   
            //Position
            int nTextPosY = 0;
            int nTextPosX = 5;
            int nHeight = (int)printFont.GetHeight(e.Graphics);

            foreach(string sPtr in PrinterSettings.InstalledPrinters)
            {
                //pSettings.PrinterName = sPtr;
                pSettings.PrinterName = "BadName";
                //if(pSettings.IsValid)
                //{
                    e.Graphics.DrawString(sPtr, printFont,Brushes.Black, nTextPosX, nTextPosY + 5);
                    e.Graphics.DrawString("Can Duplex: " + pSettings.CanDuplex.ToString(), 
                        printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight));
                    e.Graphics.DrawString("Is Default: " + pSettings.IsDefaultPrinter.ToString(), 
                        printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*2));
                    e.Graphics.DrawString("Is Plotter: " + pSettings.IsPlotter.ToString(), 
                        printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*3));
                    e.Graphics.DrawString("Landscape Angle: " + pSettings.LandscapeAngle.ToString(), 
                        printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*4));
                    e.Graphics.DrawString("Maximum Copies: " + pSettings.MaximumCopies.ToString(), 
                        printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*5));
                    e.Graphics.DrawString("Maximum Page: " + pSettings.MaximumPage.ToString(), 
                        printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*6));
                    e.Graphics.DrawString("Minimum Page: " + pSettings.MinimumPage.ToString(), 
                        printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*7));
                    e.Graphics.DrawString("Supports Color: " + pSettings.SupportsColor.ToString(), 
                        printFont,Brushes.Black, nTextPosX + 10, nTextPosY + (5 + nHeight*8));
                    nTextPosY = nTextPosY + ((5 + nHeight*8) + nHeight);
                //}

            }

            return;
        }
    }
}