PathGradientBrush::GetCenterPoint (PointF*) 方法 (gdipluspath.h)

PathGradientBrush::GetCenterPoint 方法获取此路径渐变画笔的中心点。

语法

Status GetCenterPoint(
  PointF *point
);

parameters

point

指向接收中心点的 PointF 对象的指针。

返回值

Type:Status

如果方法成功,则返回 Ok,这是 Status 枚举的元素。

如果 方法失败,它将返回 Status 枚举的其他元素之一。

注解

默认情况下,PathGradientBrush 对象的中心点位于画笔边界路径的质心,但可以通过调用 PathGradientBrush 对象的 SetCenterPoint 方法,将中心点设置为路径内外的任何位置。

示例

以下示例演示 了 PathGradientBrush 类的几种方法,包括 PathGradientBrush::GetCenterPointPathGradientBrush::SetCenterColor。 代码创建 PathGradientBrush 对象,然后设置画笔的中心颜色和边界颜色。 该代码调用 PathGradientBrush::GetCenterPoint 方法来确定路径渐变的中心点,然后从原点到该中心点绘制一条线。

VOID Example_GetCenterPoint(HDC hdc)
{
   Graphics graphics(hdc);

   // Create a path that consists of a single ellipse.
   GraphicsPath path;
   path.AddEllipse(0, 0, 200, 100);

   // Use the path to construct a brush.
   PathGradientBrush pthGrBrush(&path);

   // Set the color at the center of the path to blue.
   pthGrBrush.SetCenterColor(Color(255, 0, 0, 255));

   // Set the color along the entire boundary of the path to aqua.
   Color colors[] = {Color(255, 0, 255, 255)};
   INT count = 1;
   pthGrBrush.SetSurroundColors(colors, &count);

   // Fill the ellipse with the path gradient brush.
   graphics.FillEllipse(&pthGrBrush, 0, 0, 200, 100);

   // Obtain information about the path gradient brush.
   PointF centerPoint;
   pthGrBrush.GetCenterPoint(&centerPoint);

   // Draw a line from the origin to the center of the ellipse.
   Pen pen(Color(255, 0, 255, 0));
   graphics.DrawLine(&pen, PointF(0, 0), centerPoint);  
}

要求

   
标头 gdipluspath.h

另请参阅

画笔和填充形状

颜色

创建路径渐变

使用颜色渐变填充形状

PathGradientBrush

PathGradientBrush::GetCenterColor

PathGradientBrush::SetCenterColor

PathGradientBrush::SetCenterPoint 方法