⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 10.5.txt

📁 《Microsoft Visual C# .NET 2003开发技巧大全》源代码
💻 TXT
字号:
Listing 10.5 Printing Documents
public class ImagePrintDocument : PrintDocument
{
private Image document;
public ImagePrintDocument( Image doc )
{
this.document = doc;
}
protected override void OnPrintPage(PrintPageEventArgs e)
{
// calculate information string and update header height
int headerHeight = e.MarginBounds.Y;
SizeF strSize = e.Graphics.MeasureString(
“Visual C# .Net Developer’s Cookbook Chapter 10”,
new Font(“Times New Roman”, 12), e.MarginBounds.Width);
headerHeight += (int) strSize.Height;
// draw the header string
e.Graphics.DrawString( “Visual C# .Net Developer’s Cookbook Chapter 10”,
new Font(“Times New Roman”, 12),
new SolidBrush(Color.Blue ),
new RectangleF(e.MarginBounds.X,
e.MarginBounds.Y,
strSize.Width, strSize.Height));
// draw a line under the string
e.Graphics.DrawLine( new Pen( new SolidBrush(Color.Black)),
e.MarginBounds.X, headerHeight+5,
e.MarginBounds.Width+e.MarginBounds.X,
headerHeight+5 );
headerHeight += 10;
// computer rectangle for image so it’s centered on
// page and scaled down if too large
Rectangle rcImage = new Rectangle(0,0,0,0);
if( document.Width >= e.MarginBounds.Width )
{
rcImage.X = e.MarginBounds.X;
rcImage.Width = e.MarginBounds.Width;
}
else
{
// image width is smaller than printed page so center it
rcImage.X = (int)((e.MarginBounds.Width/2)-(document.Width/2) +
e.MarginBounds.X);
rcImage.Width = document.Width;
}
if( document.Height >= e.MarginBounds.Height-headerHeight)
{
rcImage.Y = (int)(e.MarginBounds.Y + strSize.Height+20);
rcImage.Height = (int)(e.MarginBounds.Height)-headerHeight;
}
else
{
// image width is smaller than printed page so center it
rcImage.Y = (int)((e.MarginBounds.Height/2)-(document.Height/2));
rcImage.Height = document.Height;
}
// print the image
e.Graphics.DrawImage( document, rcImage, 0, 0, document.Width,
document.Height, GraphicsUnit.Pixel );
e.HasMorePages = false;
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -