Floating objects exist independently of the cell grid and can be positioned freely at absolute locations on the worksheet. They include drawing shapes, images, and charts.

Namespace

using unvell.ReoGrid.Drawing;
using unvell.ReoGrid.Drawing.Shapes;

Class Hierarchy

FloatingObject
  โ””โ”€ DrawingObject
      โ”œโ”€ ShapeObject
      โ”‚   โ”œโ”€ RectangleShape
      โ”‚   โ”œโ”€ EllipseShape
      โ”‚   โ”œโ”€ RoundedRectangleShape
      โ”‚   โ”œโ”€ DiamondShape
      โ”‚   โ”œโ”€ PieShape
      โ”‚   โ””โ”€ BlockArcShape
      โ”œโ”€ Line
      โ”œโ”€ ImageObject
      โ””โ”€ DrawingComponent
          โ””โ”€ Chart (ColumnChart, BarChart, LineChart, etc.)

Adding Floating Objects

All floating objects are managed through the FloatingObjects collection on the worksheet:

var sheet = grid.CurrentWorksheet;

// Create a shape
var rect = new RectangleShape
{
    Location = new Graphics.Point(50, 50),
    Size = new Graphics.Size(200, 100),
    Text = "Hello ReoGrid",
};

// Add to worksheet
sheet.FloatingObjects.Add(rect);

Result: 262

FloatingObjects Collection

MethodDescription
Add(object)Add a floating object to the worksheet
AddRange(objects)Add multiple floating objects at once
Remove(object)Remove a specific floating object
Clear()Remove all floating objects
Contains(object)Check if an object is in the collection
CountNumber of floating objects (read-only)
this[int index]Access by index
// Remove a specific shape
sheet.FloatingObjects.Remove(rect);

// Remove all floating objects
sheet.FloatingObjects.Clear();

// Iterate all floating objects
foreach (var obj in sheet.FloatingObjects)
{
    Console.WriteLine($"{obj.GetType().Name}: {obj.Bounds}");
}

// Count floating objects
int count = sheet.FloatingObjects.Count;

Common Properties (All Floating Objects)

All floating objects share these positioning and sizing properties:

PropertyTypeDescription
LocationGraphics.PointTop-left position on the worksheet
SizeGraphics.SizeWidth and height
BoundsGraphics.RectanglePosition and size combined
XRGFloatX coordinate
YRGFloatY coordinate
WidthRGFloatWidth
HeightRGFloatHeight
LeftRGFloatLeft edge (read-only)
RightRGFloatRight edge (read-only)
TopRGFloatTop edge (read-only)
BottomRGFloatBottom edge (read-only)
// Position
rect.Location = new Graphics.Point(100, 200);

// Size
rect.Size = new Graphics.Size(300, 150);

// Both at once
rect.Bounds = new Graphics.Rectangle(100, 200, 300, 150);

// Individual properties
rect.X = 100;
rect.Width = 300;

DrawingObject Properties

Drawing objects add visual styling and transformation properties:

PropertyTypeDescription
VisibleboolWhether the object is visible
RotateAngleRGFloatRotation angle in degrees
ScaleXRGFloatHorizontal scale factor
ScaleYRGFloatVertical scale factor
StyleIDrawingObjectStyleStyle for fill, line, and text
ClientBoundsRectangleBounds within the object (read-only)
rect.RotateAngle = 45f;
rect.Visible = false;

Styling

Access the Style property to customize appearance:

IDrawingObjectStyle Properties

PropertyTypeDescription
FillColorIColorBackground fill color
LineColorSolidColorOutline color
LineWidthRGFloatOutline width
LineStyleLineStylesOutline style
rect.Style.FillColor = Graphics.SolidColor.LightYellow;
rect.Style.LineColor = Graphics.SolidColor.Navy;
rect.Style.LineWidth = 2.0f;
rect.Style.LineStyle = Graphics.LineStyles.Dash;

LineStyles Enum

ValueDescription
SolidSolid line (default)
DashDashed line
DotDotted line
DashDotDash-dot line
DashDotDotDash-dot-dot line

Shape Text Styling

Shapes (Rectangle, Ellipse, Diamond, etc.) support text via IDrawingShapeObjectStyle:

PropertyTypeDescription
TextColorSolidColorText color
HorizontalAlignmentHorizontalAlignmentText horizontal alignment
VerticalAlignmentVerticalAlignmentText vertical alignment
rect.Text = "Styled Shape";
rect.Style.TextColor = Graphics.SolidColor.DarkBlue;
rect.Style.HorizontalAlignment = Drawing.HorizontalAlignment.Center;
rect.Style.VerticalAlignment = Drawing.VerticalAlignment.Middle;

Line Cap Styling

Line objects support cap styles via IDrawingLineObjectStyle:

PropertyTypeDescription
StartCapLineCapStylesCap at the start point
EndCapLineCapStylesCap at the end point

LineCapStyles Enum

ValueDescription
NoneNo cap (default)
ArrowArrow head
EllipseEllipse cap
RoundRound cap

Events

FloatingObject Events

EventDescription
MouseDownMouse button pressed on the object

Selection Events

EventDescription
SelectionChangedObject selection state changed
rect.SelectionChanged += (s, e) =>
{
    Console.WriteLine($"Selected: {rect.IsSelected}");
};

Object Types

Drawing Shapes

Shapes with fill, outline, and text support. See Drawing Shapes for all shape types and their properties.

Floating Image

Display images on the worksheet. See Floating Image.

261

var image = Image.FromFile("photo.png");
var imgObj = new ImageObject(image)
{
    Location = new Graphics.Point(40, 30),
};
sheet.FloatingObjects.Add(imgObj);

Charts

Charts are also floating objects. See Chart for all chart types.

Interface Hierarchy

InterfaceExtendsDescription
IFloatingObjectโ€”Base: position, size, bounds
IDrawingObjectIFloatingObjectAdds: style, rotation, scale, container
IDrawingContainerIDrawingObjectAdds: children collection, clip bounds
Was this article helpful?