Este tema aún no ha recibido ninguna valoración - Valorar este tema

PrintPreviewControl (Clase)

Actualización: noviembre 2007

Representa la parte de vista previa original de una vista previa de impresión de una aplicación de formularios Windows Forms, sin botones ni cuadros de diálogo. La mayoría de los objetos PrintPreviewControl se encuentran en los objetos PrintPreviewDialog, pero no necesariamente tiene que ser así.

Espacio de nombres:  System.Windows.Forms
Ensamblado:  System.Windows.Forms (en System.Windows.Forms.dll)
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
public class PrintPreviewControl : Control
/** @attribute ComVisibleAttribute(true) */
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */
public class PrintPreviewControl extends Control
public class PrintPreviewControl extends Control

Cuando se crea una instancia de la clase PrintPreviewControl, se establecen algunas propiedades de lectura y escritura en sus valores iniciales. Para obtener una lista de esos valores, vea el constructor PrintPreviewControl.

Para obtener más información acerca de cómo imprimir con formularios Windows Forms, vea la información general relacionada con el espacio de nombres System.Drawing.Printing. Si desea imprimir desde una aplicación de Windows Presentation Foundation, vea el espacio de nombres System.Printing.

En el ejemplo de código siguiente se muestran las propiedades Document, UseAntiAlias y Zoom del control PrintPreviewControl. Para ejecutar este ejemplo, coloque el código siguiente en un formulario y llame al método InitializePrintPreviewControl desde el constructor del formulario o desde el método de control de eventos de Load.


	// Declare the PrintPreviewControl object and the 
	// PrintDocument object.
	internal PrintPreviewControl PrintPreviewControl1;
	private System.Drawing.Printing.PrintDocument docToPrint = 
		new System.Drawing.Printing.PrintDocument();

	private void InitializePrintPreviewControl()
	{

		// Construct the PrintPreviewControl.
		this.PrintPreviewControl1 = new PrintPreviewControl();

		// Set location, name, and dock style for PrintPreviewControl1.
		this.PrintPreviewControl1.Location = new Point(88, 80);
		this.PrintPreviewControl1.Name = "PrintPreviewControl1";
		this.PrintPreviewControl1.Dock = DockStyle.Fill;

		// Set the Document property to the PrintDocument 
		// for which the PrintPage event has been handled.
		this.PrintPreviewControl1.Document = docToPrint;

		// Set the zoom to 25 percent.
		this.PrintPreviewControl1.Zoom = 0.25;

		// Set the document name. This will show be displayed when 
		// the document is loading into the control.
		this.PrintPreviewControl1.Document.DocumentName = "c:\\someFile";

		// Set the UseAntiAlias property to true so fonts are smoothed
		// by the operating system.
		this.PrintPreviewControl1.UseAntiAlias = true;

		// Add the control to the form.
		this.Controls.Add(this.PrintPreviewControl1);
		
		// Associate the event-handling method with the
		// document's PrintPage event.
		this.docToPrint.PrintPage += 
			new System.Drawing.Printing.PrintPageEventHandler(
			docToPrint_PrintPage);
	}

	// The PrintPreviewControl will display the document
	// by handling the documents PrintPage event
	private void docToPrint_PrintPage(
		object sender, System.Drawing.Printing.PrintPageEventArgs e)
	{

		// Insert code to render the page here.
		// This code will be called when the control is drawn.

		// The following code will render a simple
		// message on the document in the control.
		string text = "In docToPrint_PrintPage method.";
		System.Drawing.Font printFont = 
			new Font("Arial", 35, FontStyle.Regular);

		e.Graphics.DrawString(text, printFont,
			Brushes.Black, 10, 10);
	}


// Declare the PrintPreviewControl object and the 
// PrintDocument object.
PrintPreviewControl printPreviewControl1;
private System.Drawing.Printing.PrintDocument docToPrint =
    new System.Drawing.Printing.PrintDocument();

private void InitializePrintPreviewControl()
{
    // Construct the PrintPreviewControl.
    this.printPreviewControl1 = new PrintPreviewControl();
    // Set location, name, and dock style for PrintPreviewControl1.
    this.printPreviewControl1.set_Location(new Point(88, 80));
    this.printPreviewControl1.set_Name("PrintPreviewControl1");
    this.printPreviewControl1.set_Dock(DockStyle.Fill);
    // Set the Document property to the PrintDocument 
    // for which the PrintPage event has been handled.
    this.printPreviewControl1.set_Document(docToPrint);
    // Set the zoom to 25 percent.
    this.printPreviewControl1.set_Zoom(0.25);
    // Set the document name. This will show be displayed when 
    // the document is loading into the control.
    this.printPreviewControl1.get_Document().set_DocumentName("c:\\someFile");
    // Set the UseAntiAlias property to true so fonts are smoothed
    // by the operating system.
    this.printPreviewControl1.set_UseAntiAlias(true);
    // Add the control to the form.
    this.get_Controls().Add(this.printPreviewControl1);
    // Associate the event-handling method with the
    // document's PrintPage event.
    this.docToPrint.add_PrintPage(
        new System.Drawing.Printing.PrintPageEventHandler(
        docToPrint_PrintPage));
} //InitializePrintPreviewControl

// The PrintPreviewControl will display the document
// by handling the documents PrintPage event
private void docToPrint_PrintPage(Object sender,
    System.Drawing.Printing.PrintPageEventArgs e)
{
    // Insert code to render the page here.
    // This code will be called when the control is drawn.
    // The following code will render a simple
    // message on the document in the control.
    String text = "In docToPrint_PrintPage method.";
    System.Drawing.Font printFont = new Font("Arial", 35, FontStyle.Regular);

    e.get_Graphics().DrawString(text, printFont, Brushes.get_Black(), 10, 10);
} //docToPrint_PrintPage


System.Object
  System.MarshalByRefObject
    System.ComponentModel.Component
      System.Windows.Forms.Control
        System.Windows.Forms.PrintPreviewControl
Todos los miembros static (Shared en Visual Basic) públicos de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

.NET Framework

Compatible con: 3.5, 3.0, 2.0, 1.1, 1.0
¿Le ha resultado útil?
(Caracteres restantes: 1500)
Contenido de la comunidad Agregar