HandsOn Writing the Form AfterRender Event Procedure

1. In the Visual Basic Editor window, double-click Form_Sales Analysis Subform 2.

2. The Code window shows the procedures created in the previous hands-on exercises for this chapter. Enter the following Form_AfterRender event procedure below the last procedure code.

Private Sub Form_AfterRender(ByVal drawObject As Object, _

ByVal chartObject As Object)

Dim oChart As Object

Set oChart = Me.ChartSpace.Charts.Item(0)

If TypeName(chartObject) = "ChLegend" Then drawObject.DrawText "Chart legend has been rendered", _ oChart.PlotArea.Left + 15, _ oChart.PlotArea.Top

End If End Sub

The DrawText method is used to draw a text string on a chart. This method uses the following syntax:

expression.DrawText(bstrText, Left, Top)

The expression returns a chChartDraw object. All arguments are required. The bstrText argument is a string specifying the text to draw on the chart. Left is a pixel coordinate of the left edge of the text. Top is a pixel coordinate of the top edge of the text.

3. Switch to the Sales Analysis Subform 2 form and choose View | PivotChart View. When the form opens you should see the text "Chart legend has been rendered" in the chart's plot area.

Event Programming in Forms and Reports

0 0

Post a comment