using System;
using System.Windows.Forms;

namespace PostCardHitsuji.Frames
{
    public partial class PrintForm : Form
    {
        private PrintForm() { }
        public PrintForm(System.Drawing.Printing.PrintDocument document,
                         System.Drawing.Printing.PrintPageEventHandler CreatePreviewLayoutEvent)
        {
            InitializeComponent();
            numericUpDown1.Value = 1;
            numericUpDown1.Minimum = 1;
            numericUpDown1.Maximum = 1000;
            printPreviewControl1.Document = document;

            printPreviewControl1.Document.PrintPage += CreatePreviewLayoutEvent;
            printPreviewControl1.InvalidatePreview();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            button1.Click += new EventHandler(
                (buttonPrint, buttonPrintEv) =>
                {
                    var res = MessageBox.Show(this, "印刷します。", "", MessageBoxButtons.YesNo);
                    if (res == System.Windows.Forms.DialogResult.No) return;

                    for (var count = 0; count < numericUpDown1.Value; count++) 
                        printPreviewControl1.Document.Print();
                });
        }
    }
}
