Example 2 — Circle with Color and Border
A circle with a fill color and a colored border. Shows how to position a perfect circle using its center point (instead of a corner) and how to set a visible border.
Result
Code
/* PARAMS */
float cx = 200f; // center X
float cy = 200f; // center Y
float size = 150f; // diameter
var fill = System.Drawing.Color.FromArgb(52, 152, 219);
var line = System.Drawing.Color.FromArgb(41, 128, 185);
/* END PARAMS */
var oCircle = ppptools.AddOval(cx - size/2f, cy - size/2f, size, size);
oCircle.Name = "MyCircle";
oCircle.Fill.ForeColor.RGB =
System.Drawing.ColorTranslator.ToOle(fill);
oCircle.Fill.Transparency = 0f;
oCircle.Line.Weight = 2f;
oCircle.Line.ForeColor.RGB =
System.Drawing.ColorTranslator.ToOle(line);
Step-by-Step Explanation
1. Circle vs. Oval — msoShapeOval
PowerPoint has no dedicated "circle" type. msoShapeOval creates an oval. When width == height, the result is a perfect circle.
ppptools.AddOval(
cx - size/2f, cy - size/2f, // top-left corner
size, size); // width = height → circle
2. Center-Point Coordinates
AddShape expects the top-left corner (not the center point). To center a circle at (cx, cy), calculate:
left = cx - size/2
top = cy - size/2
Example: cx=200, cy=200, size=150 → left=125, top=125
This is a common pattern: shapes are often defined geometrically by their center, but PowerPoint needs the corner.
3. Border Color and Thickness
oCircle.Line.Weight = 2f; // thickness in PT
oCircle.Line.ForeColor.RGB =
System.Drawing.ColorTranslator.ToOle(line);
Unlike Example 1 (no border), here a visible border is set. Line.Weight is the thickness in points. Line.ForeColor.RGB is the border color — separate from Fill.ForeColor.
| Property | Meaning |
|---|---|
Line.Weight |
Border thickness in PT |
Line.ForeColor.RGB |
Border color (OLE format) |
Line.Visible |
msoTrue / msoFalse |
Fill.ForeColor.RGB |
Fill color (OLE format) |
Fill.Transparency |
0.0 (opaque) … 1.0 (transparent) |
What's Special About This Example
- No circle type —
msoShapeOvalwith equal width/height produces a perfect circle. - Center → corner conversion —
cx - size/2f/cy - size/2fis the standard pattern for all centered shapes. 2fnot2— float literal required sinceLine.Weightexpects afloat. Using2would be interpreted asintand trigger an implicit conversion.- Two separate colors: one for the fill (
fill), one for the border (line).
Back: Example 1 — Rectangle · Next: Example 3 — Union