LinearGradientBrush LinearGradientBrush LinearGradientBrush LinearGradientBrush Class

定义

使用线性渐变封装 BrushEncapsulates a Brush with a linear gradient. 此类不能被继承。This class cannot be inherited.

public ref class LinearGradientBrush sealed : System::Drawing::Brush
public sealed class LinearGradientBrush : System.Drawing.Brush
type LinearGradientBrush = class
    inherit Brush
Public NotInheritable Class LinearGradientBrush
Inherits Brush
继承
LinearGradientBrushLinearGradientBrushLinearGradientBrushLinearGradientBrush

示例

下面的示例创建一个水平LinearGradientBrush; 当您从0的水平坐标移动到水平坐标为200时, 颜色组件会线性变化。The following example creates a horizontal LinearGradientBrush; the color components change linearly as you move from a horizontal coordinate of 0 to a horizontal coordinate of 200. 例如, 第一个坐标为介于0到200之间的点, 其蓝色分量为介于0到255之间。For example, a point whose first coordinate is halfway between 0 and 200 will have a blue component that is halfway between 0 and 255. 此示例旨在与 Windows 窗体一起使用。This example is designed for use with Windows Forms. 下面的代码示例旨在与 Windows 窗体一起使用, 并且它需要PaintEventArgs e(是的参数PaintEventHandler)。The following code example is designed for use with Windows Forms, and it requires the PaintEventArgse, which is a parameter of PaintEventHandler.

public void UseHorizontalLinearGradients(PaintEventArgs e)
{
    LinearGradientBrush linGrBrush = new LinearGradientBrush(
       new Point(0, 10),
       new Point(200, 10),
       Color.FromArgb(255, 255, 0, 0),   // Opaque red
       Color.FromArgb(255, 0, 0, 255));  // Opaque blue

    Pen pen = new Pen(linGrBrush);

    e.Graphics.DrawLine(pen, 0, 10, 200, 10);
    e.Graphics.FillEllipse(linGrBrush, 0, 30, 200, 100);
    e.Graphics.FillRectangle(linGrBrush, 0, 155, 500, 30);
}
Dim linGrBrush As New LinearGradientBrush( _
   New Point(0, 10), _
   New Point(200, 10), _
   Color.FromArgb(255, 255, 0, 0), _
   Color.FromArgb(255, 0, 0, 255))
Dim pen As New Pen(linGrBrush)

e.Graphics.DrawLine(pen, 0, 10, 200, 10)
e.Graphics.FillEllipse(linGrBrush, 0, 30, 200, 100)
e.Graphics.FillRectangle(linGrBrush, 0, 155, 500, 30)

注解

此类封装双色渐变和自定义多色渐变。This class encapsulates both two-color gradients and custom multicolor gradients.

所有线性渐变按照矩形的宽度或两个点指定的直线定义。All linear gradients are defined along a line specified either by the width of a rectangle or by two points.

默认情况下, 双色线性渐变是沿指定直线从起始色到结束颜色的水平线性混合。By default, a two-color linear gradient is an even horizontal linear blend from the starting color to the ending color along the specified line. 使用BlendSetBlendTriangularShape 、方法或方法自定义混合模式。 SetSigmaBellShapeCustomize the blend pattern using the Blend class, the SetSigmaBellShape methods, or the SetBlendTriangularShape methods. 通过在构造函数中指定LinearGradientMode枚举或角度, 自定义渐变的方向。Customize the direction of the gradient by specifying the LinearGradientMode enumeration or the angle in the constructor.

InterpolationColors使用属性创建多色渐变。Use the InterpolationColors property to create a multicolor gradient.

Transform属性指定应用到渐变的局部几何转换。The Transform property specifies a local geometric transform applied to the gradient.

构造函数

LinearGradientBrush(Point, Point, Color, Color) LinearGradientBrush(Point, Point, Color, Color) LinearGradientBrush(Point, Point, Color, Color) LinearGradientBrush(Point, Point, Color, Color)

使用指定的点和颜色初始化 LinearGradientBrush 类的新实例。Initializes a new instance of the LinearGradientBrush class with the specified points and colors.

LinearGradientBrush(PointF, PointF, Color, Color) LinearGradientBrush(PointF, PointF, Color, Color) LinearGradientBrush(PointF, PointF, Color, Color) LinearGradientBrush(PointF, PointF, Color, Color)

使用指定的点和颜色初始化 LinearGradientBrush 类的新实例。Initializes a new instance of the LinearGradientBrush class with the specified points and colors.

