10780 : In print preview images from imageList are not where they should be?

Question

I have question about custom cells draw and print preview< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

This is my source:

 

private void gantt_OnGridCustomCellDraw(PlexityHide.GTP.Grid aGrid, PlexityHide.GTP.CustomCellEventArgs e)

{

    int width = Math.Min(e.Cell.CellRect.Width, imageList.ImageSize.Width);

    int height = Math.Min(e.Cell.CellRect.Height, imageList.ImageSize.Width);

    int size = Math.Min(width, height);

    int x = e.Cell.CellRect.Left + Math.Max(0, (e.Cell.CellRect.Width – size) / 2);

    int y = e.Cell.CellRect.Top + Math.Max(0, (e.Cell.CellRect.Height – size) / 2);

    e.G.DrawImage(pictureBox1.Image, x, y, size, size);

    imageList.Draw(e.G, x, y, size, size, 1);

}

 

It draw perfect my custom cell images.

 

But in print preview images from imageList are not where they have to be. Image from pictureBox1 is on the right place.

 

Why is that? What approach I have to use when I want to draw more different images?

 

Answer

 

In the print your cell is scaled depending on the device context. Your printer likely has greater resolution than your screen. All this is handled by the Graphics object.

 

BUT the imageList.Draw somehow neglects to see this (I would say it is an image list bug).

 

To workaround go like this: 

e.G.DrawImage(imageList.Images[1],x,y);

 

instead of like this:

BUG    imageList.Draw(e.G, x, y, size, size, 1);