다음을 통해 공유


LocalPrintServer 생성자

정의

LocalPrintServer 클래스의 새 인스턴스를 초기화합니다.

오버로드

LocalPrintServer()

LocalPrintServer 클래스의 새 인스턴스를 초기화합니다.

LocalPrintServer(LocalPrintServerIndexedProperty[])

지정된 LocalPrintServer 배열이 포함된 LocalPrintServerIndexedProperty 클래스의 새 인스턴스를 초기화합니다.

LocalPrintServer(PrintSystemDesiredAccess)

지정된 LocalPrintServer를 갖는 PrintSystemDesiredAccess 클래스의 새 인스턴스를 초기화합니다.

LocalPrintServer(String[])

지정된 속성이 포함된 LocalPrintServer 클래스의 새 인스턴스를 초기화합니다.

LocalPrintServer(LocalPrintServerIndexedProperty[], PrintSystemDesiredAccess)

지정된 LocalPrintServer 배열 및 지정된 LocalPrintServerIndexedProperty를 갖는 PrintSystemDesiredAccess 클래스의 새 인스턴스를 초기화합니다.

LocalPrintServer(String[], PrintSystemDesiredAccess)

지정된 속성 및 LocalPrintServer를 갖는 PrintSystemDesiredAccess 클래스의 새 인스턴스를 초기화합니다.

LocalPrintServer()

LocalPrintServer 클래스의 새 인스턴스를 초기화합니다.

public:
 LocalPrintServer();
public LocalPrintServer ();
Public Sub New ()

예제

다음 예에서는 프린터의 기능을 테스트 하 고 활용 하는 인쇄 작업을 구성 하는 코드에서이 생성자를 사용 하는 방법을 보여 줍니다.

