473,841 Members | 1,868 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Saving a panel to a Graphics (Printing)

Dear All,

I need to save the content of a panel to a bitmap. The panel can have
many child controls which also need to be saved. The problem would be
solved if I could have the panel saved to a Graphics object, which is
the same as if I'd need to print it. It'd be easy using
Control.DrawToB itmap, but I also need the invisible part of the panel
(which is hidden because of scrolling) and DrawToBitmap just takes a
screenshot.

I've been reading about this. Many samples uses BitBlt, but that also
skips the invisible part. I've also seen some posts stating that this
is not a simple thing and I'd need to programatically scroll to all
needed position and combine the screenshots taken from all the scroll-
positions. These posts were from 2003 or 2004.

So my question: Is there any new solutions provided by VS2005? Or do I
have to do this multiple scrolling (which produces flickering)?

Thank you for any help!

Chris

Jun 9 '07 #1
9 4273

"she_prog" <pu*********@ya hoo.comwrote in message
news:11******** **************@ m36g2000hse.goo glegroups.com.. .
Dear All,

I need to save the content of a panel to a bitmap. The panel can have
many child controls which also need to be saved. The problem would be
solved if I could have the panel saved to a Graphics object, which is
the same as if I'd need to print it. It'd be easy using
Control.DrawToB itmap, but I also need the invisible part of the panel
(which is hidden because of scrolling) and DrawToBitmap just takes a
screenshot.

I've been reading about this. Many samples uses BitBlt, but that also
skips the invisible part. I've also seen some posts stating that this
is not a simple thing and I'd need to programatically scroll to all
needed position and combine the screenshots taken from all the scroll-
positions. These posts were from 2003 or 2004.

So my question: Is there any new solutions provided by VS2005? Or do I
No, there aren't. However, Windows has always had a solution for this:
WM_PRINT.

Try creating a bitmap of the appropriate size, getting a Graphics for it,
get the HDC, and SendMessage WM_PRINT to the window and each of its
children. That will usually get you the results you are looking for.
have to do this multiple scrolling (which produces flickering)?

Thank you for any help!

Chris
Jun 9 '07 #2
Thank you very much, Ben!
I tried your solution, but it didn't work for me. Maybe the problem is
that I'm trying to save a class of my own, derived from Panel and
OnPaint method is overriden in this new class. When trying to debug,
OnPaint is not called as a result of SendMessage. Here's my code:

[DllImport("user 32.dll")]
public static extern int SendMessage(
IntPtr hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);

const int WM_PRINT = 0x317;

[Flags]
enum DrawingOptions
{
PRF_CHECKVISIBL E = 0x01,
PRF_NONCLIENT = 0x02,
PRF_CLIENT = 0x04,
PRF_ERASEBKGND = 0x08,
PRF_CHILDREN = 0x10,
PRF_OWNED = 0x20
}

....
Bitmap l_bmp = new Bitmap(c_panel. Width, c_panel.Height) ;
Graphics l_grp = Graphics.FromIm age(l_bmp);
IntPtr hdc = l_grp.GetHdc();
SendMessage(c_p anel.Handle, WM_PRINT, (int)hdc,
(int)DrawingOpt ions.PRF_OWNED) ;

Could you please advice further?
Regards,
Chris

Ben Voigt [C++ MVP] írta:
"she_prog" <pu*********@ya hoo.comwrote in message
news:11******** **************@ m36g2000hse.goo glegroups.com.. .
Dear All,

I need to save the content of a panel to a bitmap. The panel can have
many child controls which also need to be saved. The problem would be
solved if I could have the panel saved to a Graphics object, which is
the same as if I'd need to print it. It'd be easy using
Control.DrawToB itmap, but I also need the invisible part of the panel
(which is hidden because of scrolling) and DrawToBitmap just takes a
screenshot.

I've been reading about this. Many samples uses BitBlt, but that also
skips the invisible part. I've also seen some posts stating that this
is not a simple thing and I'd need to programatically scroll to all
needed position and combine the screenshots taken from all the scroll-
positions. These posts were from 2003 or 2004.

So my question: Is there any new solutions provided by VS2005? Or do I
No, there aren't. However, Windows has always had a solution for this:
WM_PRINT.

