Example 4 — Square with Hole (Combine)
A circle is punched out of a square — Combine creates the hole. The result is a shape with a true geometric cutout that remains transparent even over colored backgrounds.
Result
Code
/* PARAMS */
float left = 120f;
float top = 100f;
float size = 180f;
var color = System.Drawing.Color.FromArgb(39, 174, 96);
/* END PARAMS */
int fillRgb = System.Drawing.ColorTranslator.ToOle(color);
int lineRgb = System.Drawing.ColorTranslator.ToOle(
System.Drawing.Color.FromArgb(27, 120, 67));
float cx = left + size / 2f;
float cy = top + size / 2f;
float hole = size * 0.35f;
// Square
var oSquare = ppptools.AddRect(left, top, size, size);
// Hole circle (centered in square)
var oHole = ppptools.AddOval(cx - hole/2f, cy - hole/2f, hole, hole);
// Combine — circle is punched out of the square
oSquare.Select(MsoTriState.msoTrue);
oHole.Select(MsoTriState.msoFalse);
ppptools.Combine();
foreach (dynamic sh in ppptools.GetSelectedRange())
{
sh.Name = "SquareWithHole";
sh.Fill.ForeColor.RGB = fillRgb;
sh.Fill.Transparency = 0f;
sh.Line.ForeColor.RGB = lineRgb;
sh.Line.Weight = 1.5f;
}
Step-by-Step Explanation
1. Pre-computing Colors and Dimensions
int fillRgb = System.Drawing.ColorTranslator.ToOle(color);
int lineRgb = System.Drawing.ColorTranslator.ToOle(
System.Drawing.Color.FromArgb(27, 120, 67));
float cx = left + size / 2f;
float cy = top + size / 2f;
float hole = size * 0.35f;
All derived values are stored as local variables before creating any shapes. This is cleaner than nesting calculations inside method calls.
cx/cy— center of the square (for centering the hole)hole = size * 0.35f— hole diameter = 35% of the square's size
2. Creating the Square
var oSquare = ppptools.AddRect(left, top, size, size);
width == height → perfect square (same principle as the circle in Example 2).
3. Creating and Centering the Hole Circle
var oHole = ppptools.AddOval(cx - hole/2f, cy - hole/2f, hole, hole);
The hole circle sits exactly at the center of the square. The center-point pattern from Example 2 is reused: cx - hole/2f.
4. The Combine Operation — How It Differs from Union
oSquare.Select(MsoTriState.msoTrue);
oHole.Select(MsoTriState.msoFalse);
ppptools.Combine();
Combine works like Union, except: areas where the shapes overlap are punched out (become transparent). The result is a shape with a true geometric hole.
| Operation | Overlapping Area |
|---|---|
Union |
stays filled |
Combine |
becomes a hole (transparent) |
Intersect |
only the overlap remains |
Subtract |
overlap is removed from the first shape |
Selection Order Matters
With Combine, the shape selected first (msoTrue) determines the style.
Both shapes participate in the cutout — but the first shape "wins" for styling.
5. Styling the Result Shape
foreach (dynamic sh in ppptools.GetSelectedRange())
{
sh.Name = "SquareWithHole";
sh.Fill.ForeColor.RGB = fillRgb;
sh.Fill.Transparency = 0f;
sh.Line.ForeColor.RGB = lineRgb;
sh.Line.Weight = 1.5f;
}
The hole is not noticeable when the slide background is white. Over a colored background or image, the true cutout becomes visible.
What's Special About This Example
- Combine ≠ Union — same syntax, but overlapping areas become holes, not solid fill.
- True geometric hole — not a white circle on top, but a real transparent cutout in the shape geometry. Verify it: change the slide background color → the hole reveals the background.
lineRgbdefined directly — the darker border color (27, 120, 67) is a manually darkened shade of the fill color (39, 174, 96).Line.Weight = 1.5f— a thin border that makes the hole outline visible.
Back: Example 3 — Union · Next: Example 5 — Gear Wheel