共用方式為


PrintStringProperty 建構函式

定義

初始化 PrintStringProperty 類別的新執行個體。

多載

PrintStringProperty(String)

初始化所指定之屬性之 PrintStringProperty 類別的新執行個體。

PrintStringProperty(String, Object)

初始化指定屬性擁有指定值之 PrintStringProperty 類別的新執行個體。

PrintStringProperty(String)

初始化所指定之屬性之 PrintStringProperty 類別的新執行個體。

public:
 PrintStringProperty(System::String ^ attributeName);
public PrintStringProperty (string attributeName);
new System.Printing.IndexedProperties.PrintStringProperty : string -> System.Printing.IndexedProperties.PrintStringProperty
Public Sub New (attributeName As String)

參數

attributeName
String

String 表示之 PrintStringProperty 屬性的名稱。

備註

attributeName應該拼字與列印系統物件之某些特定String屬性的名稱完全相同,包括大小寫。 例如, Submitter 對象的 屬性 PrintSystemJobInfo 必須拼字為 “Submitter”,而不是 “submitter”。

適用於

PrintStringProperty(String, Object)

初始化指定屬性擁有指定值之 PrintStringProperty 類別的新執行個體。

public:
 PrintStringProperty(System::String ^ attributeName, System::Object ^ attributeValue);
public PrintStringProperty (string attributeName, object attributeValue);
new System.Printing.IndexedProperties.PrintStringProperty : string * obj -> System.Printing.IndexedProperties.PrintStringProperty
Public Sub New (attributeName As String, attributeValue As Object)

參數

attributeName
String

String 表示之 PrintStringProperty 屬性的名稱。

attributeValue
Object

PrintStringProperty 所表示屬性的值。

範例

下列範例示範如何使用這個建構函式來安裝第二部印表機,其屬性與現有印表機不同的位置、埠和共享狀態。

LocalPrintServer myLocalPrintServer = new LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer);
PrintQueue sourcePrintQueue = myLocalPrintServer.DefaultPrintQueue;
PrintPropertyDictionary myPrintProperties = sourcePrintQueue.PropertiesCollection;

// Share the new printer using Remove/Add methods
PrintBooleanProperty shared = new PrintBooleanProperty("IsShared", true);
myPrintProperties.Remove("IsShared");
myPrintProperties.Add("IsShared", shared);

// Give the new printer its share name using SetProperty method
PrintStringProperty theShareName = new PrintStringProperty("ShareName", "\"Son of " + sourcePrintQueue.Name +"\"");
myPrintProperties.SetProperty("ShareName", theShareName);

// Specify the physical location of the new printer using Remove/Add methods
PrintStringProperty theLocation = new PrintStringProperty("Location", "the supply room");
myPrintProperties.Remove("Location");
myPrintProperties.Add("Location", theLocation);

// Specify the port for the new printer
String[] port = new String[] { "COM1:" };

// Install the new printer on the local print server
PrintQueue clonedPrinter = myLocalPrintServer.InstallPrintQueue("My clone of " + sourcePrintQueue.Name, "Xerox WCP 35 PS", port, "WinPrint", myPrintProperties);
myLocalPrintServer.Commit();

// Report outcome
Console.WriteLine("{0} in {1} has been installed and shared as {2}", clonedPrinter.Name, clonedPrinter.Location, clonedPrinter.ShareName);
Console.WriteLine("Press Return to continue ...");
Console.ReadLine();
Dim myLocalPrintServer As New LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer)
Dim sourcePrintQueue As PrintQueue = myLocalPrintServer.DefaultPrintQueue
Dim myPrintProperties As PrintPropertyDictionary = sourcePrintQueue.PropertiesCollection

' Share the new printer using Remove/Add methods
Dim [shared] As New PrintBooleanProperty("IsShared", True)
myPrintProperties.Remove("IsShared")
myPrintProperties.Add("IsShared", [shared])

' Give the new printer its share name using SetProperty method
Dim theShareName As New PrintStringProperty("ShareName", """Son of " & sourcePrintQueue.Name & """")
myPrintProperties.SetProperty("ShareName", theShareName)

' Specify the physical location of the new printer using Remove/Add methods
Dim theLocation As New PrintStringProperty("Location", "the supply room")
myPrintProperties.Remove("Location")
myPrintProperties.Add("Location", theLocation)

' Specify the port for the new printer
Dim port() As String = { "COM1:" }


' Install the new printer on the local print server
Dim clonedPrinter As PrintQueue = myLocalPrintServer.InstallPrintQueue("My clone of " & sourcePrintQueue.Name, "Xerox WCP 35 PS", port, "WinPrint", myPrintProperties)
myLocalPrintServer.Commit()

' Report outcome
Console.WriteLine("{0} in {1} has been installed and shared as {2}", clonedPrinter.Name, clonedPrinter.Location, clonedPrinter.ShareName)
Console.WriteLine("Press Return to continue ...")
Console.ReadLine()

備註

attributeName應該拼字與列印系統物件之某些特定String屬性的名稱完全相同,包括大小寫。 例如, Submitter 對象的 屬性 PrintSystemJobInfo 必須拼字為 “Submitter”,而不是 “submitter”。

適用於