private void 打印ToolStripMenuItem_Click(object sender, EventArgs e)
{
//管理打印预处理
printDocument.BeginPrint += new PrintEventHandler(printDocument_BeginPrint);
//关联打印代码
printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
//定义打印对话框
PrintDialog printDialog = new PrintDialog();
//获得用户输入
DialogResult dr = PrintDialog.ShowDialog();
//如果确认则打印
if (dr==DialogResult.OK)/*Error An object reference is required for the non-static field, method, or property 'System.Windows.Forms.CommonDialog.ShowDialog()'*/ {
printDocument.Print();
}
else
{
return;
}
}
/// <summary>
/// 打印前预处理代码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void printDocument_BeginPrint(object sender, PrintEventArgs e)
{
//设置打印文本
text = richTextBox1.Text;
}
/// <summary>
/// 打印文档代码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void printDocument_PrintPage(object sender, PrintEventArgs e)
{
//用DrawString方法输出字符串
e.Graphics.DrawString(text,new Font("Arial",10),Brushes.Black,20,20);/*'System.Drawing.Printing.PrintEventArgs' does not contain a definition for 'Graphics' and no extension method 'Graphics' accepting a first argument of type 'System.Drawing.Printing.PrintEventArgs' could be found (are you missing a using directive or an assembly reference?)*/
}
{
//管理打印预处理
printDocument.BeginPrint += new PrintEventHandler(printDocument_BeginPrint);
//关联打印代码
printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
//定义打印对话框
PrintDialog printDialog = new PrintDialog();
//获得用户输入
DialogResult dr = PrintDialog.ShowDialog();
//如果确认则打印
if (dr==DialogResult.OK)/*Error An object reference is required for the non-static field, method, or property 'System.Windows.Forms.CommonDialog.ShowDialog()'*/ {
printDocument.Print();
}
else
{
return;
}
}
/// <summary>
/// 打印前预处理代码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void printDocument_BeginPrint(object sender, PrintEventArgs e)
{
//设置打印文本
text = richTextBox1.Text;
}
/// <summary>
/// 打印文档代码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void printDocument_PrintPage(object sender, PrintEventArgs e)
{
//用DrawString方法输出字符串
e.Graphics.DrawString(text,new Font("Arial",10),Brushes.Black,20,20);/*'System.Drawing.Printing.PrintEventArgs' does not contain a definition for 'Graphics' and no extension method 'Graphics' accepting a first argument of type 'System.Drawing.Printing.PrintEventArgs' could be found (are you missing a using directive or an assembly reference?)*/
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货