G
Guest
I am working on a Windows Forms application that uses the MDI style. I am
using C# in VS.NET 2003 . I want to provide a feature that allows the user
to capture the entire form's image and save it to a file.
The problem I have run into is that I am currently only capturing the client
area of the form. This doesn't include the form's title bar and borders. I
need to include the title bar in the image since the title bar's text has
useful information. I have included the code I am using to generate the
image below.
How can I modify this code to capture the entire form?
Thanks,
Dave
======== Code ========
public void CreateFormGraphic( Form form, string filename )
{
Graphics graphic = form.CreateGraphics(); // Client area only!!!???
Size s = form.ClientSize;
this.displayImage = new Bitmap( s.Width, s.Height, graphic );
Graphics memGraphic = Graphics.FromImage( this.displayImage );
IntPtr dc1 = graphic.GetHdc();
IntPtr dc2 = memGraphic.GetHdc();
User32DllImports.BitBlt( dc2, 0, 0, s.Width, s.Height, dc1, 0, 0,
User32DllImports.SRCCOPY );
graphic.ReleaseHdc( dc1 );
memGraphic.ReleaseHdc( dc2 );
this.displayImage.Save( filename, ImageFormat.Jpeg );
this.displayImage.Dispose();
this.displayImage = null;
}
=====================
using C# in VS.NET 2003 . I want to provide a feature that allows the user
to capture the entire form's image and save it to a file.
The problem I have run into is that I am currently only capturing the client
area of the form. This doesn't include the form's title bar and borders. I
need to include the title bar in the image since the title bar's text has
useful information. I have included the code I am using to generate the
image below.
How can I modify this code to capture the entire form?
Thanks,
Dave
======== Code ========
public void CreateFormGraphic( Form form, string filename )
{
Graphics graphic = form.CreateGraphics(); // Client area only!!!???
Size s = form.ClientSize;
this.displayImage = new Bitmap( s.Width, s.Height, graphic );
Graphics memGraphic = Graphics.FromImage( this.displayImage );
IntPtr dc1 = graphic.GetHdc();
IntPtr dc2 = memGraphic.GetHdc();
User32DllImports.BitBlt( dc2, 0, 0, s.Width, s.Height, dc1, 0, 0,
User32DllImports.SRCCOPY );
graphic.ReleaseHdc( dc1 );
memGraphic.ReleaseHdc( dc2 );
this.displayImage.Save( filename, ImageFormat.Jpeg );
this.displayImage.Dispose();
this.displayImage = null;
}
=====================