Share via


DrawRectangle Method

Draws a rectangle on a chart. Uses the current settings of the Border and Interior properties to determine the properties of the new rectangle.

expression.DrawRectangle(Left, Top, Right, Bottom)

*expression   * Required. An expression that returns a ChChartDraw object.

Left   Required Long. Pixel coordinate of the left edge of the rectangle.

Top   Required Long. Pixel coordinate of the top edge of the rectangle.

Right   Required Long. Pixel coordinate of the right edge of the rectangle.

Bottom   Required Long. Pixel coordinate of the bottom edge of the rectangle.

Example

This example uses the AfterRender event to draw rectangles as a substitute for the legend entries in the first chart of Chartspace1.

Sub ChartSpace1_AfterRender(drawObject, chartObject)

    Dim chConstants

    Set chConstants = ChartSpace1.Constants

    If TypeName(chartObject) = "ChLegendEntry" Then

        ' Set the interior of the rectangle to a preset texture.
        ' You could substitute a URL to a custom graphic
        ' for the texture.
        drawObject.Interior.SetTextured chConstants.chTextureSand

        ' Begin drawing the rectangle.
        drawObject.BeginObject 1

        ' Draw the rectangle.
        drawObject.DrawRectangle chartObject.Left, chartObject.Top, _
                                 chartObject.Right, chartObject.Bottom

        drawObject.EndObject

    End If

End Sub

Applies to | ChChartDraw Object

See Also | AfterRender Event | BeforeRender Event | Border Property | DrawEllipse Method | DrawLine Method | DrawPolygon Method | DrawPolyLine Method | DrawText Method | Interior Property