请教各位高手。。。

jixiancai 2003-07-28 02:34:57
请教各位高手:
本人使用Visual Studio C#.net实现打印时的页面设置功能
1.当使用如下语句设置页面尺寸时,就会出错,因为Kind属性是只读的
printDocument1.DefaultPageSettings.PaperSize.Kind =PaperKind.B5;
请问如何将页面尺寸设置成B5或者其它纸型?

2.当使用PageSetupDialog类显示和获取用户的页面设置参数时,请问
如何将对话框中的默认纸型大小改为B5或者其它纸型(而不是A4)?

3.printDocument1.PrinterSettings.DefaultPageSettings.PaperSize与
printDocument1.DefaultPageSettings.PaperSize有何区别?
更改纸型大小时两者是否都需要进行设置?

谢谢各位!!!
...全文
19 1 打赏 收藏 举报
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
雪狼1234567 2003-07-28
  • 打赏
  • 举报
回复
看看这个,是否有帮助,
private void DrawAll(Graphics g)
{
// Create an alignment object that aligns text to the right side
// for calculations
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Far;

// Force autoscroll to start printing from the origin
this.AutoScrollPosition = new Point(0,0);

// Set up a source rectangle based on the image size
RectangleF srcRect = new Rectangle(0, 0, pictureBox1.Image.Width, pictureBox1.Image.Height);

// Set up a destination rectangle based on the paper size
int nWidth = printDocument1.PrinterSettings.DefaultPageSettings.PaperSize.Width;
int nHeight = printDocument1.PrinterSettings.DefaultPageSettings.PaperSize.Height;
RectangleF destRect = new Rectangle(0, 0, nWidth, nHeight);

// Draw the bitmap of the blank 1040EZ form
g.DrawImage(HiResImage, destRect, srcRect, GraphicsUnit.Pixel);

// Calculate the scale of the image against the paper so we
// can correctly place the text on top of the image from the
// controls.
float scalex = destRect.Width/srcRect.Width;
float scaley = destRect.Height/srcRect.Height;

// Cycle through each control and draw its contents
foreach (Control c in Controls)
{
// Determine the control type
string strType = c.GetType().ToString().Substring(c.GetType().ToString().LastIndexOf(".") + 1);
if (strType == "TextBox")
{
TextBox theText = (TextBox)c;

// check the alignment of the TextBox. If the Alignment is
// Right Aligned, calculated the Layout Rectangle and draw
// the text right aligned inside the Rectangle
if (theText.TextAlign.ToString() == "Left")
g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left*scalex, theText.Bounds.Top * scaley,
new StringFormat());
else
{
RectangleF LayoutRect = new RectangleF(theText.Bounds.Left*scalex, theText.Bounds.Top*scaley,
theText.Bounds.Width*scalex, theText.Bounds.Height*scaley);

g.DrawString(theText.Text, theText.Font, Brushes.Black, LayoutRect, sf);
}

}

// if the control is a checkbox and checked, draw an x inside
if (strType == "CheckBox")
{
CheckBox theCheck = (CheckBox)c;
Rectangle aRect = theCheck.Bounds;
if (theCheck.Checked)
{
g.DrawString("x", theCheck.Font, Brushes.Black,
theCheck.Left*scalex + 1, theCheck.Top*scaley + 1, new StringFormat());
}
}

} // end foreach control

}
发帖
C#

10.8w+

社区成员

.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
帖子事件
创建了帖子
2003-07-28 02:34
社区公告

让您成为最强悍的C#开发者