Margins.Top Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene o establece el ancho del margen superior, en centésimas de pulgada.
public:
property int Top { int get(); void set(int value); };
public int Top { get; set; }
member this.Top : int with get, set
Public Property Top As Integer
Valor de propiedad
El ancho del margen superior, en centésimas de pulgada.
Excepciones
La propiedad Top se establece en un valor menor que cero.
Ejemplos
Use los System.Drawingespacios de nombres , System.Drawing.Printingy System.IO para este ejemplo.
En el ejemplo de código siguiente se establece la configuración de página predeterminada para un documento en márgenes izquierdo y derecho de 1 pulgada de ancho, y los márgenes superior e inferior de 1,5 pulgadas de ancho.
void Printing()
{
try
{
/* This assumes that a variable of type string, named filePath,
has been set to the path of the file to print. */
streamToPrint = gcnew StreamReader( filePath );
try
{
printFont = gcnew System::Drawing::Font( "Arial",10 );
PrintDocument^ pd = gcnew PrintDocument;
/* This assumes that a method, named pd_PrintPage, has been
defined. pd_PrintPage handles the PrintPage event. */
pd->PrintPage += gcnew PrintPageEventHandler( this, &Sample::pd_PrintPage );
/* This assumes that a variable of type string, named
printer, has been set to the printer's name. */
pd->PrinterSettings->PrinterName = printer;
// Set the left and right margins to 1 inch.
pd->DefaultPageSettings->Margins->Left = 100;
pd->DefaultPageSettings->Margins->Right = 100;
// Set the top and bottom margins to 1.5 inches.
pd->DefaultPageSettings->Margins->Top = 150;
pd->DefaultPageSettings->Margins->Bottom = 150;
pd->Print();
}
finally
{
streamToPrint->Close();
}
}
catch ( Exception^ ex )
{
MessageBox::Show( String::Concat( "An error occurred printing the file - ", ex->Message ) );
}
}
public void Printing()
{
try
{
/* This assumes that a variable of type string, named filePath,
has been set to the path of the file to print. */
streamToPrint = new StreamReader (filePath);
try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
/* This assumes that a method, named pd_PrintPage, has been
defined. pd_PrintPage handles the PrintPage event. */
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
/* This assumes that a variable of type string, named
printer, has been set to the printer's name. */
pd.PrinterSettings.PrinterName = printer;
// Set the left and right margins to 1 inch.
pd.DefaultPageSettings.Margins.Left = 100;
pd.DefaultPageSettings.Margins.Right = 100;
// Set the top and bottom margins to 1.5 inches.
pd.DefaultPageSettings.Margins.Top = 150;
pd.DefaultPageSettings.Margins.Bottom = 150;
pd.Print();
}
finally
{
streamToPrint.Close() ;
}
}
catch(Exception ex)
{
MessageBox.Show("An error occurred printing the file - " + ex.Message);
}
}
Public Sub Printing()
Try
' This assumes that a variable of type string, named filePath,
' has been set to the path of the file to print.
streamToPrint = New StreamReader(filePath)
Try
printFont = New Font("Arial", 10)
Dim pd As New PrintDocument()
' This assumes that a method, named pd_PrintPage, has been
' defined. pd_PrintPage handles the PrintPage event.
AddHandler pd.PrintPage, AddressOf pd_PrintPage
' This assumes that a variable of type string, named
' printer, has been set to the printer's name.
pd.PrinterSettings.PrinterName = printer
' Set the left and right margins to 1 inch.
pd.DefaultPageSettings.Margins.Left = 100
pd.DefaultPageSettings.Margins.Right = 100
' Set the top and bottom margins to 1.5 inches.
pd.DefaultPageSettings.Margins.Top = 150
pd.DefaultPageSettings.Margins.Bottom = 150
pd.Print()
Finally
streamToPrint.Close()
End Try
Catch ex As Exception
MessageBox.Show("An error occurred printing the file - " & ex.Message)
End Try
End Sub
Comentarios
Si mide los márgenes en milímetros, multiplique el ancho de margen que desea en milímetros por 3,937 para determinar la medición correcta en centésimas de pulgada. Por ejemplo, si desea un margen de 25 mm, multiplique por 3,937 y el resultado es 98 cuando se redondea hacia abajo. A continuación, establecería el miembro adecuado Margins en 98.