Try creating a bitmap of the appropriate size, getting a Graphics for it,
get the HDC, and SendMessage WM_PRINT to the window and each of its
children. That will usually get you the results you are looking for.
have to do this multiple scrolling (which produces flickering)?

Thank you for any help!

Chris
Jun 9 '07 #3
You should also use the CLIENT and CHILDREN flags (OR-ed together), to get
the content of the window and all contained windows.
"she_prog" <pu*********@ya hoo.comwrote in message
news:11******** **************@ c77g2000hse.goo glegroups.com.. .
Thank you very much, Ben!
I tried your solution, but it didn't work for me. Maybe the problem is
that I'm trying to save a class of my own, derived from Panel and
OnPaint method is overriden in this new class. When trying to debug,
OnPaint is not called as a result of SendMessage. Here's my code:

[DllImport("user 32.dll")]
public static extern int SendMessage(
IntPtr hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);

const int WM_PRINT = 0x317;

[Flags]
enum DrawingOptions
{
PRF_CHECKVISIBL E = 0x01,
PRF_NONCLIENT = 0x02,
PRF_CLIENT = 0x04,
PRF_ERASEBKGND = 0x08,
PRF_CHILDREN = 0x10,
PRF_OWNED = 0x20
}

....
Bitmap l_bmp = new Bitmap(c_panel. Width, c_panel.Height) ;
Graphics l_grp = Graphics.FromIm age(l_bmp);
IntPtr hdc = l_grp.GetHdc();
SendMessage(c_p anel.Handle, WM_PRINT, (int)hdc,
(int)DrawingOpt ions.PRF_OWNED) ;

Could you please advice further?
Regards,
Chris

Ben Voigt [C++ MVP] írta:
"she_prog" <pu*********@ya hoo.comwrote in message
news:11******** **************@ m36g2000hse.goo glegroups.com.. .
Dear All,

I need to save the content of a panel to a bitmap. The panel can have
many child controls which also need to be saved. The problem would be
solved if I could have the panel saved to a Graphics object, which is
the same as if I'd need to print it. It'd be easy using
Control.DrawToB itmap, but I also need the invisible part of the panel
(which is hidden because of scrolling) and DrawToBitmap just takes a
screenshot.

I've been reading about this. Many samples uses BitBlt, but that also
skips the invisible part. I've also seen some posts stating that this
is not a simple thing and I'd need to programatically scroll to all
needed position and combine the screenshots taken from all the scroll-
positions. These posts were from 2003 or 2004.

So my question: Is there any new solutions provided by VS2005? Or do I
No, there aren't. However, Windows has always had a solution for this:
WM_PRINT.

Try creating a bitmap of the appropriate size, getting a Graphics for it,
get the HDC, and SendMessage WM_PRINT to the window and each of its
children. That will usually get you the results you are looking for.
have to do this multiple scrolling (which produces flickering)?

Thank you for any help!

