Margins 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定列印的頁面之邊界的維度。
public ref class Margins : ICloneable
public class Margins : ICloneable
[System.ComponentModel.TypeConverter("System.Drawing.Printing.MarginsConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")]
public class Margins : ICloneable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.Printing.MarginsConverter))]
public class Margins : ICloneable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.Printing.MarginsConverter))]
[System.Serializable]
public class Margins : ICloneable
type Margins = class
interface ICloneable
[<System.ComponentModel.TypeConverter("System.Drawing.Printing.MarginsConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")>]
type Margins = class
interface ICloneable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.Printing.MarginsConverter))>]
type Margins = class
interface ICloneable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.Printing.MarginsConverter))>]
[<System.Serializable>]
type Margins = class
interface ICloneable
Public Class Margins
Implements ICloneable
- 繼承
-
Margins
- 屬性
- 實作
範例
針對此範例, System.Drawing請使用、 System.Drawing.Printing和 System.IO 命名空間。
下列程式代碼範例會將文件的預設頁面設定設為每一邊 1 英吋的邊界。
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
備註
類別Margins是用來操作和PrintController中PageSettings邊界的寬度。 MarginsConverter 是這個類別的類型描述項。
Left、 Right、 Top和 Bottom 是定義邊界的屬性。 Clone 會建立相同的 Margins。 Equals 判斷另一個物件是否具有與 相同的維度 Margins。
如需列印的詳細資訊,請參閱 System.Drawing.Printing 命名空間概觀。
建構函式
Margins() |
使用 1 英吋寬的邊界來初始化 Margins 類別的新執行個體。 |
Margins(Int32, Int32, Int32, Int32) |
使用指定的左、右、上方、下方邊界來初始化 Margins 類別的新執行個體。 |
屬性
Bottom |
取得或設定以百分之一英吋為單位的下方邊界。 |
Left |
取得或設定左邊界寬度 (以百分之一英吋為單位)。 |
Right |
取得或設定右邊界寬度 (以百分之一英吋為單位)。 |
Top |
取得或設定上方邊界寬度 (以百分之一英吋為單位)。 |
方法
Clone() |
依成員擷取這個物件的複本。 |
Equals(Object) | |
GetHashCode() |
計算和擷取基於左邊界、右邊界、上方邊界和下方邊界之寬度的雜湊程式碼。 |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
將 Margins 轉換成字串。 |
運算子
Equality(Margins, Margins) |
比較兩個 Margins,以判斷它們是否具有相同維度。 |
Inequality(Margins, Margins) |
比較兩個 Margins,以判斷它們是否為不相等的寬度。 |