CryReport 取得使用者是否按下印表功能

crystalReport

常常在應用上,都會想知道使用者是否按下列印鈕,故採用以下方式實施

步驟一:

public delegate void PrintDelegate();

步驟二:

private void Button_Click(object sender, EventArgs e)
{
	REPORT_3B Reporter = new REPORT_3B();  // 報表檔
	Reporter.SetDataSource(Ds.Tables["Master"]);
	Reporter.ParameterFields["抬頭"].CurrentValues.AddValue("XX股份有限公司");
	ReportViewFormB ReportForm = new ReportViewFormB(Reporter);
	PrintDelegate mymethod = new PrintDelegate(CustomPrintMethod);
	ReportForm.CustomPrintMethod = mymethod;
	ReportForm.WindowState = FormWindowState.Maximized;
	ReportForm.Show();
}

步驟三:

public partial class ReportViewForm : Form
{
    public delegate void CustomPrintDelegate();

    public Delegate CustomPrintMethod { get; set; }

    public ReportViewForm(REPORT_3B Report)
    {
        InitializeComponent();

        foreach (Control control in crystalReportViewer1.Controls) {
            if (control is System.Windows.Forms.ToolStrip) {

                //Default Print Button
                ToolStripItem tsItem = ((ToolStrip)control).Items[1];
                tsItem.Click += new EventHandler(tsItem_Click);
                    
                //Custom Button
                ToolStripItem tsNewItem = ((ToolStrip)control).Items.Add("");
                tsNewItem.ToolTipText = "Custom Print Button";
                //tsNewItem.Image = Resources.CustomButton;
                tsNewItem.Tag = "99";
                ((ToolStrip)control).Items.Insert(0, tsNewItem);
                tsNewItem.Click += new EventHandler(tsNewItem_Click);
            }
        }

        crystalReportViewer1.ReportSource = Report;
        crystalReportViewer1.Refresh();
    }

    void tsNewItem_Click(object sender, EventArgs e) {
        if (CustomPrintMethod != null) {
            CustomPrintMethod.DynamicInvoke(null);
        }
    }

    void tsItem_Click(object sender, EventArgs e) {
        if (CustomPrintMethod != null) {
            CustomPrintMethod.DynamicInvoke(null);
        }
    }
}

 

 

興滿逸筑2013年全新完工,位於恆春鎮外圍離市區只要2分鐘車程,有豪華的外觀、有美麗的庭院、也有溫馨舒適的房間,這裡車流量不多,空氣不錯,適合家族或成群結黨的朋友們一同旅遊的好地方。

http://sinmaniz.tw/index.html