Margins.Top プロパティとは? わかりやすく解説

Margins.Top プロパティ

上部余白の幅を 1/100 インチ単位取得または設定します

名前空間: System.Drawing.Printing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

例外例外
例外種類条件

ArgumentException

Top プロパティは、0 未満の値が設定されています。

解説解説
使用例使用例

この例では、System.Drawing、System.Drawing.Printing、および System.IO の各名前空間使用します

ドキュメント既定ページ設定として、左右余白の幅を 1 インチ上下余白の幅を 1.5 インチ設定するコード例次に示します

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

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.add_PrintPage(new PrintPageEventHandler(pd_PrintPage));

            /* This assumes that a variable of type string, named
 
               printer, has been set to the printer's name.
             */
            pd.get_PrinterSettings().set_PrinterName(printer);

            // Set the left and right margins to 1 inch.
            pd.get_DefaultPageSettings().get_Margins().set_Left(100);
            pd.get_DefaultPageSettings().get_Margins().set_Right(100);

            // Set the top and bottom margins to 1.5 inches.
            pd.get_DefaultPageSettings().get_Margins().set_Top(150);
            pd.get_DefaultPageSettings().get_Margins().set_Bottom(150);
            pd.Print();
        }
        finally {
            streamToPrint.Close();
        }
    }
    catch (System.Exception ex) {
        MessageBox.Show(("An error occurred printing the file - " 
            + ex.get_Message()));
    }
} //Printing
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Margins クラス
Margins メンバ
System.Drawing.Printing 名前空間
Margins.Left プロパティ
Margins.Right プロパティ
Margins.Bottom プロパティ


このページでは「.NET Framework クラス ライブラリ リファレンス」からMargins.Top プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からMargins.Top プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からMargins.Top プロパティを検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Margins.Top プロパティ」の関連用語

Margins.Top プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Margins.Top プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS