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

namespace Ex05_7
{
    public partial class Form1 : Form
    {
        string str;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "*.jpg,*.jpeg,*.bmp,*.gif,*.ico,*.png,*.tif,*.wmf|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*.wmf";     //设置打开图像的类型
            openFileDialog1.ShowDialog();                        //打开对话框
            str = openFileDialog1.FileName;                      //获取打开对话框的文件名
            pictureBox1.Image = Image.FromFile(str);            //显示打开图像
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            try
            {
                Bitmap bitmap = new Bitmap(str);
                e.Graphics.DrawImage(bitmap, 100, 200, 600, 800);
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            printPreviewDialog1.Document = this.printDocument1;
            printPreviewDialog1.ShowDialog();               //打印预览对话框
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
