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;
using System.Drawing.Drawing2D;

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

        private void button1_Click(object sender, EventArgs e)
        {
            string str;
            openFileDialog1.Filter = "JPG文件(*.jpg)|*.jpg";     //设置打开图像的类型
            openFileDialog1.ShowDialog();                        //打开对话框
            str = openFileDialog1.FileName;                      
            pictureBox1.Image = Image.FromFile(str);            //显示打开图像
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Graphics myg = pictureBox1.CreateGraphics();              //创建Graphics对象实例
            SolidBrush mybrush = new SolidBrush(Color.Red);          //定义画笔类型及颜色
            Font myfont = new Font("黑体", 12);                      //设置字体类型及颜色
                                                                    //调用DrawString方法在图像上写文字
            myg.DrawString("在图像上写入文字", myfont, mybrush, new Rectangle(70, 70, 200, 70));
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Graphics myg = pictureBox1.CreateGraphics();
                                                               //定义线型渐变画笔
            LinearGradientBrush mybrush = new LinearGradientBrush(ClientRectangle, Color.SteelBlue, Color.Red, LinearGradientMode.BackwardDiagonal);
            Font myfont = new Font("隶书", 15);
            myg.DrawString("在图像上写入渐变字", myfont, mybrush, new Rectangle(60, 100, 600, 100));
        }
    }
}
