E
emorgoch
I have a .NET 1.1 windows form ap from which I'm trying to allow the
user to print out the form. I use the bitblt function in gdi32.dll to
capture the image of the form and turn it into a bitmap for printing.
The problem that I'm currently having is that the print preview dialog
on the form does not show the page margins when it displays the
preview. Relevent code is attached.
As well, if someone know how I can properly scale the image to fin on
to the page if it's too big, that would be a great help too.
Thanks,
Evan
Bitmap formImage;
private PrintDocument pd = new PrintDocument ();
private PrintPreviewDialog printPreviewDialog = new
PrintPreviewDialog();
private System.Windows.Forms.PageSetupDialog pageSetupDialog;
printPreviewDialog.Document = this.pd;
private void printMenuItem_Click(object sender, System.EventArgs e) {
this.GetFormImage();
pd.Print();
}
private void pd_PrintPage (object sender,
System.Drawing.Printing.PrintPageEventArgs e) {
e.Graphics.DrawImage (this.formImage, 0, 0);
}
private void GetFormImage() {
Graphics mygraphics = this.CreateGraphics();
this.formImage = new Bitmap (this.Size.Width, this.Size.Height,
mygraphics);
Graphics memoryGraphics = Graphics.FromImage(this.formImage);
int bordersize = (this.Width - this.ClientRectangle.Width) / 2;
int titlebarHeight = (this.Height - this.ClientRectangle.Height) -
bordersize;
IntPtr sourceHandle = mygraphics.GetHdc();
IntPtr destinationHandle = memoryGraphics.GetHdc();
BitBlt(destinationHandle, pd.DefaultPageSettings.Bounds.X,
pd.DefaultPageSettings.Bounds.Y,
this.Width, this.Height, sourceHandle, 0 - bordersize, 0 -
titlebarHeight, 13369376);
mygraphics.ReleaseHdc(sourceHandle);
memoryGraphics.ReleaseHdc(destinationHandle);
}
[DllImport("gdi32.dll")]
static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int
nWidth,
int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
private void printPreviewMenuItem_Click(object sender,
System.EventArgs e) {
this.GetFormImage();
printPreviewDialog.ShowDialog();
}
private void pageSetupMenuItem_Click(object sender, System.EventArgs
e) {
this.GetFormImage();
this.pageSetupDialog.ShowDialog();
}
user to print out the form. I use the bitblt function in gdi32.dll to
capture the image of the form and turn it into a bitmap for printing.
The problem that I'm currently having is that the print preview dialog
on the form does not show the page margins when it displays the
preview. Relevent code is attached.
As well, if someone know how I can properly scale the image to fin on
to the page if it's too big, that would be a great help too.
Thanks,
Evan
Bitmap formImage;
private PrintDocument pd = new PrintDocument ();
private PrintPreviewDialog printPreviewDialog = new
PrintPreviewDialog();
private System.Windows.Forms.PageSetupDialog pageSetupDialog;
printPreviewDialog.Document = this.pd;
private void printMenuItem_Click(object sender, System.EventArgs e) {
this.GetFormImage();
pd.Print();
}
private void pd_PrintPage (object sender,
System.Drawing.Printing.PrintPageEventArgs e) {
e.Graphics.DrawImage (this.formImage, 0, 0);
}
private void GetFormImage() {
Graphics mygraphics = this.CreateGraphics();
this.formImage = new Bitmap (this.Size.Width, this.Size.Height,
mygraphics);
Graphics memoryGraphics = Graphics.FromImage(this.formImage);
int bordersize = (this.Width - this.ClientRectangle.Width) / 2;
int titlebarHeight = (this.Height - this.ClientRectangle.Height) -
bordersize;
IntPtr sourceHandle = mygraphics.GetHdc();
IntPtr destinationHandle = memoryGraphics.GetHdc();
BitBlt(destinationHandle, pd.DefaultPageSettings.Bounds.X,
pd.DefaultPageSettings.Bounds.Y,
this.Width, this.Height, sourceHandle, 0 - bordersize, 0 -
titlebarHeight, 13369376);
mygraphics.ReleaseHdc(sourceHandle);
memoryGraphics.ReleaseHdc(destinationHandle);
}
[DllImport("gdi32.dll")]
static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int
nWidth,
int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
private void printPreviewMenuItem_Click(object sender,
System.EventArgs e) {
this.GetFormImage();
printPreviewDialog.ShowDialog();
}
private void pageSetupMenuItem_Click(object sender, System.EventArgs
e) {
this.GetFormImage();
this.pageSetupDialog.ShowDialog();
}