LinearGradientBrush(Rectangle, Color, Color, LinearGradientMode) LinearGradientBrush(Rectangle, Color, Color, LinearGradientMode) LinearGradientBrush(Rectangle, Color, Color, LinearGradientMode) LinearGradientBrush(Rectangle, Color, Color, LinearGradientMode)

根据一个矩形、起始颜色和结束颜色以及方向,创建 LinearGradientBrush 类的新实例。Creates a new instance of the LinearGradientBrush class based on a rectangle, starting and ending colors, and orientation.

LinearGradientBrush(Rectangle, Color, Color, Single) LinearGradientBrush(Rectangle, Color, Color, Single) LinearGradientBrush(Rectangle, Color, Color, Single) LinearGradientBrush(Rectangle, Color, Color, Single)

根据一个矩形、起始颜色和结束颜色以及方向角度,创建 LinearGradientBrush 类的新实例。Creates a new instance of the LinearGradientBrush class based on a rectangle, starting and ending colors, and an orientation angle.

LinearGradientBrush(Rectangle, Color, Color, Single, Boolean) LinearGradientBrush(Rectangle, Color, Color, Single, Boolean) LinearGradientBrush(Rectangle, Color, Color, Single, Boolean) LinearGradientBrush(Rectangle, Color, Color, Single, Boolean)

根据一个矩形、起始颜色和结束颜色以及方向角度,创建 LinearGradientBrush 类的新实例。Creates a new instance of the LinearGradientBrush class based on a rectangle, starting and ending colors, and an orientation angle.

LinearGradientBrush(RectangleF, Color, Color, LinearGradientMode) LinearGradientBrush(RectangleF, Color, Color, LinearGradientMode) LinearGradientBrush(RectangleF, Color, Color, LinearGradientMode) LinearGradientBrush(RectangleF, Color, Color, LinearGradientMode)

根据一个矩形、起始颜色和结束颜色以及方向模式,创建 LinearGradientBrush 类的新实例。Creates a new instance of the LinearGradientBrush based on a rectangle, starting and ending colors, and an orientation mode.

LinearGradientBrush(RectangleF, Color, Color, Single) LinearGradientBrush(RectangleF, Color, Color, Single) LinearGradientBrush(RectangleF, Color, Color, Single) LinearGradientBrush(RectangleF, Color, Color, Single)

根据一个矩形、起始颜色和结束颜色以及方向角度,创建 LinearGradientBrush 类的新实例。Creates a new instance of the LinearGradientBrush class based on a rectangle, starting and ending colors, and an orientation angle.

LinearGradientBrush(RectangleF, Color, Color, Single, Boolean) LinearGradientBrush(RectangleF, Color, Color, Single, Boolean) LinearGradientBrush(RectangleF, Color, Color, Single, Boolean) LinearGradientBrush(RectangleF, Color, Color, Single, Boolean)

根据一个矩形、起始颜色和结束颜色以及方向角度,创建 LinearGradientBrush 类的新实例。Creates a new instance of the LinearGradientBrush class based on a rectangle, starting and ending colors, and an orientation angle.

属性

Blend Blend Blend Blend

获取或设置一个 Blend,它指定定义渐变自定义过渡的位置和因素。Gets or sets a Blend that specifies positions and factors that define a custom falloff for the gradient.

GammaCorrection GammaCorrection GammaCorrection GammaCorrection

获取或设置一个值,该值指示是否为该 LinearGradientBrush 启用灰度校正。Gets or sets a value indicating whether gamma correction is enabled for this LinearGradientBrush.

InterpolationColors InterpolationColors InterpolationColors InterpolationColors

获取或设置一个定义多色线性渐变的 ColorBlendGets or sets a ColorBlend that defines a multicolor linear gradient.

LinearColors LinearColors LinearColors LinearColors

获取或设置渐变的起始色和结束色。Gets or sets the starting and ending colors of the gradient.

Rectangle Rectangle Rectangle Rectangle

获取定义渐变的起点和终点的矩形区域。Gets a rectangular region that defines the starting and ending points of the gradient.

Transform Transform Transform Transform

获取或设置一个副本 Matrix,它定义此 LinearGradientBrush 的局部几何转换。Gets or sets a copy Matrix that defines a local geometric transform for this LinearGradientBrush.

WrapMode WrapMode WrapMode WrapMode

获取或设置 WrapMode 枚举,它指示该 LinearGradientBrush 的环绕模式。Gets or sets a WrapMode enumeration that indicates the wrap mode for this LinearGradientBrush.

方法

Clone() Clone() Clone() Clone()

创建此 LinearGradientBrush 的一个精确副本。Creates an exact copy of this LinearGradientBrush.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()

