读书人

问:带这样参数的函数怎么调用

发布时间: 2012-02-24 16:30:39 作者: rapoo

问:带这样参数的函数如何调用?
void printText(string text, System.Drawing.Printing.PrintPageEventArgs e);
如果想在一个按钮点击事件中调用上面这个函数,该如何调用?

[解决办法]
不是吧 都四遍了 那直接查msdn 吧
下列代码示例假定已经在 Form 上创建了名为 printButton 的 Button 和名为 pd 的 PrintDocument。确保此示例中 Button 的 Click 事件与 printButton_Click 方法关联,PrintDocument 的 PrintPage 事件与 pd_PrintPage 关联。示例中的 printButton_Click 方法调用引发 PrintPage 事件的 Print 方法,并打印在 pd_PrintPage 方法中指定的 .bmp 文件。若要运行该示例,请更改要打印的位图的路径。

C# code
private void printButton_Click(object sender, EventArgs e)  {   try    {     // Assumes the default printer.     pd.Print();   }     catch(Exception ex)    {     MessageBox.Show("An error occurred while printing", ex.ToString());   } } // Specifies what happens when the PrintPage event is raised. private void pd_PrintPage(object sender, PrintPageEventArgs ev)  {         // Draw a picture.   ev.Graphics.DrawImage(Image.FromFile("C:\\My Folder\\MyFile.bmp"), ev.Graphics.VisibleClipBounds);   // Indicate that this is the last page to print.   ev.HasMorePages = false; } 

读书人网 >C#

热点推荐