Center image spancell

Posted by: fsegui on 21 October 2020, 2:20 am EST

  • Posted 21 October 2020, 2:20 am EST

    Hello,

    I'm trying to vertically center an image in a spancell.
    How can I do that?
    I've tried to set the verticalalignment property of each cell to center but image does only appear in the first cell.
  • Marked as Answer

    Replied 21 October 2020, 7:19 pm EST

    Hello,

    In case of cell spanning, the cell style for the upper left corner of the span is used for the whole span., as if you are stretching that corner cell to cover the other cells in the span.
    So, you are suggested to make sure the VerticalAlignment of the top left span cell is set to Center.

    I used the following code and the image shows at span's vertically center:
    fpSpread1.ActiveSheet.Cells[0, 0].Text = "These cells are spanned.";
    fpSpread1.ActiveSheet.AddSpanCell(0, 0, 10, 5);
    fpSpread1.ActiveSheet.Cells[0, 0].HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Center;
    fpSpread1.ActiveSheet.Cells[0, 0].VerticalAlignment = FarPoint.Win.Spread.CellVerticalAlignment.Center;

    FarPoint.Win.Spread.CellType.ImageCellType imgct = new FarPoint.Win.Spread.CellType.ImageCellType();
    System.Drawing.Image image = Properties.Resources.TestImage;
    imgct.Style = FarPoint.Win.RenderStyle.Normal;
    fpSpread1.Sheets[0].Cells[0, 0, 10, 5].CellType = imgct;
    fpSpread1.Sheets[0].Cells[0, 0].Value = image;
    Regards,
    Ruchir
  • Replied 21 October 2020, 11:49 pm EST

    Hello,

    Thanks for your reply. I was not applying the imagecelltype to the span cell but to each cell. Now it's working fine.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels