How to create 7 segment by graphic?

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.Threading;

 

namespace _7_segment

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            Graphics g = this.CreateGraphics();

            Pen p = new Pen(Color.White, 13);

            Font f = new Font("Arial", 50, FontStyle.Bold);

            g.DrawString("7-SEGMENT", f, Brushes.White, 10, 10);

            g.Dispose();

        }

 

        private void button2_Click(object sender, EventArgs e)

        {

            Graphics g = this.CreateGraphics();

            Pen p = new Pen(Color.White, 15);

            Point po1 = new Point(172, 120);

            Point po2 = new Point(172, 220);

            Point po3 = new Point(172, 320);

            Point po4 = new Point(280, 120);

            Point po5 = new Point(280, 220);

            Point po6 = new Point(280, 320);

            Font f = new Font("Arial", 50, FontStyle.Bold);

            Int16 i;

 

            for (i = 0; i <= 9; i++)

            {

                System.Threading.Thread.Sleep(500);

                if (i == 0)

                { g.Clear(Color.Black);

                g.DrawLine(p, po1, po2);

                g.DrawLine(p, po2, po3);

                g.DrawLine(p, po1, po4);

                g.DrawLine(p, po3, po6);

                g.DrawLine(p, po4, po5);

                g.DrawLine(p, po5, po6);

                }

                if (i == 1)

                {

                    g.Clear(Color.Black);

                    g.DrawLine(p, po4, po5);

                    g.DrawLine(p, po5, po6);

                }

                if (i == 2)

                {

                    g.Clear(Color.Black);

                    g.DrawLine(p, po1, po4);

                    g.DrawLine(p, po4, po5);

                    g.DrawLine(p, po2, po5);

                    g.DrawLine(p, po2, po3);

                    g.DrawLine(p, po3, po6);

                }

                if (i == 3)

                {

                    g.Clear(Color.Black);

                    g.DrawLine(p, po1, po4);

                    g.DrawLine(p, po4, po5);

                    g.DrawLine(p, po2, po5);

                    g.DrawLine(p, po5, po6);

                    g.DrawLine(p, po3, po6);

                }

                if (i == 4)

                {

                    g.Clear(Color.Black);

                    g.DrawLine(p, po1, po2);

                    g.DrawLine(p, po2, po5);

                    g.DrawLine(p, po4, po5);

                    g.DrawLine(p, po5, po6);

                }

                if (i == 5)

                {

                    g.Clear(Color.Black);

                    g.DrawLine(p, po1, po4);

                    g.DrawLine(p, po1, po2);

                    g.DrawLine(p, po2, po5);

                    g.DrawLine(p, po5, po6);

                    g.DrawLine(p, po3, po6);

                }

                if (i == 6)

                {

                    g.Clear(Color.Black);

                    g.DrawLine(p, po1, po2);

                    g.DrawLine(p, po2, po3);

                    g.DrawLine(p, po1, po4);

                    g.DrawLine(p, po2, po5);

                    g.DrawLine(p, po3, po6);

                    g.DrawLine(p, po5, po6);

                }

                if (i == 7)

                {

                    g.Clear(Color.Black);

                    g.DrawLine(p, po1, po4);

                    g.DrawLine(p, po4, po5);

                    g.DrawLine(p, po5, po6);

                }

                if (i == 8)

                {

                    g.Clear(Color.Black);

                    g.DrawLine(p, po1, po2);

                    g.DrawLine(p, po2, po3);

                    g.DrawLine(p, po1, po4);

                    g.DrawLine(p, po2, po5);

                    g.DrawLine(p, po3, po6);

                    g.DrawLine(p, po4, po5);

                    g.DrawLine(p, po5, po6);

                }

                if (i == 9)

                {

                    g.Clear(Color.Black);

                    g.DrawLine(p, po1, po2);

                    g.DrawLine(p, po1, po4);

                    g.DrawLine(p, po2, po5);

                    g.DrawLine(p, po3, po6);

                    g.DrawLine(p, po4, po5);

                    g.DrawLine(p, po5, po6);

                }

            }

           

            g.DrawString("COUNTING END", f, Brushes.White, 10, 10);

            g.Dispose();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

 

        }

    }

}

Ebook Download
View all
Learn
View all