c# 利用windows打印机打印问题
privatevoidprintDocument1_PrintPage(objectsender,System.Drawing.Printing.PrintPageEve...
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
SqlConnection con = new SqlConnection(constr);
con.Open();
string sqlstr = string.Format("select tbid from hy_dbfp_j where tbcnnm = '{0}'", this.comboBox1.Text);
SqlDataAdapter ada = new SqlDataAdapter(sqlstr, con);
DataSet ds = new DataSet();
ada.Fill(ds);
string sqlstr1 = string.Format("select * from {0} order by stcd", ds.Tables[0].Rows[0].ItemArray[0].ToString());
SqlCommand com = new SqlCommand(sqlstr1,con);
SqlDataReader myread = com.ExecuteReader();
}
private void button2_Click(object sender, EventArgs e)
{
printDialog1.ShowDialog();
printPreviewDialog1.Document = this.printDocument1;
printPreviewDialog1.ShowDialog();
}现在是可以调用打印对话框。可是预览出来的是一张白纸
请高手给改改 展开
{
SqlConnection con = new SqlConnection(constr);
con.Open();
string sqlstr = string.Format("select tbid from hy_dbfp_j where tbcnnm = '{0}'", this.comboBox1.Text);
SqlDataAdapter ada = new SqlDataAdapter(sqlstr, con);
DataSet ds = new DataSet();
ada.Fill(ds);
string sqlstr1 = string.Format("select * from {0} order by stcd", ds.Tables[0].Rows[0].ItemArray[0].ToString());
SqlCommand com = new SqlCommand(sqlstr1,con);
SqlDataReader myread = com.ExecuteReader();
}
private void button2_Click(object sender, EventArgs e)
{
printDialog1.ShowDialog();
printPreviewDialog1.Document = this.printDocument1;
printPreviewDialog1.ShowDialog();
}现在是可以调用打印对话框。可是预览出来的是一张白纸
请高手给改改 展开
展开全部
选择打印机然后打印文件
使用 PrintDialog 组件选择要使用的打印机。
在下面的代码示例中,有两个要处理的事件。第一个事件是 Button 控件的 Click 事件,在该事件中,PrintDialog 类被实例化,并且用户选择的打印机在敏郑伍 DialogResult 属性中捕获。
第桥或二个事件是 PrintDocument 组件的 PrintPage 事件,在该事件中,将一个示例丛伏文档打印到指定的打印机。
Visual Basic 复制代码
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim PrintDialog1 As New PrintDialog()
PrintDialog1.Document = PrintDocument1
Dim result As DialogResult = PrintDialog1.ShowDialog()
If (result = DialogResult.OK) Then
PrintDocument1.Print()
End If
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.FillRectangle(Brushes.Red, New Rectangle(500, 500, 500, 500))
End Sub
C# 复制代码
private void button1_Click(object sender, System.EventArgs e)
{
PrintDialog printDialog1 = new PrintDialog();
printDialog1.Document = printDocument1;
DialogResult result = printDialog1.ShowDialog();
if (result == DialogResult.OK)
{
printDocument1.Print();
}
}
private void printDocument1_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Red,
new Rectangle(500, 500, 500, 500));
}
J# 复制代码
private void button1_Click(Object sender, System.EventArgs e)
{
PrintDialog printDialog1 = new PrintDialog();
printDialog1.set_Document(printDocument1);
DialogResult result = printDialog1.ShowDialog();
if (result == DialogResult.OK)
{
printDocument1.Print();
}
}
private void printDocument1_PrintPage(Object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.get_Graphics().FillRectangle(Brushes.get_Red(),
new Rectangle(500, 500, 500, 500));
}
Visual C++ 复制代码
private:
void button1_Click(System::Object ^ sender,
System::EventArgs ^ e)
{
PrintDialog ^ printDialog1 = gcnew PrintDialog();
printDialog1->Document = printDocument1;
System::Windows::Forms::DialogResult result =
printDialog1->ShowDialog();
if (result == DialogResult::OK)
{
printDocument1->Print();
}
}
private:
void printDocument1_PrintPage(System::Object ^ sender,
System::Drawing::Printing::PrintPageEventArgs ^ e)
{
e->Graphics->FillRectangle(Brushes::Red,
Rectangle(500, 500, 500, 500));
}
((Visual C#、Visual J# 和 Visual C++)在窗体的构造函数中放入以下代码以注册事件处理程序。
C#
this.printDocument1.PrintPage += new
System.Drawing.Printing.PrintPageEventHandler
(this.printDocument1_PrintPage);
this.button1.Click += new System.EventHandler(this.button1_Click);
使用 PrintDialog 组件选择要使用的打印机。
在下面的代码示例中,有两个要处理的事件。第一个事件是 Button 控件的 Click 事件,在该事件中,PrintDialog 类被实例化,并且用户选择的打印机在敏郑伍 DialogResult 属性中捕获。
第桥或二个事件是 PrintDocument 组件的 PrintPage 事件,在该事件中,将一个示例丛伏文档打印到指定的打印机。
Visual Basic 复制代码
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim PrintDialog1 As New PrintDialog()
PrintDialog1.Document = PrintDocument1
Dim result As DialogResult = PrintDialog1.ShowDialog()
If (result = DialogResult.OK) Then
PrintDocument1.Print()
End If
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.FillRectangle(Brushes.Red, New Rectangle(500, 500, 500, 500))
End Sub
C# 复制代码
private void button1_Click(object sender, System.EventArgs e)
{
PrintDialog printDialog1 = new PrintDialog();
printDialog1.Document = printDocument1;
DialogResult result = printDialog1.ShowDialog();
if (result == DialogResult.OK)
{
printDocument1.Print();
}
}
private void printDocument1_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Red,
new Rectangle(500, 500, 500, 500));
}
J# 复制代码
private void button1_Click(Object sender, System.EventArgs e)
{
PrintDialog printDialog1 = new PrintDialog();
printDialog1.set_Document(printDocument1);
DialogResult result = printDialog1.ShowDialog();
if (result == DialogResult.OK)
{
printDocument1.Print();
}
}
private void printDocument1_PrintPage(Object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.get_Graphics().FillRectangle(Brushes.get_Red(),
new Rectangle(500, 500, 500, 500));
}
Visual C++ 复制代码
private:
void button1_Click(System::Object ^ sender,
System::EventArgs ^ e)
{
PrintDialog ^ printDialog1 = gcnew PrintDialog();
printDialog1->Document = printDocument1;
System::Windows::Forms::DialogResult result =
printDialog1->ShowDialog();
if (result == DialogResult::OK)
{
printDocument1->Print();
}
}
private:
void printDocument1_PrintPage(System::Object ^ sender,
System::Drawing::Printing::PrintPageEventArgs ^ e)
{
e->Graphics->FillRectangle(Brushes::Red,
Rectangle(500, 500, 500, 500));
}
((Visual C#、Visual J# 和 Visual C++)在窗体的构造函数中放入以下代码以注册事件处理程序。
C#
this.printDocument1.PrintPage += new
System.Drawing.Printing.PrintPageEventHandler
(this.printDocument1_PrintPage);
this.button1.Click += new System.EventHandler(this.button1_Click);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询