Margins.Left Właściwość

Definicja

Pobiera lub ustawia szerokość lewego marginesu w setkach cala.

C#
public int Left { get; set; }

Wartość właściwości

Szerokość lewego marginesu w setkach cala.

Wyjątki

Właściwość Left jest ustawiona na wartość mniejszą niż 0.

Przykłady

W tym przykładzie System.Drawingużyj przestrzeni nazw , System.Drawing.Printingi System.IO .

Poniższy przykład kodu ustawia domyślne ustawienia strony dokumentu na lewy i prawy margines 1 cala szerokości, a górny i dolny margines 1,5 cala szerokości.

C#
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);
  }
}

Uwagi

Jeśli mierzysz marginesy w milimetrach, pomnóż szerokość marginesu, która ma być w milimetrach o 3,937, aby określić prawidłową miarę w setkach cala. Jeśli na przykład chcesz użyć marginesu 25mm, pomnóż wartość 3,937, a wynik to 98 po zaokrągleniu w dół. Następnie należy ustawić odpowiedni element członkowski Margins na 98.

Dotyczy

Produkt Wersje
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Zobacz też