Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Разработка Windows Forms > Переписать код под WinForms


Автор: dnss 12.10.2016, 10:46
Код

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication1
{
    class Triangle
    {
        int a, b, c;
        public int A
        {
            get
            {
                return a;
            }
            set
            {
                a = value;
            }
        }
        public int B
        {
            get
            {
                return b;
            }
            set
            {
                b = value;
            }
        }
        public int C
        {
            get
            {
                return c;
            }
            set
            {
                c = value;
            }
        }
        public bool isTriangle
        {
            get
            {
                if (a + b > c && a + c > b && b + c > a)
                {
                    return true;
                }
                return false;
            }
 
        }
        public Triangle(int a_, int b_, int c_)
        {
            isCorrect(a_, b_, c_);
            A = a_;
            B = b_;
            C = c_;
        }
        public void PrintSides()
        {
            Console.WriteLine("a = {0}, b = {1}, c = {2}", a, b, c);
        }
        public int Perimetr()
        {
            return a + b + c;
        }
        public double Square()
        {
            return Math.Sqrt(halfper(this) * (halfper(this) - a) * (halfper(this) - b)
                * (halfper(this) - c));
        }
        static double halfper(Triangle Ob)
        {
            return Ob.Perimetr() / 2.0;
        }
        static void isCorrect(int a, int b, int c)
        {
            if (a < 0 || b < 0 || c < 0)
                throw new Exception("Sides of triangle can` t be negative");
        }
        public static Triangle operator ++(Triangle Ob)
        {
            return new Triangle(++Ob.a, ++Ob.b, ++Ob.c);
        }
        public static Triangle operator --(Triangle Ob)
        {
            return new Triangle(--Ob.a, --Ob.b, --Ob.c);
        }
        public static Triangle operator *(Triangle Ob, int mult)
        {
            return new Triangle(Ob.a * mult, Ob.b * mult, Ob.c * mult);
        }
        public override string ToString()
        {
            return "Стороны: " + "a = " + A + " b = " + B + " c = " + C;
        }
        public int this[int idx]
        {
            get
            {
                if (idx == 1)
                    return a;
                else if (idx == 2)
                    return b;
                else if (idx == 3)
                    return c;
                else
                    throw new Exception("idx can be only 1, 2 and 3");
            }
            set
            {
                if (idx == 1)
                    a = value;
                else if (idx == 2)
                    b = value;
                else if (idx == 3)
                    c = value;
                else
                    throw new Exception("idx can be only 1, 2 and 3");
            }
        }
        public static bool operator true(Triangle t)
        {
            return t.isTriangle;
        }
        public static bool operator false(Triangle t)
        {
            return t.isTriangle;
        }
    };
 
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Triangle Ob = new Triangle(3, 3, 3);
                if (Ob)
                    Ob.PrintSides();
                else
                    throw new Exception("There is no triangle with such sides");
                Console.WriteLine("Perimetr={0}", Ob.Perimetr());
                Console.WriteLine("Sqaure={0}", Ob.Square());
                Ob++;
                Ob.PrintSides();
                --Ob;
                Ob.PrintSides();
                Ob *= 5;
                Ob.PrintSides();
                Console.WriteLine(Ob);
                Console.WriteLine(Ob[1]);
                Ob[2] = 30;
                Console.WriteLine(Ob);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                Console.ReadKey();
            }
        }
    }
}

Автор: infarch 13.10.2016, 10:17
Ну а в чем проблема? Создайте винформ-проект, из палитры добавьте на форму нужные контролы, напишите хендлеры. Что конкретно у вас не получается?

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)