SizeF 結構

定義

儲存已排序的浮點數值 (Floating-Point Number) 配對,通常是矩形的寬度和高度。

public value class SizeF : IEquatable<System::Drawing::SizeF>
public value class SizeF
[System.ComponentModel.TypeConverter("System.Drawing.SizeFConverter, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public struct SizeF : IEquatable<System.Drawing.SizeF>
public struct SizeF
public struct SizeF : IEquatable<System.Drawing.SizeF>
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public struct SizeF
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
[System.ComponentModel.TypeConverter(typeof(System.Drawing.SizeFConverter))]
public struct SizeF
[<System.ComponentModel.TypeConverter("System.Drawing.SizeFConverter, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
type SizeF = struct
type SizeF = struct
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type SizeF = struct
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.SizeFConverter))>]
type SizeF = struct
Public Structure SizeF
Implements IEquatable(Of SizeF)
Public Structure SizeF
繼承
屬性
實作

範例

下列程式碼範例會使用下列成員將陰影新增至 ListBox

此範例的設計目的是要與 Windows Form 搭配使用。 若要執行此範例,請將此程式碼貼到表單中,並在處理表單的事件 Paint 時呼叫 AddShadow 方法。 確認表單包含 ListBox 名為 listBox1 的 。

private:
   void AddShadow( PaintEventArgs^ e )
   {
      // Create two SizeF objects.
      SizeF shadowSize = listBox1->Size;
      SizeF addSize = SizeF(10.5F,20.8F);

      // Add them together and save the result in shadowSize.
      shadowSize = shadowSize + addSize;

      // Get the location of the ListBox and convert it to a PointF.
      PointF shadowLocation = listBox1->Location;

      // Add two points to get a new location.
      shadowLocation = shadowLocation + System::Drawing::Size( 5, 5 );

      // Create a rectangleF. 
      RectangleF rectFToFill = RectangleF(shadowLocation,shadowSize);

      // Create a custom brush using a semi-transparent color, and 
      // then fill in the rectangle.
      Color customColor = Color::FromArgb( 50, Color::Gray );
      SolidBrush^ shadowBrush = gcnew SolidBrush( customColor );
      array<RectangleF>^ temp0 = {rectFToFill};
      e->Graphics->FillRectangles( shadowBrush, temp0 );

      // Dispose of the brush.
      delete shadowBrush;
   }
private void AddShadow(PaintEventArgs e)
{

    // Create two SizeF objects.
    SizeF shadowSize = listBox1.Size;
    SizeF addSize = new SizeF(10.5F, 20.8F);

    // Add them together and save the result in shadowSize.
    shadowSize = shadowSize + addSize;

    // Get the location of the ListBox and convert it to a PointF.
    PointF shadowLocation = listBox1.Location;

    // Add two points to get a new location.
    shadowLocation = shadowLocation + new Size(5, 5);

    // Create a rectangleF. 
    RectangleF rectFToFill = 
        new RectangleF(shadowLocation, shadowSize);

    // Create a custom brush using a semi-transparent color, and 
    // then fill in the rectangle.
    Color customColor = Color.FromArgb(50, Color.Gray);
    SolidBrush shadowBrush = new SolidBrush(customColor);
    e.Graphics.FillRectangles(shadowBrush, new RectangleF[]{rectFToFill});

    // Dispose of the brush.
    shadowBrush.Dispose();
}
Private Sub AddShadow(ByVal e As PaintEventArgs)

    ' Create two SizeF objects.
    Dim shadowSize As SizeF = Size.op_Implicit(listBox1.Size)
    Dim addSize As New SizeF(10.5F, 20.8F)

    ' Add them together and save the result in shadowSize.
    shadowSize = SizeF.op_Addition(shadowSize, addSize)

    ' Get the location of the ListBox and convert it to a PointF.
    Dim shadowLocation As PointF = Point.op_Implicit(listBox1.Location)

    ' Add a Size to the Point to get a new location.
    shadowLocation = PointF.op_Addition(shadowLocation, New Size(5, 5))

    ' Create a rectangleF. 
    Dim rectFToFill As New RectangleF(shadowLocation, shadowSize)

    ' Create a custom brush using a semi-transparent color, and 
    ' then fill in the rectangle.
    Dim customColor As Color = Color.FromArgb(50, Color.Gray)
    Dim shadowBrush As SolidBrush = New SolidBrush(customColor)
    e.Graphics.FillRectangles(shadowBrush, _
        New RectangleF() {rectFToFill})

    ' Dispose of the brush.
    shadowBrush.Dispose()
End Sub

備註

結構的單位 SizeF 取決於 PageUnit 用來繪製之 Graphics 物件的 和 PageScale 設定。

建構函式

SizeF(PointF)

從指定的 SizeF 結構,初始化 PointF 結構的新執行個體。

SizeF(Single, Single)

從指定的維度,初始化 SizeF 結構的新執行個體。

SizeF(SizeF)

從現有的指定 SizeF 結構,初始化 SizeF 結構的新執行個體。

SizeF(Vector2)

從指定的 Vector2 ,初始化 結構的新實例 SizeF

欄位

Empty

取得 SizeFHeight 值為 0 的 Width 結構。

屬性

Height

取得或設定這個 SizeF 結構的垂直元件。

IsEmpty

取得值,指出這個 SizeF 結構是否具有零的寬度和高度。

Width

取得或設定這個 SizeF 結構的水平元件。

方法

Add(SizeF, SizeF)

將一個 SizeF 結構的寬度和高度加上另一個 SizeF 結構的寬度和高度。

Equals(Object)

測試指定的物件是否為和此 SizeF 結構具有相同維度的 SizeF 結構。

Equals(SizeF)

指出目前的物件是否等於另一個相同類型的物件。

GetHashCode()

傳回這個 Size 結構的雜湊程式碼。

Subtract(SizeF, SizeF)

將另一個 SizeF 結構的寬度和高度減去某一個 SizeF 結構的寬度和高度。

ToPointF()

SizeF 結構轉換成 PointF 結構。

ToSize()

SizeF 結構轉換成 Size 結構。

ToString()

建立表示這個 SizeF 結構之人類看得懂的字串。

ToVector2()

從這個 SizeF 建立新的 Vector2

運算子

Addition(SizeF, SizeF)

將一個 SizeF 結構的寬度和高度加上另一個 SizeF 結構的寬度和高度。

Division(SizeF, Single)

將指定的 SizeF 除以所指定單精確度浮點數。

Equality(SizeF, SizeF)

測試兩個 SizeF 結構是否相等。

Explicit(SizeF to PointF)

將指定的 SizeF 結構轉換成 PointF 結構。

Explicit(SizeF to Vector2)

將指定的 SizeF 轉換成 Vector2

Explicit(Vector2 to SizeF)

將指定的 Vector2 轉換成 SizeF

Inequality(SizeF, SizeF)

測試兩個 SizeF 結構是否不同。

Multiply(Single, SizeF)

將指定的單精確度浮點數乘以所指定 SizeF

Multiply(SizeF, Single)

將指定的 SizeF 乘以所指定單精確度浮點數。

Subtraction(SizeF, SizeF)

將另一個 SizeF 結構的寬度和高度減去某一個 SizeF 結構的寬度和高度。

適用於