http://community.csdn.net/Expert/topic/3590/3590767.xml?temp=.6344568http://community.csdn.net/Expert/topic/3575/3575011.xml?temp=.2797663http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.aspvoid DrawForm(Graphics g, int resX, int resY)
{
g.FillRectangle(new SolidBrush(this.BackColor), 0, 0, this.Width, this.Height);
float scale = resX/ScreenResolution;
foreach (Control c in Controls)
{
string strType = c.GetType().ToString().Substring(c.GetType().ToString().LastIndexOf(".") + 1);
switch (strType)
{
case "Button":
Button b = (Button)c;
ControlPaint.DrawButton(g, ((Button)c).Left, ((Button)c).Top, ((Button)c).Width, ((Button)c).Height, ButtonState.Normal);
g.DrawString(b.Text, b.Font, new SolidBrush(b.ForeColor), b.Left + b.Width/2 - g.MeasureString(b.Text, b.Font).Width/2, b.Top  + b.Height/2  - g.MeasureString("a", b.Font).Height/2,  new StringFormat());
break;
case "TextBox":
TextBox t = (TextBox)c;
ControlPaint.DrawButton(g, t.Left, t.Top, t.Width, t.Height, ButtonState.Pushed );
g.FillRectangle(new SolidBrush(t.BackColor), t.Left+1, t.Top + 1, t.Width+2, t.Height -2);
g.DrawString(t.Text, t.Font, new SolidBrush(t.ForeColor), t.Left + 2, t.Top  + t.Height/2  - g.MeasureString("a", t.Font).Height/2,  new StringFormat());
break;
case "CheckBox":
CheckBox cb = (CheckBox)c;
if (cb.Checked)
ControlPaint.DrawCheckBox(g, cb.Left, cb.Top, cb.Height/2, cb.Height/2, ButtonState.Checked);
else
ControlPaint.DrawCheckBox(g, cb.Left, cb.Top, cb.Height/2, cb.Height/2, ButtonState.Normal);
g.DrawString(cb.Text, cb.Font, new SolidBrush(cb.ForeColor), cb.Right -cb.Height - g.MeasureString(cb.Text, cb.Font).Width , cb.Top,  new StringFormat());
break;
}
}
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
PrinterResolution pr = e.PageSettings.PrinterResolution;
DrawForm(e.Graphics, pr.X, pr.Y);
}
float ScreenResolution = 96.0f;
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
ScreenResolution = e.Graphics.DpiX;
}
添加以上几个事件。
在窗体上添加如下控件:private System.Windows.Forms.PrintPreviewDialog printPreviewDialog1;
private System.Drawing.Printing.PrintDocument printDocument1;
其中,窗口上要添加它的Paint事件也就是上面的Form1_Paint,printDocument1要添加它的PrintPage事件,也就是上面的printDocument1_PrintPage事件
然后的话,用菜单或按钮调用printDocument1.Print();
就可以进行打印了。也可以直接调用printPreviewDialog1.ShowDialog()事件就可以进行打印预览。
:)

解决方案 »

  1.   

    我原来也遇到过这样的问题我当时的原因是
    报表定义的纸张和实际的纸张的尺寸不太对应
    或者是打印属性设置不正确
    楼主在这方面试一试看看
      

  2.   

    可是我把表格都正常打印出来了,就是不给我先是我添加的数据,应该不是你那个问题,可能和数据连结那里有点问题,郁闷~~~~~~~~~~~~~~~~
      

  3.   

    谢谢女娃哈哈,看了他的代码,有了灵感,搞定了。谢谢啦,实现我的诺言,分给你。