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 Ex01_5
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            int y, dy;   //定义变量
            y = this.ClientRectangle.Location.Y;
            dy = this.ClientRectangle.Height / 256;
            for (int i = 255; i >= 0; i--)          //利用For循环语句渐变窗体背景
            {

                Color c = new Color();               //定义颜色对象实例
                //调用Color对象的FromArgb方法
                c = Color.FromArgb(i, Convert.ToInt32(textBox1.Text.ToString()), Convert.ToInt32(textBox2.Text.ToString()));
                SolidBrush sb = new SolidBrush(c);    //定义画笔颜色
                Pen p = new Pen(sb, 1);               //定义画笔
                //绘制矩形
                e.Graphics.DrawRectangle(p, this.ClientRectangle.X, y, this.Width, y + dy);
                y = y + dy;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            this.Visible = true;
        }
    }
}
