コード例 #1
0
        static void Main(string[] args)
        {
            Circle       fc           = new Circle("FirstCircle");
            Hexagon      fh           = new Hexagon("FirstHexagon");
            ThreeDCircle ThreeDCircle = new ThreeDCircle("3d Circle");

            object[] ArrC = new  object[5];

            object sc = new Circle("SecondCircle");



            ArrC[0] = fc;
            ArrC[1] = fh;
            ArrC[2] = ThreeDCircle;
            ArrC[3] = (Circle)sc;
            ArrC[4] = new ClassDontForThisProject();


            Console.WriteLine(fc.ToString());


            foreach (object s in ArrC)
            {
                if (s is Shape d)
                {
                    d.Draw();
                }
                else
                {
                    ClassDontForThisProject h = s as ClassDontForThisProject;
                    if (h == null)
                    {
                        Console.WriteLine("Не ClassDontForThisProject");
                    }
                    else
                    {
                        h.Learn();
                    }
                }
            }

            GetName((Circle)ArrC[0]);



            Console.ReadLine();
        }
コード例 #2
0
        //the class PaintEventArgs provides data for the object event Paint
        private void panelDrawing_Paint(object sender, PaintEventArgs e)
        {
            // Fill before painting to have a lighter border
            // Rectangle
            if (this.radioButtonRectangle.Checked == true && myRectangle != null)
            {
                if (fill)
                {
                    myRectangle.Fill(e);
                }
                myRectangle.Draw(e);

                this.textBoxDisplay.Text = myRectangle.ToString();
            }
            // Square
            if (this.radioButtonSquare.Checked == true && mySquare != null)
            {
                if (fill)
                {
                    mySquare.Fill(e);
                }
                mySquare.Draw(e);

                this.textBoxDisplay.Text = mySquare.ToString();
            }
            // Circle
            if (this.radioButtonCircle.Checked == true && myCircle != null)
            {
                if (fill)
                {
                    myCircle.Fill(e);
                }
                myCircle.Draw(e);

                this.textBoxDisplay.Text = myCircle.ToString();
            }
            // Ellipse
            if (this.radioButtonEllipse.Checked == true && myEllipse != null)
            {
                if (fill)
                {
                    myEllipse.Fill(e);
                }
                myEllipse.Draw(e);

                this.textBoxDisplay.Text = myEllipse.ToString();
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            #region Circles
            // create new Circle
            Circle c1 = new Circle();
            Circle c2 = new Circle();
            Circle c3 = new Circle();

            // ToString tests
            Console.WriteLine("Circle1:\n" + c1.ToString());
            Console.WriteLine("Circle2:\n" + c2.ToString());
            Console.WriteLine("Circle3:\n" + c3.ToString());

            // Equals tests
            Console.WriteLine("Does Circle1 equal Circle2? {0}", c1.Equals(c2));
            Console.WriteLine("Does Circle1 equal Circle3? {0}", c1.Equals(c3));
            Console.WriteLine("Does Circle2 equal Circle3? {0}", c2.Equals(c3) + "\n");
            #endregion

            #region Squares
            // create new Squares
            Square s1 = new Square();
            Square s2 = new Square();
            Square s3 = new Square();

            // ToString tests
            Console.WriteLine("Square1:\n" + s1.ToString());
            Console.WriteLine("Square2:\n" + s2.ToString());
            Console.WriteLine("Square3:\n" + s3.ToString());

            // Equals tests
            Console.WriteLine("Does Square1 equal Square2? {0}", s1.Equals(s2));
            Console.WriteLine("Does Square1 equal Square3? {0}", s1.Equals(s3));
            Console.WriteLine("Does Square2 equal Square3? {0}", s2.Equals(s3) + "\n");
            #endregion

            Console.ReadLine();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: barshchou/Shapes
        static void Main(string[] args)
        {
            Random random = new Random();
            int    rand   = random.Next(1, 3);

            Drawer figure = new FigureDrawer();

            figure.Draw(rand);

            Figure figure1 = new Circle(0, 0, 10);

            Console.WriteLine(figure1.ToString());

            Figure figure2 = new Rectangle(0, 0, 0, 5, 5, 5, 0, 5);

            Console.WriteLine(figure2.ToString());

            Figure figure3 = new Triangle(0, 0, 3, 3, 0, 6);

            Console.WriteLine(figure3.ToString());

            Console.ReadKey();
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: prudx/CSharp-Labs
        static void Main(string[] args)
        {
            //test vertex class
            Vertex v1 = new Vertex(4, 6);
            Vertex v2 = new Vertex(2, 5);

            Console.WriteLine("");
            Console.WriteLine(v1.ToString());
            Console.WriteLine("");

            Line l1 = new Line(1, 2, 3, 4, ShapeColor.Green);

            //Shape s = new Shape("Yellow");
            Console.WriteLine(l1.ToString());

            l1.Translate(v1);

            Console.WriteLine("\nTranslated by first vertex\n");
            Console.WriteLine(l1.ToString());

            Circle c1 = new Circle(1, 2, 4, ShapeColor.Red);

            Console.WriteLine("");
            Console.WriteLine(c1.ToString());
            Console.WriteLine("");
            Console.WriteLine("---Polymorphic testing---");

            Shape[] shapes = { new Line(2, 2, 3, 3, ShapeColor.Green), new Circle(5, 5, 50, ShapeColor.Blue) };

            foreach (Shape s in shapes)
            {
                Console.WriteLine("before : " + s);             // ToString()
                s.Translate(new Vertex(10, 10));
                Console.WriteLine("after : " + s);              // ToString()
                Console.WriteLine("");
            }
        }
コード例 #6
0
 private void button1_Click(object sender, EventArgs e)
 {
     richTextBox1.Text = Circ.ToString();
 }
コード例 #7
0
        private void Draw_Click(object sender, EventArgs e)
        {
            // Rectangle
            if (this.radioButtonRectangle.Checked == true)
            {
                int x      = Convert.ToInt32(this.textBoxX.Text);
                int y      = Convert.ToInt32(this.textBoxY.Text);
                int height = Convert.ToInt32(this.textBoxHeight.Text);
                int width  = Convert.ToInt32(this.textBoxWidth.Text);

                myRectangle = new Rectangle(x, y, height, width);

                // fill or draw?
                fill = false;

                //txt_Display
                String info = myRectangle.ToString();
                this.textBoxDisplay.Text    = info;
                this.textBoxDisplay.Visible = true;
            }
            // Square
            if (this.radioButtonSquare.Checked == true)
            {
                int x     = Convert.ToInt32(this.textBoxX.Text);
                int y     = Convert.ToInt32(this.textBoxY.Text);
                int width = Convert.ToInt32(this.textBoxWidth.Text);

                mySquare = new Square(x, y, width);

                // fill or draw?
                fill = false;

                //txt_Display
                String info = mySquare.ToString();
                this.textBoxDisplay.Text    = info;
                this.textBoxDisplay.Visible = true;
            }
            // Circle
            if (this.radioButtonCircle.Checked == true)
            {
                int x     = Convert.ToInt32(this.textBoxX.Text);
                int y     = Convert.ToInt32(this.textBoxY.Text);
                int width = Convert.ToInt32(this.textBoxWidth.Text);

                myCircle = new Circle(x, y, width);

                // fill or draw?
                fill = false;

                //txt_Display
                String info = myCircle.ToString();
                this.textBoxDisplay.Text    = info;
                this.textBoxDisplay.Visible = true;
            }
            // Ellipse
            if (this.radioButtonEllipse.Checked == true)
            {
                int x      = Convert.ToInt32(this.textBoxX.Text);
                int y      = Convert.ToInt32(this.textBoxY.Text);
                int height = Convert.ToInt32(this.textBoxHeight.Text);
                int width  = Convert.ToInt32(this.textBoxWidth.Text);

                myEllipse = new Ellipse(x, y, height, width);

                // fill or draw?
                fill = false;

                //txt_Display
                String info = myEllipse.ToString();
                this.textBoxDisplay.Text    = info;
                this.textBoxDisplay.Visible = true;
            }

            this.panelDrawing.Invalidate(); // it causes the control to be redrawn
            this.panelDrawing.Update();
            this.Refresh();
        }