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

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

        private void button1_Click(object sender, EventArgs e)
        {
            SolidBrush myBrush = new SolidBrush(Color.Blue );
            Pen myPen = new Pen(myBrush, 5);
            myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
            Graphics formGraphics =  this.CreateGraphics ();
            Point p1 = new Point(80, 150);
            Point p2 = new Point(340, 150);
            formGraphics.DrawLine(myPen, p1, p2);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SolidBrush myBrush = new SolidBrush(Color.Red);
            Pen myPen = new Pen(myBrush);
            Graphics formGraphics = this.CreateGraphics();
            Point p1 = new Point(80, 160);
            Size size = new Size(250, 50);
            Rectangle rect = new Rectangle(p1, size);
            formGraphics.DrawRectangle(myPen, rect);
            Font font = new Font ("Arial", 20,  FontStyle.Bold );
            formGraphics.DrawString("C# Graphics", font, myBrush,rect);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            SolidBrush myBrush = new SolidBrush(Color.Red);
            Pen myPen = new Pen(myBrush);
            Graphics formGraphics = this.CreateGraphics();
            Point p1 = new Point(0, 0);
            Size size = new Size(50, 100);
            Rectangle rect = new Rectangle(p1, size);
            formGraphics.FillRectangle(myBrush, rect);
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            SolidBrush brush = new SolidBrush(Color.Blue);
            Pen pen = new Pen(Color.Black, 2);
            // create filled rectangle
            g.FillRectangle(brush, 90, 30, 150, 90);
            // draw lines to connect rectangles
            g.DrawLine(pen, 90, 30, 110, 40);
            g.DrawLine(pen, 90, 120, 110, 130);
            g.DrawLine(pen, 240, 30, 260, 40);
            g.DrawLine(pen, 240, 120, 260, 130);
            // draw top rectangle
            g.DrawRectangle(pen, 110, 40, 150, 90);
            // set brush to red
            brush.Color = Color.Red;
            // draw base Ellipse
            g.FillEllipse(brush, 280, 75, 100, 50);
            // draw connecting lines
            g.DrawLine(pen, 380, 55, 380, 100);
            g.DrawLine(pen, 280, 55, 280, 100);
            // draw Ellipse outline
            g.DrawEllipse(pen, 280, 30, 100, 50);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            SolidBrush myBrush = new SolidBrush(Color.Red);
            Pen myPen = new Pen(myBrush);
            Graphics formGraphics = this.CreateGraphics();
            Point p1 = new Point (400, 100);
            Point p2 = new Point (450, 170);
            Point p3 = new Point (400, 200);
            Point p4 = new Point (340, 170);
            Point [] points = new Point[4];
            points[0] = p1;
            points [1] = p2;
            points [2] = p3;
            points [3] = p4;
            formGraphics .DrawPolygon(myPen , points );            
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