// ---------------------- GetPrintTicketFromPrinter -----------------------
/// <summary>
///   Returns a PrintTicket based on the current default printer.</summary>
/// <returns>
///   A PrintTicket for the current local default printer.</returns>
PrintTicket^ GetPrintTicketFromPrinter ()
{
   PrintQueue^ printQueue = nullptr;

   LocalPrintServer^ localPrintServer = gcnew LocalPrintServer();

   // Retrieving collection of local printer on user machine
   PrintQueueCollection^ localPrinterCollection = localPrintServer->GetPrintQueues();

   System::Collections::IEnumerator^ localPrinterEnumerator = localPrinterCollection->GetEnumerator();

   if (localPrinterEnumerator->MoveNext())
   {
      // Get PrintQueue from first available printer
      printQueue = ((PrintQueue^)localPrinterEnumerator->Current);
   } else
   {
      return nullptr;
   }
   // Get default PrintTicket from printer
   PrintTicket^ printTicket = printQueue->DefaultPrintTicket;

   PrintCapabilities^ printCapabilities = printQueue->GetPrintCapabilities();

   // Modify PrintTicket
   if (printCapabilities->CollationCapability->Contains(Collation::Collated))
   {
      printTicket->Collation = Collation::Collated;
   }
   if (printCapabilities->DuplexingCapability->Contains(Duplexing::TwoSidedLongEdge))
   {
      printTicket->Duplexing = Duplexing::TwoSidedLongEdge;
   }
   if (printCapabilities->StaplingCapability->Contains(Stapling::StapleDualLeft))
   {
      printTicket->Stapling = Stapling::StapleDualLeft;
   }
   return printTicket;
};// end:GetPrintTicketFromPrinter()
// ---------------------- GetPrintTicketFromPrinter -----------------------
/// <summary>
///   Returns a PrintTicket based on the current default printer.</summary>
/// <returns>
///   A PrintTicket for the current local default printer.</returns>
private PrintTicket GetPrintTicketFromPrinter()
{
    PrintQueue printQueue = null;

    LocalPrintServer localPrintServer = new LocalPrintServer();

    // Retrieving collection of local printer on user machine
    PrintQueueCollection localPrinterCollection =
        localPrintServer.GetPrintQueues();

    System.Collections.IEnumerator localPrinterEnumerator =
        localPrinterCollection.GetEnumerator();

    if (localPrinterEnumerator.MoveNext())
    {
        // Get PrintQueue from first available printer
        printQueue = (PrintQueue)localPrinterEnumerator.Current;
    }
    else
    {
        // No printer exist, return null PrintTicket
        return null;
    }

    // Get default PrintTicket from printer
    PrintTicket printTicket = printQueue.DefaultPrintTicket;

    PrintCapabilities printCapabilities = printQueue.GetPrintCapabilities();

    // Modify PrintTicket
    if (printCapabilities.CollationCapability.Contains(Collation.Collated))
    {
        printTicket.Collation = Collation.Collated;
    }

    if ( printCapabilities.DuplexingCapability.Contains(
            Duplexing.TwoSidedLongEdge) )
    {
        printTicket.Duplexing = Duplexing.TwoSidedLongEdge;
    }

    if (printCapabilities.StaplingCapability.Contains(Stapling.StapleDualLeft))
    {
        printTicket.Stapling = Stapling.StapleDualLeft;
    }

    return printTicket;
}// end:GetPrintTicketFromPrinter()
' ---------------------- GetPrintTicketFromPrinter -----------------------
''' <summary>
'''   Returns a PrintTicket based on the current default printer.</summary>
''' <returns>
'''   A PrintTicket for the current local default printer.</returns>
Private Function GetPrintTicketFromPrinter() As PrintTicket
    Dim printQueue As PrintQueue = Nothing

    Dim localPrintServer As New LocalPrintServer()

    ' Retrieving collection of local printer on user machine
    Dim localPrinterCollection As PrintQueueCollection = localPrintServer.GetPrintQueues()

    Dim localPrinterEnumerator As System.Collections.IEnumerator = localPrinterCollection.GetEnumerator()

    If localPrinterEnumerator.MoveNext() Then
        ' Get PrintQueue from first available printer
        printQueue = CType(localPrinterEnumerator.Current, PrintQueue)
    Else
        ' No printer exist, return null PrintTicket
        Return Nothing
    End If

    ' Get default PrintTicket from printer
    Dim printTicket As PrintTicket = printQueue.DefaultPrintTicket

    Dim printCapabilities As PrintCapabilities = printQueue.GetPrintCapabilities()

    ' Modify PrintTicket
    If printCapabilities.CollationCapability.Contains(Collation.Collated) Then
        printTicket.Collation = Collation.Collated
    End If

    If printCapabilities.DuplexingCapability.Contains(Duplexing.TwoSidedLongEdge) Then
        printTicket.Duplexing = Duplexing.TwoSidedLongEdge
    End If

    If printCapabilities.StaplingCapability.Contains(Stapling.StapleDualLeft) Then
        printTicket.Stapling = Stapling.StapleDualLeft
    End If

    Return printTicket
End Function ' end:GetPrintTicketFromPrinter()

적용 대상

LocalPrintServer(LocalPrintServerIndexedProperty[])

지정된 LocalPrintServer 배열이 포함된 LocalPrintServerIndexedProperty 클래스의 새 인스턴스를 초기화합니다.

public:
 LocalPrintServer(cli::array <System::Printing::LocalPrintServerIndexedProperty> ^ propertiesFilter);
public LocalPrintServer (System.Printing.LocalPrintServerIndexedProperty[] propertiesFilter);
new System.Printing.LocalPrintServer : System.Printing.LocalPrintServerIndexedProperty[] -> System.Printing.LocalPrintServer
Public Sub New (propertiesFilter As LocalPrintServerIndexedProperty())

매개 변수

propertiesFilter
LocalPrintServerIndexedProperty[]

생성자가 초기화하는 속성의 배열입니다.

적용 대상

LocalPrintServer(PrintSystemDesiredAccess)

지정된 LocalPrintServer를 갖는 PrintSystemDesiredAccess 클래스의 새 인스턴스를 초기화합니다.

public:
 LocalPrintServer(System::Printing::PrintSystemDesiredAccess desiredAccess);
