关于打印winform窗口的问题,求助

LAST_MAN 2013-03-12 08:43:31
在winform界面上添加了个groupBox1,如下图


然后按打印预览,却出现这样


代码如下

public partial class print : Form
{
public print()
{
InitializeComponent();
this.printDocument1.OriginAtMargins = true;//启用页边距
this.pageSetupDialog1.EnableMetric = true; //以毫米为单位


}

private void button3_Click(object sender, EventArgs e) //打印设置
{
this.pageSetupDialog1.ShowDialog();

}

private void button2_Click(object sender, EventArgs e) //打印
{
if (this.printDialog1.ShowDialog() == DialogResult.OK)
{
this.printDocument1.Print();
}

}

private void button1_Click(object sender, EventArgs e) //打印预览
{
printDialog1.Document = printDocument1;
this.printPreviewDialog1.ShowDialog();



}

private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{

////打印内容 为 整个Form
//Image myFormImage;
//myFormImage = new Bitmap(this.Width, this.Height);
//Graphics g = Graphics.FromImage(myFormImage);
//g.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, this.Size);
//e.Graphics.DrawImage(myFormImage, 0, 0);

//打印内容 为 局部的 this.groupBox1
Bitmap _NewBitmap = new Bitmap(groupBox1.Width, groupBox1.Height);
groupBox1.DrawToBitmap(_NewBitmap, new Rectangle(0, 0, _NewBitmap.Width, _NewBitmap.Height));
e.Graphics.DrawImage(_NewBitmap, 0, 0, _NewBitmap.Width, _NewBitmap.Height);

////打印内容 为 自定义文本内容
//Font font = new Font("宋体", 12);
//Brush bru = Brushes.Blue;
//for (int i = 1; i <= 5; i++)
//{
// e.Graphics.DrawString("Hello world ", font, bru, i * 20, i * 20);
//}
}




请问哪里出问题了?应该怎么改才对?
...全文
2065 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
LAST_MAN 2013-03-12
  • 打赏
  • 举报
回复
引用 2 楼 assky124 的回复:
你确定上面的那些控件都在GroupBox中? _NewBitmap 打个断点,看看生成的图片对不对
是不是我先弄了GroupBox,然后将GroupBox至于控件底层的缘故?
assky124 2013-03-12
  • 打赏
  • 举报
回复
你确定上面的那些控件都在GroupBox中? _NewBitmap  打个断点,看看生成的图片对不对

110,534

社区成员

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

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

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