Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • User (Old forums)
    Post count: 23064
    #13348 |

    How can I draw an existing grid onto a Graphics object?

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

    User (Old forums)
    Post count: 23064

    I don’t think the GridControl has a specific method for doing this. But the GridControl is just a Control, and I think you can send a WM_PRINT message to a control, that will make the control paint itself onto a device context you specify.<code>using System.Drawing;
    using System.Windows.Forms;

    public class ControlPainter
    private const int WM_PRINT = 0x317, PRF_CLIENT = 4;

    private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, int lParam);

    public static void PaintControl(Control control, Graphics graphics)
    IntPtr hWnd = control.Handle;
    IntPtr hDC = graphics.GetHdc();
    SendMessage(hWnd, WM_PRINT, hDC, PRF_CLIENT);
    If you try this (untested code), could you let me know if it worked?

    Imported from legacy forums. Posted by Tommy (had 171 views)

    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)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.