释放由此 Brush 对象使用的所有资源。Releases all resources used by this Brush object.

(Inherited from Brush)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

释放由 Brush 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the Brush and optionally releases the managed resources.

(Inherited from Brush)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
MultiplyTransform(Matrix) MultiplyTransform(Matrix) MultiplyTransform(Matrix) MultiplyTransform(Matrix)

通过预先计算指定的 Matrix,将表示此 LinearGradientBrush 的局部几何转换的 Matrix 与指定的 Matrix 相乘。Multiplies the Matrix that represents the local geometric transform of this LinearGradientBrush by the specified Matrix by prepending the specified Matrix.

MultiplyTransform(Matrix, MatrixOrder) MultiplyTransform(Matrix, MatrixOrder) MultiplyTransform(Matrix, MatrixOrder) MultiplyTransform(Matrix, MatrixOrder)

按指定的顺序,将表示此 LinearGradientBrush 的局部几何转换的 Matrix 与指定的 Matrix 相乘。Multiplies the Matrix that represents the local geometric transform of this LinearGradientBrush by the specified Matrix in the specified order.

ResetTransform() ResetTransform() ResetTransform() ResetTransform()

Transform 属性重置为标识。Resets the Transform property to identity.

RotateTransform(Single) RotateTransform(Single) RotateTransform(Single) RotateTransform(Single)

将局部几何转换旋转指定大小。Rotates the local geometric transform by the specified amount. 此方法预先计算对转换的旋转。This method prepends the rotation to the transform.

RotateTransform(Single, MatrixOrder) RotateTransform(Single, MatrixOrder) RotateTransform(Single, MatrixOrder) RotateTransform(Single, MatrixOrder)

将局部几何转换以指定顺序旋转指定量。Rotates the local geometric transform by the specified amount in the specified order.

ScaleTransform(Single, Single) ScaleTransform(Single, Single) ScaleTransform(Single, Single) ScaleTransform(Single, Single)

将局部几何转换缩放指定的量。Scales the local geometric transform by the specified amounts. 此方法预先计算转换的缩放矩阵。This method prepends the scaling matrix to the transform.

ScaleTransform(Single, Single, MatrixOrder) ScaleTransform(Single, Single, MatrixOrder) ScaleTransform(Single, Single, MatrixOrder) ScaleTransform(Single, Single, MatrixOrder)

将局部几何转换以指定顺序缩放指定的量。Scales the local geometric transform by the specified amounts in the specified order.

SetBlendTriangularShape(Single) SetBlendTriangularShape(Single) SetBlendTriangularShape(Single) SetBlendTriangularShape(Single)

创建一个从中心色向两端单一颜色线性过渡的线性渐变过程。Creates a linear gradient with a center color and a linear falloff to a single color on both ends.

SetBlendTriangularShape(Single, Single) SetBlendTriangularShape(Single, Single) SetBlendTriangularShape(Single, Single) SetBlendTriangularShape(Single, Single)

创建一个从中心色向两端单一颜色线性过渡的线性渐变过程。Creates a linear gradient with a center color and a linear falloff to a single color on both ends.

SetNativeBrush(IntPtr) SetNativeBrush(IntPtr) SetNativeBrush(IntPtr) SetNativeBrush(IntPtr)

在派生类中,设置对 GDI+GDI+ 画笔对象的引用。In a derived class, sets a reference to a GDI+GDI+ brush object.

(Inherited from Brush)
SetSigmaBellShape(Single) SetSigmaBellShape(Single) SetSigmaBellShape(Single) SetSigmaBellShape(Single)

创建基于钟形曲线的渐变过渡过程。Creates a gradient falloff based on a bell-shaped curve.

SetSigmaBellShape(Single, Single) SetSigmaBellShape(Single, Single) SetSigmaBellShape(Single, Single) SetSigmaBellShape(Single, Single)

创建基于钟形曲线的渐变过渡过程。Creates a gradient falloff based on a bell-shaped curve.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)
TranslateTransform(Single, Single) TranslateTransform(Single, Single) TranslateTransform(Single, Single) TranslateTransform(Single, Single)

将局部几何转换平移指定的尺寸。Translates the local geometric transform by the specified dimensions. 该方法将预先计算对转换的平移。This method prepends the translation to the transform.

TranslateTransform(Single, Single, MatrixOrder) TranslateTransform(Single, Single, MatrixOrder) TranslateTransform(Single, Single, MatrixOrder) TranslateTransform(Single, Single, MatrixOrder)

按指定的顺序将局部几何转换平移指定的尺寸。Translates the local geometric transform by the specified dimensions in the specified order.

适用于

另请参阅