Chris
Jun 9 '07 #4
Great, now I can see stepping through OnPaint when debugging. Still,
the resulted Bitmap is all blank :(
Right after SendMessage I'm calling l_bmp.Save(file name); so there's
no code overdrawing the result of SendMessage. The same OnPaint draws
the panel and its children just fine onto the screen.
Right now I'm just testing without scrollbars, so that shouldn't cause
the problem. I might try to do a small sample application to try to
narrow down the cause.

Thank you very much for the help! If you could think of anything that
could cause the problem, please let me know!
Regards,
Chris

Ben Voigt [C++ MVP] írta:
You should also use the CLIENT and CHILDREN flags (OR-ed together), to get
the content of the window and all contained windows.
"she_prog" <pu*********@ya hoo.comwrote in message
news:11******** **************@ c77g2000hse.goo glegroups.com.. .
Thank you very much, Ben!
I tried your solution, but it didn't work for me. Maybe the problem is
that I'm trying to save a class of my own, derived from Panel and
OnPaint method is overriden in this new class. When trying to debug,
OnPaint is not called as a result of SendMessage. Here's my code:

[DllImport("user 32.dll")]
public static extern int SendMessage(
IntPtr hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);

const int WM_PRINT = 0x317;

[Flags]
enum DrawingOptions
{
PRF_CHECKVISIBL E = 0x01,
PRF_NONCLIENT = 0x02,
PRF_CLIENT = 0x04,
PRF_ERASEBKGND = 0x08,
PRF_CHILDREN = 0x10,
PRF_OWNED = 0x20
}

...
Bitmap l_bmp = new Bitmap(c_panel. Width, c_panel.Height) ;
Graphics l_grp = Graphics.FromIm age(l_bmp);
IntPtr hdc = l_grp.GetHdc();
SendMessage(c_p anel.Handle, WM_PRINT, (int)hdc,
(int)DrawingOpt ions.PRF_OWNED) ;

Could you please advice further?
Regards,
Chris

Ben Voigt [C++ MVP] írta:
"she_prog" <pu*********@ya hoo.comwrote in message
news:11******** **************@ m36g2000hse.goo glegroups.com.. .
Dear All,
>
I need to save the content of a panel to a bitmap. The panel can have
many child controls which also need to be saved. The problem would be
solved if I could have the panel saved to a Graphics object, which is
the same as if I'd need to print it. It'd be easy using
Control.DrawToB itmap, but I also need the invisible part of the panel
(which is hidden because of scrolling) and DrawToBitmap just takes a
screenshot.
>
I've been reading about this. Many samples uses BitBlt, but that also
skips the invisible part. I've also seen some posts stating that this
is not a simple thing and I'd need to programatically scroll to all
needed position and combine the screenshots taken from all the scroll-
positions. These posts were from 2003 or 2004.
>
So my question: Is there any new solutions provided by VS2005? Or do I
No, there aren't. However, Windows has always had a solution for this:
WM_PRINT.

Try creating a bitmap of the appropriate size, getting a Graphics for it,
get the HDC, and SendMessage WM_PRINT to the window and each of its
children. That will usually get you the results you are looking for.
have to do this multiple scrolling (which produces flickering)?
>
Thank you for any help!
>
Chris
>
Jun 9 '07 #5
Did you Dispose the Graphics object before trying to use the Bitmap?

"she_prog" <pu*********@ya hoo.comwrote in message
news:11******** **************@ k79g2000hse.goo glegroups.com.. .
Great, now I can see stepping through OnPaint when debugging. Still,
the resulted Bitmap is all blank :(
Right after SendMessage I'm calling l_bmp.Save(file name); so there's
no code overdrawing the result of SendMessage. The same OnPaint draws
the panel and its children just fine onto the screen.
Right now I'm just testing without scrollbars, so that shouldn't cause
the problem. I might try to do a small sample application to try to
narrow down the cause.

Thank you very much for the help! If you could think of anything that
could cause the problem, please let me know!
Regards,
Chris

Ben Voigt [C++ MVP] írta:
You should also use the CLIENT and CHILDREN flags (OR-ed together), to get
the content of the window and all contained windows.
"she_prog" <pu*********@ya hoo.comwrote in message
news:11******** **************@ c77g2000hse.goo glegroups.com.. .
Thank you very much, Ben!
I tried your solution, but it didn't work for me. Maybe the problem is
that I'm trying to save a class of my own, derived from Panel and
OnPaint method is overriden in this new class. When trying to debug,
OnPaint is not called as a result of SendMessage. Here's my code:

[DllImport("user 32.dll")]
public static extern int SendMessage(
IntPtr hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);

const int WM_PRINT = 0x317;

[Flags]
enum DrawingOptions
{
PRF_CHECKVISIBL E = 0x01,
PRF_NONCLIENT = 0x02,
PRF_CLIENT = 0x04,
PRF_ERASEBKGND = 0x08,
PRF_CHILDREN = 0x10,
PRF_OWNED = 0x20
}

...
Bitmap l_bmp = new Bitmap(c_panel. Width, c_panel.Height) ;
Graphics l_grp = Graphics.FromIm age(l_bmp);
IntPtr hdc = l_grp.GetHdc();
SendMessage(c_p anel.Handle, WM_PRINT, (int)hdc,
(int)DrawingOpt ions.PRF_OWNED) ;

Could you please advice further?
Regards,
Chris

Ben Voigt [C++ MVP] írta:
"she_prog" <pu*********@ya hoo.comwrote in message
news:11******** **************@ m36g2000hse.goo glegroups.com.. .
Dear All,
>
I need to save the content of a panel to a bitmap. The panel can have
many child controls which also need to be saved. The problem would be
solved if I could have the panel saved to a Graphics object, which is
the same as if I'd need to print it. It'd be easy using
Control.DrawToB itmap, but I also need the invisible part of the panel
(which is hidden because of scrolling) and DrawToBitmap just takes a
screenshot.
>
I've been reading about this. Many samples uses BitBlt, but that also
skips the invisible part. I've also seen some posts stating that this
is not a simple thing and I'd need to programatically scroll to all
needed position and combine the screenshots taken from all the scroll-
positions. These posts were from 2003 or 2004.
>
So my question: Is there any new solutions provided by VS2005? Or do I
No, there aren't. However, Windows has always had a solution for this:
WM_PRINT.

Try creating a bitmap of the appropriate size, getting a Graphics for
it,
get the HDC, and SendMessage WM_PRINT to the window and each of its
children. That will usually get you the results you are looking for.
have to do this multiple scrolling (which produces flickering)?
>
Thank you for any help!
>
Chris
>
Jun 9 '07 #6
"she_prog" <pu*********@ya hoo.comwrote in message
news:11******** **************@ k79g2000hse.goo glegroups.com.. .
>the resulted Bitmap is all blank :(
Right after SendMessage I'm calling l_bmp.Save(file name); so there's
no code overdrawing the result of SendMessage.
Release the hdc before saving the bitmap.

c_panel.Width and c_panel.Height will only get you the visible part of the
control.
Use c_panel.Display Rectangle.Width , c_panel.Display Rectangle.Heigh t to get
the entire control.

--
Mick Doherty
http://www.dotnetrix.co.uk/nothing.html
Jun 10 '07 #7
Thank you, Mick! The first code was just for testing purposes, yes, I
did use DisplayRectangl e.
Mick Doherty írta:
"she_prog" <pu*********@ya hoo.comwrote in message
news:11******** **************@ k79g2000hse.goo glegroups.com.. .
the resulted Bitmap is all blank :(
Right after SendMessage I'm calling l_bmp.Save(file name); so there's
no code overdrawing the result of SendMessage.

Release the hdc before saving the bitmap.

c_panel.Width and c_panel.Height will only get you the visible part of the
control.
Use c_panel.Display Rectangle.Width , c_panel.Display Rectangle.Heigh t to get
the entire control.

--
Mick Doherty
http://www.dotnetrix.co.uk/nothing.html
Jun 10 '07 #8
You're great, Ben, thank you very much! I did play with flags and all,
but here I'm displaying the code that's working for me for every case
- it might help someone sometime in the future :)

[DllImport("user 32.dll")]
public static extern int SendMessage(
IntPtr hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);

const int WM_PRINT = 0x317;

[Flags]
enum DrawingOptions
{
PRF_CHECKVISIBL E = 0x01,
PRF_NONCLIENT = 0x02,
PRF_CLIENT = 0x04,
PRF_ERASEBKGND = 0x08,
PRF_CHILDREN = 0x10,
PRF_OWNED = 0x20
}

private void command_Click(o bject sender, EventArgs e)
{
// get filename
c_panel.AutoScr ollPosition = new Point(0, 0);
Bitmap l_bmpPanel = new
Bitmap(c_panel. DisplayRectangl e.Width,
c_panel.Display Rectangle.Heigh t);
Graphics l_grpSrc = Graphics.FromIm age(l_bmpPanel) ;

c_panel.ForcePa int(new PaintEventArgs( l_grpSrc,
c_panel.Display Rectangle));
SendMessage(c_p anel.Handle, WM_PRINT,
(int)l_grpSrc.G etHdc(), (int)(DrawingOp tions.PRF_OWNED |
DrawingOptions. PRF_CHILDREN | DrawingOptions. PRF_CLIENT |
DrawingOptions. PRF_NONCLIENT)) ;
l_grpSrc.Releas eHdc();

l_bmpPanel.Save (filename);
}

I had to set AutoScrollPosit ion to (0,0), but I don't think it's
against the user-friendliness of the application.
ForcePaint is simple:

public void ForcePaint(Pain tEventArgs pe)
{
OnPaint(pe);
}

It's only needed because I have some custom painting in this OnPaint
and that was only drawn in the visible area of the panel, I don't
really know why. All children have custom painting as well, and those
drawings are done both on visible and invisible area. Although I don't
think it's elegant programming, I couldn't think of any other
solution.

So thank you again for the help, Ben!
Regards, Chris

Ben Voigt [C++ MVP] írta:
Did you Dispose the Graphics object before trying to use the Bitmap?

"she_prog" <pu*********@ya hoo.comwrote in message
news:11******** **************@ k79g2000hse.goo glegroups.com.. .
Great, now I can see stepping through OnPaint when debugging. Still,
the resulted Bitmap is all blank :(
Right after SendMessage I'm calling l_bmp.Save(file name); so there's
no code overdrawing the result of SendMessage. The same OnPaint draws
the panel and its children just fine onto the screen.
Right now I'm just testing without scrollbars, so that shouldn't cause
the problem. I might try to do a small sample application to try to
narrow down the cause.

Thank you very much for the help! If you could think of anything that
could cause the problem, please let me know!
Regards,
Chris

Ben Voigt [C++ MVP] írta:
You should also use the CLIENT and CHILDREN flags (OR-ed together), to get
the content of the window and all contained windows.
"she_prog" <pu*********@ya hoo.comwrote in message
news:11******** **************@ c77g2000hse.goo glegroups.com.. .
Thank you very much, Ben!
I tried your solution, but it didn't work for me. Maybe the problem is
that I'm trying to save a class of my own, derived from Panel and
OnPaint method is overriden in this new class. When trying to debug,
OnPaint is not called as a result of SendMessage. Here's my code:

[DllImport("user 32.dll")]
public static extern int SendMessage(
IntPtr hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);

const int WM_PRINT = 0x317;

[Flags]
enum DrawingOptions
{
PRF_CHECKVISIBL E = 0x01,
PRF_NONCLIENT = 0x02,
PRF_CLIENT = 0x04,
PRF_ERASEBKGND = 0x08,
PRF_CHILDREN = 0x10,
PRF_OWNED = 0x20
}

...
Bitmap l_bmp = new Bitmap(c_panel. Width, c_panel.Height) ;
Graphics l_grp = Graphics.FromIm age(l_bmp);
IntPtr hdc = l_grp.GetHdc();
SendMessage(c_p anel.Handle, WM_PRINT, (int)hdc,
(int)DrawingOpt ions.PRF_OWNED) ;

Could you please advice further?
Regards,
Chris

Ben Voigt [C++ MVP] írta:
"she_prog" <pu*********@ya hoo.comwrote in message
news:11******** **************@ m36g2000hse.goo glegroups.com.. .
Dear All,

I need to save the content of a panel to a bitmap. The panel can have
many child controls which also need to be saved. The problem would be
solved if I could have the panel saved to a Graphics object, which is
the same as if I'd need to print it. It'd be easy using
Control.DrawToB itmap, but I also need the invisible part of the panel
(which is hidden because of scrolling) and DrawToBitmap just takes a
screenshot.

I've been reading about this. Many samples uses BitBlt, but that also
skips the invisible part. I've also seen some posts stating that this
is not a simple thing and I'd need to programatically scroll to all
needed position and combine the screenshots taken from all the scroll-
positions. These posts were from 2003 or 2004.

So my question: Is there any new solutions provided by VS2005? Or do I
No, there aren't. However, Windows has always had a solution for this:
WM_PRINT.
>
Try creating a bitmap of the appropriate size, getting a Graphics for
it,
get the HDC, and SendMessage WM_PRINT to the window and each of its
children. That will usually get you the results you are looking for.
>
have to do this multiple scrolling (which produces flickering)?

Thank you for any help!

Chris
Jun 10 '07 #9
I'm glad it helped. If custom draw worked properly in children but not the
panel itself, then the panel's WM_PAINT must clip to the visible area
instead of using the clipping region you gave it. Does your OnPaint do
anything like that? That part about having to call OnPaint yourself seems
to be the most hacky part of this, and still not too bad. WM_PRINT is
definitely intended for this purpose.
"she_prog" <pu*********@ya hoo.comwrote in message
news:11******** **************@ m36g2000hse.goo glegroups.com.. .
You're great, Ben, thank you very much! I did play with flags and all,
but here I'm displaying the code that's working for me for every case
- it might help someone sometime in the future :)

[DllImport("user 32.dll")]
public static extern int SendMessage(
IntPtr hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);

const int WM_PRINT = 0x317;

[Flags]
enum DrawingOptions
{
PRF_CHECKVISIBL E = 0x01,
PRF_NONCLIENT = 0x02,
PRF_CLIENT = 0x04,
PRF_ERASEBKGND = 0x08,
PRF_CHILDREN = 0x10,
PRF_OWNED = 0x20
}

private void command_Click(o bject sender, EventArgs e)
{
// get filename
c_panel.AutoScr ollPosition = new Point(0, 0);
Bitmap l_bmpPanel = new
Bitmap(c_panel. DisplayRectangl e.Width,
c_panel.Display Rectangle.Heigh t);
Graphics l_grpSrc = Graphics.FromIm age(l_bmpPanel) ;

c_panel.ForcePa int(new PaintEventArgs( l_grpSrc,
c_panel.Display Rectangle));
SendMessage(c_p anel.Handle, WM_PRINT,
(int)l_grpSrc.G etHdc(), (int)(DrawingOp tions.PRF_OWNED |
DrawingOptions. PRF_CHILDREN | DrawingOptions. PRF_CLIENT |
DrawingOptions. PRF_NONCLIENT)) ;
l_grpSrc.Releas eHdc();

l_bmpPanel.Save (filename);
}

I had to set AutoScrollPosit ion to (0,0), but I don't think it's
against the user-friendliness of the application.
ForcePaint is simple:

public void ForcePaint(Pain tEventArgs pe)
{
OnPaint(pe);
}

It's only needed because I have some custom painting in this OnPaint
and that was only drawn in the visible area of the panel, I don't
really know why. All children have custom painting as well, and those
drawings are done both on visible and invisible area. Although I don't
think it's elegant programming, I couldn't think of any other
solution.

So thank you again for the help, Ben!
Regards, Chris

Ben Voigt [C++ MVP] írta:
Did you Dispose the Graphics object before trying to use the Bitmap?

"she_prog" <pu*********@ya hoo.comwrote in message
news:11******** **************@ k79g2000hse.goo glegroups.com.. .
Great, now I can see stepping through OnPaint when debugging. Still,
the resulted Bitmap is all blank :(
Right after SendMessage I'm calling l_bmp.Save(file name); so there's
no code overdrawing the result of SendMessage. The same OnPaint draws
the panel and its children just fine onto the screen.
Right now I'm just testing without scrollbars, so that shouldn't cause
the problem. I might try to do a small sample application to try to
narrow down the cause.

Thank you very much for the help! If you could think of anything that
could cause the problem, please let me know!
Regards,
Chris

Ben Voigt [C++ MVP] írta:
You should also use the CLIENT and CHILDREN flags (OR-ed together), to
get
the content of the window and all contained windows.
"she_prog" <pu*********@ya hoo.comwrote in message
news:11******** **************@ c77g2000hse.goo glegroups.com.. .
Thank you very much, Ben!
I tried your solution, but it didn't work for me. Maybe the problem is
that I'm trying to save a class of my own, derived from Panel and
OnPaint method is overriden in this new class. When trying to debug,
OnPaint is not called as a result of SendMessage. Here's my code:

[DllImport("user 32.dll")]
public static extern int SendMessage(
IntPtr hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);

const int WM_PRINT = 0x317;

[Flags]
enum DrawingOptions
{
PRF_CHECKVISIBL E = 0x01,
PRF_NONCLIENT = 0x02,
PRF_CLIENT = 0x04,
PRF_ERASEBKGND = 0x08,
PRF_CHILDREN = 0x10,
PRF_OWNED = 0x20
}

...
Bitmap l_bmp = new Bitmap(c_panel. Width, c_panel.Height) ;
Graphics l_grp = Graphics.FromIm age(l_bmp);
IntPtr hdc = l_grp.GetHdc();
SendMessage(c_p anel.Handle, WM_PRINT, (int)hdc,
(int)DrawingOpt ions.PRF_OWNED) ;

Could you please advice further?
Regards,
Chris

Ben Voigt [C++ MVP] írta:
"she_prog" <pu*********@ya hoo.comwrote in message
news:11******** **************@ m36g2000hse.goo glegroups.com.. .
Dear All,

I need to save the content of a panel to a bitmap. The panel can
have
many child controls which also need to be saved. The problem would
be
solved if I could have the panel saved to a Graphics object, which
is
the same as if I'd need to print it. It'd be easy using
Control.DrawToB itmap, but I also need the invisible part of the
panel
(which is hidden because of scrolling) and DrawToBitmap just takes a
screenshot.

I've been reading about this. Many samples uses BitBlt, but that
also
skips the invisible part. I've also seen some posts stating that
this
is not a simple thing and I'd need to programatically scroll to all
needed position and combine the screenshots taken from all the
scroll-
positions. These posts were from 2003 or 2004.

So my question: Is there any new solutions provided by VS2005? Or do
I
No, there aren't. However, Windows has always had a solution for
this:
WM_PRINT.
>
Try creating a bitmap of the appropriate size, getting a Graphics for
it,
get the HDC, and SendMessage WM_PRINT to the window and each of its
children. That will usually get you the results you are looking for.
>
have to do this multiple scrolling (which produces flickering)?

Thank you for any help!

Chris
Jun 12 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1778
by: TheTenor | last post by:
I have a page with a graphic. I want to be able to define the graphics such that it is not saved when the viewer saves the page to his local drive. I'm trying to avoid having a seperate folder created just for the graphic when the page is saved. The page is an asp page that is used to access a database record. I have the page title convey the record name so that the user can save the page and it will be saved with the record name. I just...
1
3417
by: Laxmikant Rashinkar | last post by:
Hi, I am drawing some graphical data (such as waveforms and graphs) on a panel. I would like to save this graphical data as a jpeg image. How does one do this in C#? thank you for your help. LK
21
1561
by: Michael Turner | last post by:
Hi Guys I have several images that will be used over and over again on different forms in the same place, I have decided to create a control to save space/time in development, I have create a control which inherits the panel and added three panel control which host the 3 background images ( one to the left the other to the right and one to fill the gap) now with this control textboxes will be placed on these controls once they are added...
2
2172
by: Peteroid | last post by:
When the application I'm working on is run it creates a panel with a Paint event customized to draw primitives (circles, rectangles, etc.), places the panel on a form, and then launches the form. The weird part is, the panel, in the instant it becomes visible, seems to have an image of what this panel had in it the LAST TIME THE APPLICATION WAS RUN! Since this panel is created anew every time the application is run ('natch), this seems...
6
6458
by: Paul_Madden | last post by:
I have a System.Windows.Forms.Form onto which I add a Panel (MyPanel) directly derived from System.Windows.Forms.Panel. Here are the important code fragments ... public class MyPanel : Panel { ............................. public MyPanel () : base ()
6
3250
by: Chris Dunaway | last post by:
The method for printing documents in .Net can be confusing, especially for newer users. I would like to create a way to simplify this process. My idea would be implemented using a PrintDocument (much like the current model), but my PrintDocument would have a Pages collection such that each time you need to have an additional page, you would just add another page to the collection and then use the page object for the actual drawing etc. ...
11
11279
by: dongarbage | last post by:
Hi there, I'm very much a C# novice. How do you do freehand drawing on a panel with a mouse in c#? Thanks, Don
8
2247
by: vicky87.eie | last post by:
I used a picture box to draw lines and rectangle using its graphics object in paint event. Now i need to save those lines i have drawn and print them. I need to know how to save them. I tried image.save. But i didn't work...
5
5867
by: Adam Sandler | last post by:
Hello, I took a look at http://msdn.microsoft.com/en-us/library/aa287531(VS.71).aspx which gives a code sample on how to print a form. To print a panel, I just substituted 'p' for 'this': private void CaptureScreen(Panel p) { Graphics myGraphics = p.CreateGraphics(); Size s = p.Size;
0
9865
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9708
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10932
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10609
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7025
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5881
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4083
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.