关于c#直接打印问题

gjwcy510 2011-03-10 03:26:20
我用的是PrintDocument控件,能不能直接打印,不弹出对话框,打印panel里面的内容啊。 panel的id是 "panel1"
...全文
289 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lizhibin11 2011-03-10
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 gjwcy510 的回复:]
我要的是,不显示打印对话框,直接打印
[/Quote]
对,我发的这个代码就是没有对话框,那个本来就是可有可无的.
gjwcy510 2011-03-10
  • 打赏
  • 举报
回复
我要的是,不显示打印对话框,直接打印
lizhibin11 2011-03-10
  • 打赏
  • 举报
回复

class Printb
{
public static void rowprint(int pointheight, int height, object[] chars, int[] widths, Graphics gp, StringFormat df)
{
Font cellFont = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134)));
rowprint(pointheight, height, chars, widths, gp, df, cellFont);
}
public static void rowprint(int pointheight, int height, object[] chars, int[] widths, Graphics gp, StringFormat df, Font ft)
{
int[] kb = new int[0];
rowprint(pointheight, height, chars, widths, gp, df, ft, kb);
}
public static void rowprint(int pointheight, int height, object[] chars, int[] widths, Graphics gp, StringFormat df, Font ft, int[] kb)
{
int pointwidth = 30;
for (int i = 0; i < chars.Length; i++)
{
if (i > 0)
pointwidth = pointwidth + widths[i - 1];
PrintCell pc = new PrintCell(chars[i].ToString(), widths[i], height, ft);
Point pt = new Point(pointwidth, pointheight);
Rectangle rt = new Rectangle(pt.X, pt.Y, pc.Width, pc.Height);
if (kb.Contains(i) == false)
{
gp.FillRectangle(Brushes.White, rt);
gp.DrawRectangle(Pens.Black, rt);
}
gp.DrawString(chars[i].ToString(), ft, Brushes.Black, rt, df);
}
}
}
lizhibin11 2011-03-10
  • 打赏
  • 举报
回复
这是我的一个例子

public static int index = 0;
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Graphics gp = e.Graphics;
int[] cellWidth = { 45, 55, 95, 55, 100, 64, 64, 64, 64, 64, 55 };
System.Drawing.Font headFont = new System.Drawing.Font("宋体", 20, System.Drawing.FontStyle.Regular);
SolidBrush brush = new SolidBrush(System.Drawing.Color.Black);//刷子
StringFormat drawFormat = new StringFormat();//打印的字符串的格式
drawFormat.Alignment = StringAlignment.Center;
drawFormat.LineAlignment = StringAlignment.Center;
int rowPerPage = 33;
string head = kssj.Text + "至" + jssj.Text + "司机工资表";
gp.DrawString(head, headFont, brush, 250, 100);

object[] pchars = { "序号", "个人编码", "姓名", "趟数", "应发工资", "保费", "水费", "扣款", "退款", "实发工资", "备注" };
Printb.rowprint(100 + headFont.Height, 50, pchars, cellWidth, gp, drawFormat);
int currentRow = 0;
while (currentRow < rowPerPage && index < dggz.Items.Count)
{
if (index == dggz.Items.Count)
break;
pchars = ((DataView)dggz.ItemsSource).Table.Rows[index].ItemArray;
Printb.rowprint(150 + headFont.Height + currentRow * 26, 26, pchars, cellWidth, gp, drawFormat);
currentRow++;
index++;
}
if (index < dggz.Items.Count)
{
e.HasMorePages = true;
}
else
{
e.HasMorePages = false;
index = 0;
((PrintDocument)sender).PrintPage -= printDocument1_PrintPage;
}
}
lizhibin11 2011-03-10
  • 打赏
  • 举报
回复
http://www.cnblogs.com/chris1943/archive/2008/03/04/1090719.html
这是个示例,可以把对话框部分去掉,不弹出对话框直接打印你下面画的内容。
gjwcy510 2011-03-10
  • 打赏
  • 举报
回复
楼上的朋友,你好,能不能具体一点啊
lizhibin11 2011-03-10
  • 打赏
  • 举报
回复
不可以,必须在打印时用GDI+画。

110,536

社区成员

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

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

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