如何将PrintPageEventArgs添加到Form_Load C#

时间:2018-07-24 11:54:55

标签: c#

我正在尝试创建一个打印listview项目和一些图片的应用程序。在第一个表单中,我填充列表视图,当我按下预览按钮时,它将打开表单2并打印我的列表视图和其他内容。

private void Form1_Load(object sender, EventArgs e){
    System.Drawing.Image img = System.Drawing.Image.FromFile("C:\\assda.jpg");
    Point loc = new Point(100, 100);
    d.Graphics.DrawImage(img, new Rectangle(10, 20, 195, 100), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel);
    d.Graphics.DrawString("xxxxx", new Font("Times New Romans", 14, FontStyle.Bold), Brushes.Black, new PointF(350, 60));
    }

我必须添加PrintPageEventArgs d,但是当我这样添加时:

private void Form1_Load(object sender, EventArgs e, PrintPageEventArgs d)

我收到以下错误:

No overload for 'Form1_Load' matches delegate 'System.EventHandler'

它显示Form1.Designer.cs中的错误:

this.Load += new System.EventHandler(this.Form1_Load); 

1 个答案:

答案 0 :(得分:-1)

添加一个新的.cs并编写类似的内容;

override protected void print(PrintPageEventArgs e){

    System.Drawing.Image img = System.Drawing.Image.FromFile("C:\\assda.jpg");
        Point loc = new Point(100, 100);
        d.Graphics.DrawImage(img, new Rectangle(10, 20, 195, 100), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel);
        d.Graphics.DrawString("xxxxx", new Font("Times New Romans", 14, FontStyle.Bold), Brushes.Black, new PointF(350, 60));
        }

在您要使用的地方调用此代码