SizeF 构造函数

定义

根据指定的现有 SizeF 结构初始化 SizeF 结构的新实例。

重载

SizeF(PointF)

根据指定的 PointF 结构初始化 SizeF 结构的新实例。

SizeF(SizeF)

根据指定的现有 SizeF 结构初始化 SizeF 结构的新实例。

SizeF(Vector2)

从指定的 Vector2初始化 结构的新实例SizeF

SizeF(Single, Single)

根据指定的维度初始化 SizeF 结构的新实例。

SizeF(PointF)

Source:
SizeF.cs
Source:
SizeF.cs
Source:
SizeF.cs

根据指定的 PointF 结构初始化 SizeF 结构的新实例。

C#
public SizeF (System.Drawing.PointF pt);

参数

pt
PointF

初始化此 SizeF 结构所依据的 PointF 结构。

适用于

.NET 9 和其他版本
产品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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
.NET Standard 2.0, 2.1

SizeF(SizeF)

Source:
SizeF.cs
Source:
SizeF.cs
Source:
SizeF.cs

根据指定的现有 SizeF 结构初始化 SizeF 结构的新实例。

C#
public SizeF (System.Drawing.SizeF size);

参数

size
SizeF

要从其中创建新 SizeF 结构的 SizeF 结构。

适用于

.NET 9 和其他版本
产品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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
.NET Standard 2.0, 2.1

SizeF(Vector2)

Source:
SizeF.cs
Source:
SizeF.cs
Source:
SizeF.cs

从指定的 Vector2初始化 结构的新实例SizeF

C#
public SizeF (System.Numerics.Vector2 vector);

参数

vector
Vector2

源向量。

适用于

.NET 9 和其他版本
产品 版本
.NET 6, 7, 8, 9

SizeF(Single, Single)

Source:
SizeF.cs
Source:
SizeF.cs
Source:
SizeF.cs

根据指定的维度初始化 SizeF 结构的新实例。

C#
public SizeF (float width, float height);

参数

width
Single

SizeF 结构的宽度分量。

height
Single

SizeF 结构的高度分量。

示例

下面的代码示例使用以下成员将阴影添加到 :ListBox

此示例旨在与 Windows 窗体一起使用。 若要运行此示例,请将此代码粘贴到窗体中, AddShadow 并在处理窗体 Paint 的事件时调用 方法。 验证窗体是否包含 ListBox 名为 listBox1的 。

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

适用于

.NET 9 和其他版本
产品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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
.NET Standard 2.0, 2.1