PageSettings.PaperSize Свойство
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Получает или задает размер бумаги для страницы.
public:
property System::Drawing::Printing::PaperSize ^ PaperSize { System::Drawing::Printing::PaperSize ^ get(); void set(System::Drawing::Printing::PaperSize ^ value); };
public System.Drawing.Printing.PaperSize PaperSize { get; set; }
member this.PaperSize : System.Drawing.Printing.PaperSize with get, set
Public Property PaperSize As PaperSize
Значение свойства
PaperSize, представляющий размер бумаги. Размер бумаги по умолчанию устанавливается в соответствии с настройками принтера.
Исключения
Принтер, указанный в свойстве PrinterName, отсутствует или не установлен принтер по умолчанию.
Примеры
В следующем примере кода задаются три свойства для страницы документа по умолчанию, включая размер бумаги на основе размера, выбранного comboPaperSize
в поле со списком, а затем выполняется печать документа с помощью Print метода . В этом примере требуется, чтобы существует переменная PrintDocument с именем printDoc
и существовали определенные поля со списком.
// Add list of supported paper sizes found on the printer.
// The DisplayMember property is used to identify the property that will provide the display String*.
comboPaperSize->DisplayMember = "PaperName";
PaperSize^ pkSize;
for ( int i = 0; i < printDoc->PrinterSettings->PaperSizes->Count; i++ )
{
pkSize = printDoc->PrinterSettings->PaperSizes[ i ];
comboPaperSize->Items->Add( pkSize );
}
// Create a PaperSize and specify the custom paper size through the constructor and add to combobox.
PaperSize^ pkCustomSize1 = gcnew PaperSize( "First custom size",100,200 );
comboPaperSize->Items->Add( pkCustomSize1 );
// Add list of supported paper sizes found on the printer.
// The DisplayMember property is used to identify the property that will provide the display string.
comboPaperSize.DisplayMember = "PaperName";
PaperSize pkSize;
for (int i = 0; i < printDoc.PrinterSettings.PaperSizes.Count; i++){
pkSize = printDoc.PrinterSettings.PaperSizes[i];
comboPaperSize.Items.Add(pkSize);
}
// Create a PaperSize and specify the custom paper size through the constructor and add to combobox.
PaperSize pkCustomSize1 = new PaperSize("First custom size", 100, 200);
comboPaperSize.Items.Add(pkCustomSize1);
' Add list of supported paper sizes found on the printer.
' The DisplayMember property is used to identify the property that will provide the display string.
comboPaperSize.DisplayMember = "PaperName"
Dim pkSize As PaperSize
For i = 0 to printDoc.PrinterSettings.PaperSizes.Count - 1
pkSize = printDoc.PrinterSettings.PaperSizes.Item(i)
comboPaperSize.Items.Add(pkSize)
Next
' Create a PaperSize and specify the custom paper size through the constructor and add to combobox.
Dim pkCustomSize1 As New PaperSize("Custom Paper Size", 100, 200)
comboPaperSize.Items.Add(pkCustomSize1)
// Add list of paper sources found on the printer to the combo box.
// The DisplayMember property is used to identify the property that will provide the display String*.
comboPaperSource->DisplayMember = "SourceName";
PaperSource^ pkSource;
for ( int i = 0; i < printDoc->PrinterSettings->PaperSources->Count; i++ )
{
pkSource = printDoc->PrinterSettings->PaperSources[ i ];
comboPaperSource->Items->Add( pkSource );
}
// Add list of paper sources found on the printer to the combo box.
// The DisplayMember property is used to identify the property that will provide the display string.
comboPaperSource.DisplayMember="SourceName";
PaperSource pkSource;
for (int i = 0; i < printDoc.PrinterSettings.PaperSources.Count; i++){
pkSource = printDoc.PrinterSettings.PaperSources[i];
comboPaperSource.Items.Add(pkSource);
}
' Add list of paper sources found on the printer to the combo box.
' The DisplayMember property is used to identify the property that will provide the display string.
comboPaperSource.DisplayMember = "SourceName"
Dim pkSource As PaperSource
For i = 0 to printDoc.PrinterSettings.PaperSources.Count - 1
pkSource = printDoc.PrinterSettings.PaperSources.Item(i)
comboPaperSource.Items.Add(pkSource)
Next
// Add list of printer resolutions found on the printer to the combobox.
// The PrinterResolution's ToString() method will be used to provide the display String.
PrinterResolution^ pkResolution;
for ( int i = 0; i < printDoc->PrinterSettings->PrinterResolutions->Count; i++ )
{
pkResolution = printDoc->PrinterSettings->PrinterResolutions[ i ];
comboPrintResolution->Items->Add( pkResolution );
}
// Add list of printer resolutions found on the printer to the combobox.
// The PrinterResolution's ToString() method will be used to provide the display string.
PrinterResolution pkResolution;
for (int i = 0; i < printDoc.PrinterSettings.PrinterResolutions.Count; i++){
pkResolution = printDoc.PrinterSettings.PrinterResolutions[i];
comboPrintResolution.Items.Add(pkResolution);
}
' Add list of printer resolutions found on the printer to the combobox.
' The PrinterResolution's ToString() method will be used to provide the display string.
Dim pkResolution As PrinterResolution
For i = 0 to printDoc.PrinterSettings.PrinterResolutions.Count - 1
pkResolution = printDoc.PrinterSettings.PrinterResolutions.Item(i)
comboPrintResolution.Items.Add(pkResolution)
Next
private:
void MyButtonPrint_Click( Object^ sender, System::EventArgs^ e )
{
// Set the paper size based upon the selection in the combo box.
if ( comboPaperSize->SelectedIndex != -1 )
{
printDoc->DefaultPageSettings->PaperSize = printDoc->PrinterSettings->PaperSizes[ comboPaperSize->SelectedIndex ];
}
// Set the paper source based upon the selection in the combo box.
if ( comboPaperSource->SelectedIndex != -1 )
{
printDoc->DefaultPageSettings->PaperSource = printDoc->PrinterSettings->PaperSources[ comboPaperSource->SelectedIndex ];
}
// Set the printer resolution based upon the selection in the combo box.
if ( comboPrintResolution->SelectedIndex != -1 )
{
printDoc->DefaultPageSettings->PrinterResolution = printDoc->PrinterSettings->PrinterResolutions[ comboPrintResolution->SelectedIndex ];
}
// Print the document with the specified paper size, source, and print resolution.
printDoc->Print();
}
private void MyButtonPrint_Click(object sender, System.EventArgs e)
{
// Set the paper size based upon the selection in the combo box.
if (comboPaperSize.SelectedIndex != -1) {
printDoc.DefaultPageSettings.PaperSize =
printDoc.PrinterSettings.PaperSizes[comboPaperSize.SelectedIndex];
}
// Set the paper source based upon the selection in the combo box.
if (comboPaperSource.SelectedIndex != -1) {
printDoc.DefaultPageSettings.PaperSource =
printDoc.PrinterSettings.PaperSources[comboPaperSource.SelectedIndex];
}
// Set the printer resolution based upon the selection in the combo box.
if (comboPrintResolution.SelectedIndex != -1)
{
printDoc.DefaultPageSettings.PrinterResolution=
printDoc.PrinterSettings.PrinterResolutions[comboPrintResolution.SelectedIndex];
}
// Print the document with the specified paper size, source, and print resolution.
printDoc.Print();
}
Private Sub MyButtonPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyButtonPrint.Click
' Set the paper size based upon the selection in the combo box.
If comboPaperSize.SelectedIndex <> -1 Then
printDoc.DefaultPageSettings.PaperSize = _
printDoc.PrinterSettings.PaperSizes.Item(comboPaperSize.SelectedIndex)
End If
' Set the paper source based upon the selection in the combo box.
If comboPaperSource.SelectedIndex <> -1 Then
printDoc.DefaultPageSettings.PaperSource = _
printDoc.PrinterSettings.PaperSources.Item(comboPaperSource.SelectedIndex)
End If
' Set the printer resolution based upon the selection in the combo box.
If comboPrintResolution.SelectedIndex <> -1 Then
printDoc.DefaultPageSettings.PrinterResolution = _
printDoc.PrinterSettings.PrinterResolutions.Item(comboPrintResolution.SelectedIndex)
End If
' Print the document with the specified paper size and source.
printDoc.Print()
End Sub
Комментарии
Представляет PaperSize размер бумаги с помощью PaperSize.Kind свойства , которое содержит одно из значений PaperKind .
PaperSize Задайте для свойства страницы допустимое PaperSizeзначение , доступное через коллекцию PrinterSettings.PaperSizes .
Сведения о том, как можно указать пользовательский размер бумаги, см. в конструкторе PaperSize .