100分 C#打印窗体上的PANEL 调用API 发现打印并不完整

成都锦福工作室 2010-07-07 05:27:57
参照以前的文章,在打印时调用这个函数(其实就是把控件截图),不过我发现,当我需要打印一个PANEL时,如果PANEL上的控件过多,导致出现了横向滚动条,那么这个函数截取的图片是不完整的,请问大家有没有什么方法,使得打印一个比较大的控件时,能自适应呢?谢谢~
[DllImport( "gdi32.dll ")]
private static extern bool BitBlt
...全文
1272 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
bono123 2012-02-23
  • 打赏
  • 举报
回复
路过.............学习
wangl 2011-06-21
  • 打赏
  • 举报
回复
学习下。
上海瞰沃 2011-04-15
  • 打赏
  • 举报
回复
求了好多天的问题。。激动。。感激。。
freetd 2010-10-27
  • 打赏
  • 举报
回复
路过.............
捷哥1999 2010-07-07
  • 打赏
  • 举报
回复
上面这篇文章使用的画出控件去打印的方法,这是总的画控件函数:
private void DrawControl(Control ctl, Point ptOffset, Graphics g)
{
// Cycle through each control on the form and paint

// it on the graphics object

foreach (Control c in ctl.Controls)
{
// Skip invisible controls

if (!c.Visible)
continue;

// Calculate the location offset for the control - this offset is

// relative to the original offset passed in

Point p = new Point(c.Left, c.Top);
p.Offset(ptOffset.X, ptOffset.Y);

// Draw the control

if (c is GroupBox)
DrawGroupBox((GroupBox)c, p, g);
else if (c is Button)
DrawButton((Button)c, p, g);
else if (c is TextBox)
DrawTextBox((TextBox)c, p, g);
else if (c is CheckBox)
DrawCheckBox((CheckBox)c, p, g);
else if (c is Label)
DrawLabel((Label)c, p, g);
else if (c is ComboBox)
DrawComboBox((ComboBox)c, p, g);
else if (c is RadioButton)
DrawRadioButton((RadioButton)c, p, g);
else
return;

// Draw the controls within this control

DrawControl(c, p, g);
}
}


这是画RadioButton控件的方法:
private void DrawRadioButton(RadioButton rdo, Point p, Graphics g)
{
// Setup the size of a RadioButton

Rectangle rRadioButton = new Rectangle(p.X, p.Y, 12, 12);

ControlPaint.DrawRadioButton(g, p.X,
p.Y + (rdo.Height / 2) - (rRadioButton.Height / 2),
rRadioButton.Width,
rRadioButton.Height,
(rdo.Checked ? ButtonState.Checked : ButtonState.Normal));

// RadioButton's text left justified & centered vertically

g.DrawString(rdo.Text,
rdo.Font,
new SolidBrush(rdo.ForeColor),
rRadioButton.Right + 1,
p.Y + (rdo.Height / 2) - (g.MeasureString(rdo.Text,
rdo.Font).Height / 2));
}
捷哥1999 2010-07-07
  • 打赏
  • 举报
回复
这是使用API打印窗体控件的一个实现,你可以参考!



源代码下载,需要先注册用户!
文章地址
hyblusea 2010-07-07
  • 打赏
  • 举报
回复
对于没有滚动条的控件, 截图,也不需要调用 API的

控件.DrawToBitmap()
hyblusea 2010-07-07
  • 打赏
  • 举报
回复
yypf2540017 2010-07-07
  • 打赏
  • 举报
回复
帮顶吧

110,549

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

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

试试用AI创作助手写篇文章吧