public LocalPrintServer (System.Printing.PrintSystemDesiredAccess desiredAccess);
new System.Printing.LocalPrintServer : System.Printing.PrintSystemDesiredAccess -> System.Printing.LocalPrintServer
Public Sub New (desiredAccess As PrintSystemDesiredAccess)

매개 변수

desiredAccess
PrintSystemDesiredAccess

애플리케이션에 필요한 인쇄 서버 액세스 유형을 지정하는 값입니다.

예외

desiredAccessPrintQueue 개체가 아니라 LocalPrintServer 개체에만 적용될 수 있는 값인 경우(예: 예들 들어 UsePrinter입니다.

예제

다음 예제에서는 위치, 포트 및 공유 상태에만 기존 프린터에서 속성과 다른 두 번째 프린터를 설치 하는 코드에서이 생성자를 사용 하는 방법을 보여 줍니다.

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()

적용 대상

LocalPrintServer(String[])

지정된 속성이 포함된 LocalPrintServer 클래스의 새 인스턴스를 초기화합니다.

public:
 LocalPrintServer(cli::array <System::String ^> ^ propertiesFilter);
public LocalPrintServer (string[] propertiesFilter);
new System.Printing.LocalPrintServer : string[] -> System.Printing.LocalPrintServer
Public Sub New (propertiesFilter As String())

매개 변수

propertiesFilter
String[]

생성자가 초기화하는 속성 이름의 배열입니다.

적용 대상

LocalPrintServer(LocalPrintServerIndexedProperty[], PrintSystemDesiredAccess)

지정된 LocalPrintServer 배열 및 지정된 LocalPrintServerIndexedProperty를 갖는 PrintSystemDesiredAccess 클래스의 새 인스턴스를 초기화합니다.

public:
 LocalPrintServer(cli::array <System::Printing::LocalPrintServerIndexedProperty> ^ propertiesFilter, System::Printing::PrintSystemDesiredAccess desiredAccess);
public LocalPrintServer (System.Printing.LocalPrintServerIndexedProperty[] propertiesFilter, System.Printing.PrintSystemDesiredAccess desiredAccess);
new System.Printing.LocalPrintServer : System.Printing.LocalPrintServerIndexedProperty[] * System.Printing.PrintSystemDesiredAccess -> System.Printing.LocalPrintServer
Public Sub New (propertiesFilter As LocalPrintServerIndexedProperty(), desiredAccess As PrintSystemDesiredAccess)

매개 변수

propertiesFilter
LocalPrintServerIndexedProperty[]

생성자가 초기화하는 속성의 배열입니다.

desiredAccess
PrintSystemDesiredAccess

프로그램에 필요한 인쇄 서버 액세스 유형을 지정하는 값입니다.

예외

desiredAccessPrintQueue 개체가 아니라 LocalPrintServer 개체에만 적용될 수 있는 값인 경우(예: 예들 들어 UsePrinter입니다.

적용 대상

LocalPrintServer(String[], PrintSystemDesiredAccess)

지정된 속성 및 LocalPrintServer를 갖는 PrintSystemDesiredAccess 클래스의 새 인스턴스를 초기화합니다.

public:
 LocalPrintServer(cli::array <System::String ^> ^ propertiesFilter, System::Printing::PrintSystemDesiredAccess desiredAccess);
public LocalPrintServer (string[] propertiesFilter, System.Printing.PrintSystemDesiredAccess desiredAccess);
new System.Printing.LocalPrintServer : string[] * System.Printing.PrintSystemDesiredAccess -> System.Printing.LocalPrintServer
Public Sub New (propertiesFilter As String(), desiredAccess As PrintSystemDesiredAccess)

매개 변수

propertiesFilter
String[]

생성자가 초기화하는 속성 이름의 배열입니다.

desiredAccess
PrintSystemDesiredAccess

애플리케이션에 필요한 인쇄 서버 액세스 유형을 지정하는 값입니다.

예외

desiredAccessPrintQueue 개체가 아니라 LocalPrintServer 개체에만 적용될 수 있는 값인 경우(예: 예들 들어 UsePrinter입니다.

적용 대상