日期:2014-05-17  浏览次数:20951 次

关于【pd_PrintPage】的错误。
本帖最后由 mucmucll 于 2013-10-15 20:06:49 编辑
最近准备做个POS打印的程序,借鉴了一下这个网页的内容:
http://www.cnblogs.com/weixing/p/3283182.html

新建了一个windows窗口项目,然后在默认创建的Form1上面拖了两个button控件,然后就直接粘贴下面的代码,无法编译,总是提示:
错误 CS1061: “Pos_Test.Form1”不包含“pd_PrintPage”的定义,并且找不到可接受类型为“Pos_Test.Form1”的第一个参数的扩展方法“pd_PrintPage”(是否缺少 using 指令或程序集引用?)

难道是忘了加命名空间了?请高手指点一下。


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using System.Windows;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Printing;

namespace Pos_Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //打印预览
            PrintPreviewDialog ppd = new PrintPreviewDialog();
            PrintDocument pd = new PrintDocument();
            //设置边距
            Margins margin = new Margins(20, 20, 20, 20);
            pd.DefaultPageSettings.Margins = margin;
            ////纸张设置默认
            PaperSize pageSize = new PaperSize("First custom size", getYc(58), 600);
            pd.DefaultPageSettings.PaperSize = pageSize;
            //打印事件设置
            pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
            ppd.Document = pd;
            ppd.ShowDialog();
            try
            {
                pd.Print();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
                pd.PrintController.O