Margins Constructeurs
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Initialise une nouvelle instance de la classe Margins.
Surcharges
Margins() |
Initialise une nouvelle instance de la classe Margins avec des marges de 1 pouce de large. |
Margins(Int32, Int32, Int32, Int32) |
Initialise une nouvelle instance de la classe Margins avec les marges gauche, droite, haute et basse spécifiées. |
Margins()
- Source:
- Margins.cs
- Source:
- Margins.cs
- Source:
- Margins.cs
Initialise une nouvelle instance de la classe Margins avec des marges de 1 pouce de large.
public:
Margins();
public Margins ();
Public Sub New ()
S’applique à
Margins(Int32, Int32, Int32, Int32)
- Source:
- Margins.cs
- Source:
- Margins.cs
- Source:
- Margins.cs
Initialise une nouvelle instance de la classe Margins avec les marges gauche, droite, haute et basse spécifiées.
public:
Margins(int left, int right, int top, int bottom);
public Margins (int left, int right, int top, int bottom);
new System.Drawing.Printing.Margins : int * int * int * int -> System.Drawing.Printing.Margins
Public Sub New (left As Integer, right As Integer, top As Integer, bottom As Integer)
Paramètres
- left
- Int32
Marge gauche, en centièmes de pouce.
- right
- Int32
Marge droite, en centièmes de pouce.
- top
- Int32
Marge haute, en centièmes de pouce.
- bottom
- Int32
Marge basse, en centièmes de pouce.
Exceptions
La valeur du paramètre left
est inférieure à 0.
- ou -
La valeur du paramètre right
est inférieure à 0.
- ou -
La valeur du paramètre top
est inférieure à 0.
- ou -
La valeur du paramètre bottom
est inférieure à 0.
Exemples
Utilisez les System.Drawingespaces de noms , System.Drawing.Printinget System.IO pour cet exemple.
L’exemple de code suivant définit les paramètres de page par défaut d’un document sur des marges de 1 pouce de largeur de chaque côté.
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;
// Create a new instance of Margins with one inch margins.
Margins^ margins = gcnew Margins( 100,100,100,100 );
pd->DefaultPageSettings->Margins = margins;
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;
// Create a new instance of Margins with one inch margins.
Margins margins = new Margins(100,100,100,100);
pd.DefaultPageSettings.Margins = margins;
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
' Create a new instance of Margins with one inch margins.
Dim margins As New Margins(100, 100, 100, 100)
pd.DefaultPageSettings.Margins = margins
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