The PaperSize class has four properties: Height, Kind, PaperName, and Width.Height, Width and PaperName have both get and set access. The Height and Width properties are used to get and set the paper's height and width, respectively, in hundredths of an inch. The PaperName property is used to get and set the name of the type of paper, but it can be used only when the Kind property is set to Custom. The Kind property returns the type of paper.
We can construct custom paper size using the PaperSize clas. Listing 11.12 reads the PaperSize properties.
LISTING 11.12: Reading PaperSize properties
PrinterSettings ps = new PrinterSettings();
Console.WriteLine("Paper Sizes");
foreach (PaperSize psize in ps.PaperSizes)
{
string str1 = psize.Kind.ToString();
string str2 = psize.PaperName.ToString();
string str3 = psize.Height.ToString();
string str4 = psize.Width.ToString();
}
The PaperSource Class
The PaperSource class specifies the paper tray from which the printer retrieves the paper for the current printing task. This class is used by PritnerSettings through its PaperSoruces property to get and set the paper source trays that a re available on the printer. The PaperSize class has two properties: Kind and SourceName. The Kind property returns an enumerated value for the paper source, and SoruceName returns the name of the paper source as a string.
Listing 11.13 reads all the paper sources and displays them in a message box.
LISTING 11.13: Reading paper sources
PrinterSettings ps = new PrinterSettings();
foreach (PaperSource p in ps.PaperSources)
{
MessageBox.Show(p.SourceName);
}
The PrinterResolutionKind Enumeration
The PrinterResolutionKind enumeration specifies a printer resolution, as described in Table 11.3. This enumeration is used by the PrinterResolution, PrinterSettings, and PageSettings classes.
PrinterSettings Collection Classes
Besides the PrinterSetting class, the System.Drawing.Printing namespace provides three PrinterSettings collection classes. These collection classes provide members to count total items in a collection, and to add item to and remove items from a collection. The classes are:
-
PrinterSettings.PaperSizeCollection. A printer may support different kinds of papers, including papers of different sizes. This class returns a collection including all paper sizes supported by the printer. PaperSizeCollection contains PaperSizes objects.
-
PrinterSettings.PaperSourceCollection. A printer may support different paper sources (trays). This class represents a collection of paper sources (trays) provided by a printer. PaperSourceCollection is available via the PaperSoruces property and contains PaperSource objects.
-
PrinterSettings.PrinterResolution.Collection. A printer may support different resolutions. This class represents a collection of resolutions supported by a printer. PrinterResolutionsCollection is accessible via the PrinterResoultions property and contains PrinterResoultion objects.
TABLE 11.3: PrinterResolutionKind members
|
Member |
Description |
|
Custom |
Custom resolution |
|
Draft |
Draft-quality resolution |
|
High |
High resolution |
|
Low |
Low resolution |
|
Medium |
Medium resolution |
All these collection classes provide Count and Item properties. The Count property returns the total number of items in a collection, and the Item property returns the item at the specified index. We will use these classes in our samples.
Conclusion
Hope the article would have helped you in understanding the PaperSize Class in GDI+. Read other articles on GDI+ on the website.
 |
This book teaches .NET developers how to work with GDI+ as they develop applications that include graphics, or that interact with monitors or printers. It begins by explaining the difference between GDI and GDI+, and covering the basic concepts of graphics programming in Windows. |
Join the conversation! Your thoughts help the community grow.