Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Linq;
- using System.Windows.Forms;
- class Program
- {
- static void Main()
- {
- var p = new Panel { Dock = DockStyle.Fill };
- var b = new Button { Dock = DockStyle.Bottom, Text = "X" };
- Random losowa = new Random();
- b.Click += (o, e) =>
- {
- int szerokosc_panelu = p.Width;
- int wysokosc_panelu = p.Height;
- int dlugosc_x1 = losowa.Next(p.Width);
- int wysokosc_y1 = losowa.Next(p.Height);
- int dlugosc_x2 = losowa.Next(p.Width);
- int wysokosc_y2 = losowa.Next(p.Height);
- int x1 = losowa.Next(szerokosc_panelu);
- int x2 = losowa.Next(szerokosc_panelu);
- int y1 = losowa.Next(wysokosc_panelu);
- int y2 = losowa.Next(wysokosc_panelu);
- alamakota(ref x1, ref x2);
- alamakota(ref y1, ref y2);
- p.CreateGraphics().FillRectangle(Brushes.White, 0, 0, szerokosc_panelu, wysokosc_panelu);
- int w3 = Math.Max(x1 + dlugosc_x1, x2 + dlugosc_x2) - x1;
- int h3 = Math.Max(y1 + wysokosc_y1, y2 + wysokosc_y2) - y1;
- var rysuj = p.CreateGraphics();
- rysuj.FillRectangle(Brushes.Pink, x1, y1, w3, h3);
- rysuj.FillRectangle(Brushes.Cyan, x1, y1, dlugosc_x1, wysokosc_y1);
- rysuj.FillRectangle(Brushes.Green, x2, y2, dlugosc_x2, wysokosc_y2);
- };
- var f = new Form { Text = "Y" };
- f.Controls.Add(b);
- f.Controls.Add(p);
- Application.Run(f);
- }
- static void alamakota(ref int a, ref int b)
- {
- int pomocnicza;
- if (a > b)
- {
- pomocnicza = a;
- a = b;
- b = pomocnicza;
- }
- }
- }
Add Comment
Please, Sign In to add comment