C#打印问题
就一个简单打印,打印出几句话就行,我不知道内容怎么加进去,这个是我随便找的,界面出来了,但是打不出来(没写打印内容,不知道怎么加)PrintDialogprintdial...
就一个简单打印,打印出几句话就行,我不知道内容怎么加进去,这个是我随便找的,界面出来了,但是打不出来(没写打印内容,不知道怎么加)
PrintDialog printdialog1 = new PrintDialog();
PrintDocument doctoprint =new PrintDocument();
doctoprint.DocumentName = "打印标题";
printdialog1.Document = doctoprint;
doctoprint.Print();
DialogResult result = printdialog1.ShowDialog();
求代码赐教 展开
PrintDialog printdialog1 = new PrintDialog();
PrintDocument doctoprint =new PrintDocument();
doctoprint.DocumentName = "打印标题";
printdialog1.Document = doctoprint;
doctoprint.Print();
DialogResult result = printdialog1.ShowDialog();
求代码赐教 展开
1个回答
展开全部
你没有定义打印内容,我这有个简单的代码,你可以参考一下:
//打印按钮事件
private void button1_Click_1(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(PrintPage);
if (this.storePageSettings != null)
{
pd.DefaultPageSettings = this.storePageSettings;
}
PrintDialog dlg = new PrintDialog();
dlg.Document = pd;
if (dlg.ShowDialog() == DialogResult.OK)
{
pd.Print();
}
}
//打印事件
private void PrintPage(Object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics;
PaintDocument(g);
e.HasMorePages = false;
}
/// <summary>
/// 打印输出定位
/// </summary>
/// <param ></param>
private void PaintDocument(Graphics g)
{
g.PageUnit = GraphicsUnit.Point;
//出口口岸
g.DrawString(grid1.Cell(2,2).Text.Trim(), new Font("Arial",8f), Brushes.Black, new Point(80, 180));//POINT定位
}
//打印按钮事件
private void button1_Click_1(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(PrintPage);
if (this.storePageSettings != null)
{
pd.DefaultPageSettings = this.storePageSettings;
}
PrintDialog dlg = new PrintDialog();
dlg.Document = pd;
if (dlg.ShowDialog() == DialogResult.OK)
{
pd.Print();
}
}
//打印事件
private void PrintPage(Object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics;
PaintDocument(g);
e.HasMorePages = false;
}
/// <summary>
/// 打印输出定位
/// </summary>
/// <param ></param>
private void PaintDocument(Graphics g)
{
g.PageUnit = GraphicsUnit.Point;
//出口口岸
g.DrawString(grid1.Cell(2,2).Text.Trim(), new Font("Arial",8f), Brushes.Black, new Point(80, 180));//POINT定位
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询