Form1の全コード
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Graphics
{
    public partial class Form1 : Form
    {
        int M = 1;
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.Clear(Color.White);
            switch (M)
            {
                case 2:
                    e.Graphics.DrawLine(Pens.Black, 0, 50, 400, 50);
                    e.Graphics.DrawLine(Pens.Red, 100, 0, 100, 500);
                    e.Graphics.DrawLine(Pens.Blue, 0, 0, this.Width, this.Height);
                    e.Graphics.DrawLine(Pens.Black, 0, 50, 400, 50);
                    e.Graphics.DrawLine(Pens.Red, 100, 0, 100, 500);
                    e.Graphics.DrawLine(Pens.Blue, 0, 0, this.Width, this.Height);
                    break;
                case 3:
                    e.Graphics.DrawRectangle(Pens.Green, 10, 50, 200, 150);
                    e.Graphics.DrawRectangle(Pens.Blue, 30, 50, 150, 150);
                    e.Graphics.DrawEllipse(Pens.Red, 10, 150, 150, 250);
                    e.Graphics.DrawEllipse(Pens.Yellow, 20, 50, 250, 125);
                    e.Graphics.FillEllipse(Brushes.Red, 0, 50, 150, 150);
                    e.Graphics.FillRectangle(Brushes.Aquamarine, 31, 51, 148, 148);
                    break;
                case 4:
                    System.Drawing.Font aFont = new System.Drawing.Font("Arial", 22, FontStyle.Bold);
                    e.Graphics.DrawString("Graphics are fun!", aFont, Brushes.Black, 20, 50);
                    e.Graphics.RotateTransform(45);
                    e.Graphics.DrawString("And exciting too!", aFont, Brushes.Red, 100, 0);
                    break;
                case 5:
                    e.Graphics.RotateTransform(45);
                    e.Graphics.DrawImage(Graphics.Properties.Resources.Image1, 200, -100);
                    break;
                default:
                    break;
            }
        }
        public Form1()
        {
            InitializeComponent();
        }
        private void ToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            this.Invalidate();
            M = 2;
        }
        private void ToolStripMenuItem3_Click(object sender, EventArgs e)
        {
            this.Invalidate();
            M = 3;
        }
        private void ToolStripMenuItem4_Click(object sender, EventArgs e)
        {
            this.Invalidate();
            M = 4;
        }
        private void ToolStripMenuItem5_Click(object sender, EventArgs e)
        {
            this.Invalidate();
            M = 5;
        }
    }
}