Home Forums WinForms controls Xceed Grid for WinForms Grid Drawing Reply To: Grid Drawing

User (Old forums)
Post count: 23064

Here is the code I used; with no success may I add; The Draw method is called from the ‘OnPrintPage’ of the PrintDocument. It is passed the graphics to be printed on (targetGraphics). The grid to be printed is represented by teh sourceGraphics. For some reason I am getting a screen shoot (Graphics) of the entire screen instead of the data grid (the first line). Any ideas? I am not getting any help from Xceed at all.

I need the drawing functionality for my customized printing, which repeats selected columns in the grid on every print page.

public void Draw(Graphics targetGraphics, float x, float y)
Graphics sourceGraphics = this.dataGrid.CreateGraphics();
Size sourceSize = this.GetElementSize();

//Copy it to panel2
Image sourceImage = new Bitmap(sourceSize.Width, sourceSize.Height, sourceGraphics);
Graphics sourceImageGraphics = Graphics.FromImage(sourceImage);

IntPtr dc1 = sourceGraphics.GetHdc();
IntPtr dc2 = sourceImageGraphics.GetHdc();

PrintElement.BitBlt(dc2, 0, 0, this.dataGrid.Size.Width, this.dataGrid.Size.Height, dc1, 0, 0, 13369376);


targetGraphics.DrawImage(sourceImage, x, y);


Imported from legacy forums. Posted by romanr (had 3536 views)