Margins.Left Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene o imposta la larghezza del margine sinistro, in centesimi di pollice.
public:
property int Left { int get(); void set(int value); };
public int Left { get; set; }
member this.Left : int with get, set
Public Property Left As Integer
Valore della proprietà
Larghezza del margine sinistro, in centesimi di pollice.
Eccezioni
La proprietà Left è impostata su un valore minore di 0.
Esempio
Usare gli System.Drawingspazi dei nomi , System.Drawing.Printinge System.IO per questo esempio.
Nell'esempio di codice seguente vengono impostate le impostazioni di pagina predefinite per un documento a sinistra e a destra dei margini di larghezza di 1 pollice e dei margini superiore e inferiore di 1,5 pollici in larghezza.
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
Commenti
Se si misurano margini in millimetri, moltiplicare la larghezza del margine desiderata in millimetri per 3,937 per determinare la misura corretta in centesimi di pollice. Ad esempio, se si vuole un margine di 25mm, moltiplicare per 3,937 e il risultato è 98 quando arrotondato. Si imposta quindi il membro appropriato Margins su 98.