The CircleShape Property

This topic presents general information on:

CircleShape Property Functionality

When the CircleShape property's value is set to TRUE, the Circle control draws the largest possible perfect circle centered within the bounding rectangle of the control. When the CircleShape property is set to FALSE, the Circle control draws an ellipse whose major and minor axes touch the bounding rectangle of the control. The initial value of the CircleShape property should be TRUE. Whenever the CircleShape property is changed, the Circle control is redrawn to reflect the change.

The figure below shows the Circle control drawn as an ellipse, the desired effect when CircleShape is set to FALSE. Notice that the ellipse is drawn to the edges of the bounding rectangle. This is the standard drawing behavior of the Circle control, so very little code is modified to implement the required drawing behavior when CircleShape is set to FALSE.

The CircleShape Property Set to FALSE

When the CircleShape property is set to TRUE, the Circle control is drawn as a perfect circle. The following figure shows how the circle would be drawn within the bounding rectangle of the control. To determine how to draw the circle, you will calculate the square region centered within the bounding rectangle of the control.

The CircleShape Property Set to TRUE

Recall from the previous lesson that the CCircCtrl::OnDraw function used the CDC::Ellipse function to draw the ellipse. This function can also be used to draw the circle. By passing the calculated square region instead of the bounding rectangle of the control to the Ellipse function, the Ellipse function will draw a perfect circle.

Implementing the CircleShape Property

Now that the CircleShape property's functional specification is complete, and the basic logic is described, you can revise the Circle control's code as follows:

Aspects of this strategy apply whenever you add any custom property. Using ClassWizard to add the property greatly simplifies the process by updating the appropriate class and the object definition library (.ODL) files (which are used to create the type library). It is always good practice to provide a default value for the new property by adding initialization code for the property to the DoPropExchange member function in the control class.