Advertisement
istomina_sofia

c# windowsforms 7

Jan 16th, 2022
959
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.68 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4.  
  5. namespace _777
  6. {
  7.     public partial class Form1 : Form
  8.     {
  9.         public Form1()
  10.         {
  11.             InitializeComponent();
  12.         }
  13.  
  14.         private void Clear_Click(object sender, EventArgs e)
  15.         {
  16.             Graphics clear = Graphics.FromHwnd(Picture.Handle);
  17.             clear.Clear(BackColor);
  18.             listBox.Items.Clear();
  19.         }
  20.  
  21.         class Quadr   //класс ЧЕТЫРЕХУГОЛЬНИК
  22.         {
  23.             public Point A, B, C, D;
  24.  
  25.             public Quadr(Point A, Point B, Point C, Point D)   //конструктор с параметрами
  26.             {
  27.                 this.A = A; this.B = B; this.C = C; this.D = D;
  28.             }
  29.  
  30.             public float St(Point X, Point Y)    //метод для вычисления сторон четырехугольника
  31.             {
  32.                 float st = (float)Math.Sqrt(Math.Pow(Y.X - X.X, 2) + Math.Pow(Y.Y - X.Y, 2));
  33.                 return st;
  34.             }
  35.  
  36.             public bool Proverka(Point X, Point Y, Point Z)   //метод для проверки существования четырехугольника
  37.             {
  38.                 float neparX = ((Z.X - X.X) / (Y.X - X.X));    //четырехугольник существует, если три любые точки не лежат на одной прямой
  39.                 float neparY = ((Z.Y - X.Y) / (Y.Y - X.Y));
  40.  
  41.                 float[] arr = { St(A, B), St(B, C), St(C, D), St(A, D) };
  42.                 float max = arr[0];
  43.                 for (int i = 1; i < arr.Length; i++)
  44.                 {
  45.                     if (arr[i] > max) max = arr[i];
  46.                 }
  47.  
  48.                 float sum = St(A, B) + St(B, C) + St(C, D) + St(A, D) - max;   //четырехугольник существует, если длина одной из его сторон меньше, чем сумма длин трех остальных
  49.                 if (sum > max && neparX != neparY) return true;
  50.                 else return false;
  51.             }
  52.  
  53.             public float Square()   //метод для вычисления площади четырехугольника
  54.             {
  55.                 if (Proverka(A, B, C))
  56.                 {
  57.                     float P = St(A, B) + St(B, C) + St(C, D) + St(A, D);
  58.                     float p = P / 2;
  59.                     float S = (float)Math.Sqrt((p - St(A, B)) * (p - St(B, C)) * (p - St(C, D)) * (p - St(A, D)));
  60.                     return S;
  61.                 }
  62.                 else return 0;
  63.             }
  64.         }
  65.  
  66.         class Parallelogram : Quadr    //класс ПАРАЛЛЕЛОГРАММ
  67.         {
  68.             public Parallelogram(Point A, Point B, Point C, Point D)
  69.                 : base(A, B, C, D) { }
  70.  
  71.             public bool Proverka()
  72.             {
  73.                 if (St(A, B) == St(C, D) && St(B, C) == St(A, D)) return true;
  74.                 else return false;
  75.             }
  76.  
  77.             public float Sq(Point X, Point Y, Point Z, Point Q)
  78.             {
  79.                 if (Proverka())
  80.                 {
  81.                     //float a = Y.Y - X.Y;
  82.                     float AB = St(A, B);
  83.                     float h = (float)Math.Sqrt(Math.Pow(X.X - Q.X, 2) + Math.Pow(X.Y - Q.Y, 2));
  84.                     float ss = AB * h;
  85.                     return ss;
  86.                 }
  87.                 else return 0;
  88.             }
  89.  
  90.             public bool Romb(Point A, Point B, Point C, Point D)     //окружность может быть вписаной, если параллелограмм - ромб
  91.             {
  92.                 if (St(A, B) == St(B, C) && St(A, B) == St(A, D) && St(A, B) == St(C, D))
  93.                 {
  94.                     return true;
  95.                 }
  96.                 else return false;
  97.             }
  98.         }
  99.  
  100.         class Circle   //класс ОКРУЖНОСТЬ
  101.         {
  102.             protected float R;
  103.  
  104.             public Circle(float R) { this.R = R; }
  105.  
  106.             public float getR()
  107.             {
  108.                 return R;
  109.             }
  110.             public float Square()
  111.             {
  112.                 float Sr = (float)(Math.PI * Math.Pow(R, 2)) / 10;
  113.                 return Sr;
  114.             }
  115.  
  116.             public float Dlina()
  117.             {
  118.                 float Dr = (float)(2 * Math.PI * R);
  119.                 return Dr;
  120.             }
  121.  
  122.             public float Change(Parallelogram p)            //изменение радиуса в зависимости от переданного параллелограмма
  123.             {
  124.                 return R = (p.St(p.A, p.C)  * p.St(p.B, p.D)) / (2 * p.St(p.A, p.B));
  125.             }
  126.         }
  127.  
  128.         private void Quadrr_Click(object sender, EventArgs e)     //ЧЕТЫРЕХУГОЛЬНИК
  129.         {
  130.             Graphics clear = Graphics.FromHwnd(Picture.Handle);
  131.             clear.Clear(BackColor);
  132.             listBox.Items.Clear();
  133.  
  134.             Point A1 = new Point(50, 50);
  135.             Point B1 = new Point(350, 100);
  136.             Point C1 = new Point(300, 350);
  137.             Point D1 = new Point(150, 350);
  138.             Quadr ABCD1 = new Quadr(A1, B1, C1, D1);
  139.             ABCD1.Proverka(A1, B1, C1);
  140.  
  141.             Graphics qq = Picture.CreateGraphics();
  142.             Pen pen = new Pen(Color.Black, 3f);
  143.             Point[] points = { A1, B1, C1, D1 };
  144.             qq.DrawPolygon(pen, points);
  145.             qq.Dispose();
  146.             if (ABCD1.Proverka(A1, B1, C1))
  147.             {
  148.                 listBox.Items.Add("Четырехугольник существует\n");
  149.                 listBox.Items.Add(" ");
  150.                 listBox.Items.Add("Стороны: AB = " + ABCD1.St(A1, B1));
  151.                 listBox.Items.Add("                  BC = " + ABCD1.St(B1, C1));
  152.                 listBox.Items.Add("                  CD = " + ABCD1.St(C1, D1));
  153.                 listBox.Items.Add("                  AD = " + ABCD1.St(A1, D1));
  154.                 listBox.Items.Add(" ");
  155.                 listBox.Items.Add("Диагонали: AC = " + ABCD1.St(A1, C1));
  156.                 listBox.Items.Add("                      BD = " + ABCD1.St(B1, D1));
  157.                 listBox.Items.Add(" ");
  158.                 listBox.Items.Add("Периметр: P = " + (ABCD1.St(A1, B1) + ABCD1.St(B1, C1) + ABCD1.St(C1, D1) + ABCD1.St(A1, D1)));
  159.                 listBox.Items.Add(" ");
  160.                 listBox.Items.Add("Площадь: S = " + ABCD1.Square());
  161.             }
  162.             else listBox.Items.Add("Четырехугольник не существует");
  163.         }
  164.  
  165.         private void Parallelogramm_Click(object sender, EventArgs e)      //ПАРАЛЛЕЛОГРАММ
  166.         {
  167.             Graphics clear = Graphics.FromHwnd(Picture.Handle);
  168.             clear.Clear(BackColor);
  169.             listBox.Items.Clear();
  170.  
  171.             Point a1 = new Point(150, 50);
  172.             Point b1 = new Point(350, 50);
  173.             Point c1 = new Point(250, 350);
  174.             Point d1 = new Point(50, 350);
  175.             Parallelogram abcd1 = new Parallelogram(a1, b1, c1, d1);
  176.             abcd1.Proverka();
  177.             float ss1 = abcd1.Sq(a1, b1, c1, d1);
  178.  
  179.             Graphics pp = Picture.CreateGraphics();
  180.             Pen pen = new Pen(Color.Black, 3f);
  181.             Point[] points = { a1, b1, c1, d1 };
  182.             pp.DrawPolygon(pen, points);
  183.             pp.Dispose();
  184.             if(abcd1.Proverka())
  185.             {
  186.                 listBox.Items.Add("Фигура - параллелограмм");
  187.                 listBox.Items.Add(" ");
  188.                 listBox.Items.Add("Стороны: AB = " + abcd1.St(a1, b1));
  189.                 listBox.Items.Add("                   BC = " + abcd1.St(b1, c1));
  190.                 listBox.Items.Add("                   CD = " + abcd1.St(c1, d1));
  191.                 listBox.Items.Add("                   AD = " + abcd1.St(a1, d1));
  192.                 listBox.Items.Add(" ");
  193.                 listBox.Items.Add("Площадь: S = " + ss1);
  194.             }
  195.             else listBox.Items.Add("Фигура - не параллелограмм");
  196.         }
  197.  
  198.         private void Circlee_Click(object sender, EventArgs e)   //ОКРУЖНОСТЬ
  199.         {
  200.             Graphics clear = Graphics.FromHwnd(Picture.Handle);
  201.             clear.Clear(BackColor);
  202.             listBox.Items.Clear();
  203.  
  204.             float rr = 200;
  205.             Circle okr = new Circle(rr);
  206.  
  207.             Graphics oo = Picture.CreateGraphics();
  208.             Pen pen = new Pen(Color.Black, 3f);
  209.             RectangleF rect  = new RectangleF(100, 100, rr, rr);
  210.             oo.DrawEllipse(pen, rect);
  211.             oo.Dispose();
  212.             listBox.Items.Add("Радиус: R = " + okr.getR());
  213.             listBox.Items.Add(" ");
  214.             listBox.Items.Add("Длина: L = " + okr.Dlina());
  215.             listBox.Items.Add(" ");
  216.             listBox.Items.Add("Площадь: S = " + okr.Square());
  217.         }
  218.  
  219.         private void вписаннаяОкружностьToolStripMenuItem_Click(object sender, EventArgs e)   //ВПИСАННАЯ ОКРУЖНОСТЬ
  220.         {
  221.             Graphics clear = Graphics.FromHwnd(Picture.Handle);
  222.             clear.Clear(BackColor);
  223.             listBox.Items.Clear();
  224.  
  225.             Point a = new Point(200, 50);
  226.             Point b = new Point(350, 200);
  227.             Point c = new Point(200, 350);
  228.             Point d = new Point(50, 200);
  229.             Parallelogram abcd = new Parallelogram(a, b, c, d);
  230.             abcd.Romb(a, b, c, d);
  231.             float rr = 200; ;
  232.             Circle okr = new Circle(rr);
  233.             float R = okr.Change(abcd);
  234.  
  235.             Graphics oo = Picture.CreateGraphics();
  236.             Pen pen = new Pen(Color.Black, 3f);
  237.             RectangleF rect = new RectangleF(94, 94, R, R);
  238.             oo.DrawEllipse(pen, rect);
  239.             oo.Dispose();
  240.  
  241.             Graphics pp = Picture.CreateGraphics();
  242.             Point[] points = { a, b, c, d };
  243.             pp.DrawPolygon(pen, points);
  244.             pp.Dispose();
  245.  
  246.             if(abcd.Romb(a, b, c, d))
  247.             {
  248.                 listBox.Items.Add("Парраллелограмм - ромб");
  249.                 listBox.Items.Add(" ");
  250.                 listBox.Items.Add("Информация о вписанной окружности:");
  251.                 listBox.Items.Add(" ");
  252.                 listBox.Items.Add("Радиус: R = " + okr.getR());
  253.                 listBox.Items.Add(" ");
  254.                 listBox.Items.Add("Длина: L = " + okr.Dlina());
  255.                 listBox.Items.Add(" ");
  256.                 listBox.Items.Add("Площадь: S = " + okr.Square());
  257.             }
  258.             else listBox.Items.Add("Парраллелограмм - не ромб");
  259.         }
  260.     }  
  261. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement