关于c#直接打印问题
我用的是PrintDocument控件,能不能直接打印,不弹出对话框,打印panel里面的内容啊。 panel的id是 "panel1" --------------------编程问答-------------------- 不可以,必须在打印时用GDI+画。 --------------------编程问答-------------------- 楼上的朋友,你好,能不能具体一点啊 --------------------编程问答-------------------- http://www.cnblogs.com/chris1943/archive/2008/03/04/1090719.html这是个示例,可以把对话框部分去掉,不弹出对话框直接打印你下面画的内容。 --------------------编程问答-------------------- 这是我的一个例子
--------------------编程问答--------------------
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;
}
}
--------------------编程问答-------------------- 我要的是,不显示打印对话框,直接打印 --------------------编程问答--------------------
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);
}
}
}
对,我发的这个代码就是没有对话框,那个本来就是可有可无的.
补充:.NET技术 , C#