Overview
ReoGrid supports adding drawing shapes — rectangles, ellipses, lines, diamonds, rounded rectangles, pie shapes, and more — directly onto a worksheet. Shapes are managed through the worksheet.FloatingObjects collection and belong to the unvell.ReoGrid.Drawing.Shapes namespace.
using unvell.ReoGrid.Drawing;
using unvell.ReoGrid.Drawing.Shapes;
Adding a Shape to a Worksheet
Create a shape instance, configure its position and size, then add it to FloatingObjects.
var worksheet = grid.CurrentWorksheet;
var rect = new RectangleShape()
{
Location = new Graphics.Point(60, 90),
Size = new Graphics.Size(160, 80),
Text = "Hello ReoGrid",
};
worksheet.FloatingObjects.Add(rect);
All shapes share the same Location / Size / Bounds positioning API inherited from DrawingObject.
Available Shape Types
Rectangle
var rect = new RectangleShape()
{
Location = new Graphics.Point(60, 90),
Size = new Graphics.Size(160, 80),
};
worksheet.FloatingObjects.Add(rect);
Ellipse
var ellipse = new EllipseShape()
{
Location = new Graphics.Point(60, 90),
Size = new Graphics.Size(120, 80),
};
worksheet.FloatingObjects.Add(ellipse);
Diamond
var diamond = new DiamondShape()
{
Location = new Graphics.Point(60, 90),
Size = new Graphics.Size(120, 80),
};
worksheet.FloatingObjects.Add(diamond);
Rounded Rectangle
Use RoundRate (0.0 – 1.0) to control the corner radius relative to the shorter side.
var rounded = new RoundedRectangleShape()
{
Location = new Graphics.Point(60, 90),
Size = new Graphics.Size(160, 80),
RoundRate = 0.3f,
};
worksheet.FloatingObjects.Add(rounded);
Pie
var pie = new PieShape()
{
Location = new Graphics.Point(60, 90),
Size = new Graphics.Size(120, 120),
StartAngle = 0f,
SweepAngle = 270f,
};
worksheet.FloatingObjects.Add(pie);
Block Arc
var arc = new BlockArcShape()
{
Location = new Graphics.Point(60, 90),
Size = new Graphics.Size(120, 120),
StartAngle = -90f,
SweepAngle = 180f,
ArcWidth = 20f,
};
worksheet.FloatingObjects.Add(arc);
Line
A Line is positioned by StartPoint and EndPoint. You can add arrow caps to either end.
var line = new Line()
{
StartPoint = new Graphics.Point(60, 130),
EndPoint = new Graphics.Point(220, 130),
};
line.Style.LineWidth = 1.5f;
line.Style.EndCap = Graphics.LineCapStyles.Arrow;
worksheet.FloatingObjects.Add(line);
Setting Text
All shapes derived from ShapeObject (Rectangle, Ellipse, Diamond, etc.) support a Text property.
rect.Text = "My Label";
Styling
Access the Style property on any shape to customize its appearance.
Fill Color
rect.Style.FillColor = Graphics.SolidColor.LightYellow;
Line Color and Width
rect.Style.LineColor = Graphics.SolidColor.Navy;
rect.Style.LineWidth = 2.0f;
Line Style
rect.Style.LineStyle = Graphics.LineStyles.Dash;
Available LineStyles values:
| Value | Description |
|---|---|
Solid | Solid line (default) |
Dash | Dashed line |
Dot | Dotted line |
DashDot | Dash-dot line |
DashDotDot | Dash-dot-dot line |
Text Color and Alignment
rect.Style.TextColor = Graphics.SolidColor.DarkBlue;
rect.Style.HorizontalAlignment = Drawing.HorizontalAlignment.Center;
rect.Style.VerticalAlignment = Drawing.VerticalAlignment.Middle;
Line Cap Styles (for Line shapes)
line.Style.StartCap = Graphics.LineCapStyles.Ellipse;
line.Style.EndCap = Graphics.LineCapStyles.Arrow;
Available LineCapStyles values:
| Value | Description |
|---|---|
None | No cap (default) |
Arrow | Arrow head |
Ellipse | Ellipse cap |
Round | Round cap |
Rotation
Rotate any shape around its center point using RotateAngle (degrees).
rect.RotateAngle = 45f;
Complete Style Example
var rect = new RectangleShape()
{
Location = new Graphics.Point(120, 90),
Size = new Graphics.Size(160, 100),
Text = "Styled Shape",
};
rect.Style.FillColor = Graphics.SolidColor.LightGoldenrodYellow;
rect.Style.LineColor = Graphics.SolidColor.LimeGreen;
rect.Style.LineWidth = 3f;
rect.RotateAngle = 15f;
worksheet.FloatingObjects.Add(rect);
Managing Shapes
// Remove a specific shape
worksheet.FloatingObjects.Remove(rect);
// Remove all shapes
worksheet.FloatingObjects.Clear();
// Iterate all shapes
foreach (var obj in worksheet.FloatingObjects)
{
Console.WriteLine(obj.Bounds);
}
// Count shapes
int count = worksheet.FloatingObjects.Count;
API Reference
Common Properties (all shapes)
| Property | Type | Description |
|---|---|---|
Location | Graphics.Point | Top-left position on the worksheet |
Size | Graphics.Size | Width and height |
Bounds | Graphics.Rectangle | Position and size combined |
X, Y | RGFloat | Individual coordinates |
Width, Height | RGFloat | Individual dimensions |
RotateAngle | RGFloat | Rotation angle in degrees (0 = no rotation) |
Visible | bool | Whether the shape is visible |
Style | IDrawingObjectStyle | Style object for fill, line, and text |
ShapeObject Properties (Rectangle, Ellipse, Diamond, etc.)
| Property | Type | Description |
|---|---|---|
Text | string | Text displayed inside the shape |
Style.TextColor | SolidColor | Color of the text |
Style.HorizontalAlignment | HorizontalAlignment | Horizontal text alignment |
Style.VerticalAlignment | VerticalAlignment | Vertical text alignment |
RoundedRectangleShape
| Property | Type | Description |
|---|---|---|
RoundRate | RGFloat | Corner roundness (0.0 = sharp, 1.0 = fully round) |
PieShape
| Property | Type | Description |
|---|---|---|
StartAngle | RGFloat | Start angle in degrees |
SweepAngle | RGFloat | Sweep angle in degrees |
BlockArcShape
| Property | Type | Description |
|---|---|---|
StartAngle | RGFloat | Start angle in degrees |
SweepAngle | RGFloat | Sweep angle in degrees |
ArcWidth | RGFloat | Thickness of the arc |
Line
| Property | Type | Description |
|---|---|---|
StartPoint | Graphics.Point | Start position of the line |
EndPoint | Graphics.Point | End position of the line |
Style.StartCap | LineCapStyles | Cap style at start point |
Style.EndCap | LineCapStyles | Cap style at end point |
Style.LineWidth | RGFloat | Width of the line |
Style.LineColor | SolidColor | Color of the line |
IDrawingObjectStyle Properties (via shape.Style)
| Property | Type | Description |
|---|---|---|
FillColor | IColor | Background fill color |
LineColor | SolidColor | Outline color |
LineWidth | RGFloat | Outline width |
LineStyle | LineStyles | Outline style (Solid, Dash, Dot, etc.) |