How to draw shape?

E.g.: draw line, circle, triangle

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

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

 
        private void Form1_Load(object sender, EventArgs e)
        {

 
        }

 
        private void button1_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Pen p = new Pen(Color.Black, 2);
            g.DrawLine(p, 10, 10, 100, 100);

            g.Dispose();
         }

        private void button2_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Pen p = new Pen(Color.Black, 2);
            g.FillPolygon(Brushes.White, new Point[3] { new Point(10, 310), new Point(40, 260), new
Point(70, 310) });
            g.DrawPolygon(p, new Point[3] { new Point(10, 310), new Point(40, 260), new Point(70, 310) });
            g.Dispose();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Pen p = new Pen(Color.Black, 2);
            g.FillEllipse(Brushes.White, 15, 100, 50, 50);
            g.DrawEllipse(p, 100, 100, 100, 100);
            g.Dispose();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            g.Clear(Color.White);
            g.Dispose();
        }
    }
}

Ebook Download
View all
Learn
View all