mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-04 09:06:04 +02:00
* Reset branch for WPF changes * Convert BMP to PNG; fix link-out-of-scope err * Add snippets for WPF... 6794 files!!!! * Add missing snippets * update file updated between migration * Fix paths to include * update breadcrumb and toc * fix index links * fix index links * fix index links * fix markdown
61 lines
4.3 KiB
Markdown
61 lines
4.3 KiB
Markdown
---
|
|
title: "How to: Clone a Printer"
|
|
ms.date: "03/30/2017"
|
|
dev_langs:
|
|
- "csharp"
|
|
- "vb"
|
|
helpviewer_keywords:
|
|
- "print queues [WPF]"
|
|
- "cloning printers [WPF]"
|
|
- "printers [WPF], cloning"
|
|
- "print queues [WPF], cloning"
|
|
- "cloning print queues [WPF]"
|
|
ms.assetid: dd6997c9-fe04-40f8-88a6-92e3ac0889eb
|
|
---
|
|
# How to: Clone a Printer
|
|
Most businesses will, at some point, buy multiple printers of the same model. Typically, these are all installed with virtually identical configuration settings. Installing each printer can be time-consuming and error prone. The <xref:System.Printing.IndexedProperties?displayProperty=nameWithType> namespace and the <xref:System.Printing.PrintServer.InstallPrintQueue%2A> class that are exposed with Microsoft .NET Framework makes it possible to instantly install any number of additional print queues that are cloned from an existing print queue.
|
|
|
|
## Example
|
|
In the example below, a second print queue is cloned from an existing print queue. The second differs from the first only in its name, location, port, and shared status. The major steps for doing this are as follows.
|
|
|
|
1. Create a <xref:System.Printing.PrintQueue> object for the existing printer that is going to be cloned.
|
|
|
|
2. Create a <xref:System.Printing.IndexedProperties.PrintPropertyDictionary> from the <xref:System.Printing.PrintSystemObject.PropertiesCollection%2A> of the <xref:System.Printing.PrintQueue>. The <xref:System.Collections.DictionaryEntry.Value%2A> property of each entry in this dictionary is an object of one of the types derived from <xref:System.Printing.IndexedProperties.PrintProperty>. There are two ways to set the value of an entry in this dictionary.
|
|
|
|
- Use the dictionary's **Remove** and <xref:System.Printing.IndexedProperties.PrintPropertyDictionary.Add%2A> methods to remove the entry and then re-add it with the desired value.
|
|
|
|
- Use the dictionary's <xref:System.Printing.IndexedProperties.PrintPropertyDictionary.SetProperty%2A> method.
|
|
|
|
The example below illustrates both ways.
|
|
|
|
3. Create a <xref:System.Printing.IndexedProperties.PrintBooleanProperty> object and set its <xref:System.Printing.IndexedProperties.PrintProperty.Name%2A> to "IsShared" and its <xref:System.Printing.IndexedProperties.PrintBooleanProperty.Value%2A> to `true`.
|
|
|
|
4. Use the <xref:System.Printing.IndexedProperties.PrintBooleanProperty> object to be the value of the <xref:System.Printing.IndexedProperties.PrintPropertyDictionary>'s "IsShared" entry.
|
|
|
|
5. Create a <xref:System.Printing.IndexedProperties.PrintStringProperty> object and set its <xref:System.Printing.IndexedProperties.PrintProperty.Name%2A> to "ShareName" and its <xref:System.Printing.IndexedProperties.PrintStringProperty.Value%2A> to an appropriate <xref:System.String>.
|
|
|
|
6. Use the <xref:System.Printing.IndexedProperties.PrintStringProperty> object to be the value of the <xref:System.Printing.IndexedProperties.PrintPropertyDictionary>'s "ShareName" entry.
|
|
|
|
7. Create another <xref:System.Printing.IndexedProperties.PrintStringProperty> object and set its <xref:System.Printing.IndexedProperties.PrintProperty.Name%2A> to "Location" and its <xref:System.Printing.IndexedProperties.PrintStringProperty.Value%2A> to an appropriate <xref:System.String>.
|
|
|
|
8. Use the second <xref:System.Printing.IndexedProperties.PrintStringProperty> object to be the value of the <xref:System.Printing.IndexedProperties.PrintPropertyDictionary>'s "Location" entry.
|
|
|
|
9. Create an array of <xref:System.String>s. Each item is the name of a port on the server.
|
|
|
|
10. Use <xref:System.Printing.PrintServer.InstallPrintQueue%2A> to install the new printer with the new values.
|
|
|
|
An example is below.
|
|
|
|
[!code-csharp[ClonePrinter#ClonePrinter](~/samples/snippets/csharp/VS_Snippets_Wpf/ClonePrinter/CSharp/Program.cs#cloneprinter)]
|
|
[!code-vb[ClonePrinter#ClonePrinter](~/samples/snippets/visualbasic/VS_Snippets_Wpf/ClonePrinter/visualbasic/program.vb#cloneprinter)]
|
|
|
|
## See also
|
|
|
|
- <xref:System.Printing.IndexedProperties>
|
|
- <xref:System.Printing.IndexedProperties.PrintPropertyDictionary>
|
|
- <xref:System.Printing.LocalPrintServer>
|
|
- <xref:System.Printing.PrintQueue>
|
|
- <xref:System.Collections.DictionaryEntry>
|
|
- [Documents in WPF](documents-in-wpf.md)
|
|
- [Printing Overview](printing-overview.md)
|