Floating Image

ReoGrid supports floating images displayed on worksheet. It is possible to load and save images from Excel file as well as show the images on worksheet.

Add image on worksheet

// Get a worksheet instance
var worksheet = reoGridControl.Worksheets[0];

// Create a Windows Form image from file
var image = Image.FromFile("Sample.png");

// Create a floating image object
var imageObject = new Drawing.ImageObject(image)
{
  // Set the image location on worksheet
  Location = new Graphics.Point(4030),
};

// Add the floating image object onto worksheet
worksheet.FloatingObjects.Add(imageObject);

Result: 261

Get image from worksheet

Iterate over all floating objects and check whether or not a floating object is image object:

foreach (var floatingObject in worksheet.FloatingObjects)
{
  // check whether or not the floating object is an image
  if (floatingObject is Drawing.ImageObject)
  {
    var imageObject = (Drawing.ImageObject)floatingObject;
    ...
  }
}

Get and set image location and size

Property Location used to set the location of image on worksheet.

imageObject.Location = new Graphics.Point(40, 30);

Property Size of floating image used to get and set the size of floating image.

When the floating image created initially, the Size is the actual size of image. To change the size, use the following code:

imageObject.Size = new Graphics.Size(200, 100);

It is possible to set both location and size at same time:

imageObject.Bounds = new Graphics.Rectangle(200, 100, 80, 60);

Excel Support

When a worksheet contains any floating images, the floating images will be loaded from Excel and saved into Excel file automatically.

About Floating Objects

Drawing shapes, Images and Charts are the floating objects on worksheet. To add and remove floating objects to and from worksheet, use the Worksheet.FloatingObjects collection property.

Learn more about Floating Objects.


Was the content of the page helpful?