Margins.Top プロパティ
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
上部余白の幅 (1/100 インチ単位)。
解説
ミリメートル単位で余白を設定する場合は、設定するミリメートル単位の余白幅に 3.937 を掛けて 1/100 インチ単位の余白幅を割り出します。たとえば、余白を 25 mm に設定するときは、3.937 を掛けてから端数を切り捨てます。結果は 98 になります。次に、該当する Margins メンバを 98 に設定します。
この例では、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
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Weblioに収録されているすべての辞書からMargins.Top プロパティを検索する場合は、下記のリンクをクリックしてください。
全ての辞書からMargins.Top プロパティを検索
- Margins.Top プロパティのページへのリンク