Guest User

Untitled

a guest
Jan 16th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Linq;
  4. using System.Windows.Forms;
  5.  
  6.  
  7. class Program
  8. {
  9.  
  10.  
  11.  
  12.  
  13. static void Main()
  14. {
  15.  
  16.  
  17. var p = new Panel { Dock = DockStyle.Fill };
  18. var b = new Button { Dock = DockStyle.Bottom, Text = "X" };
  19. Random losowa = new Random();
  20.  
  21.  
  22.  
  23.  
  24. b.Click += (o, e) =>
  25. {
  26.  
  27. int szerokosc_panelu = p.Width;
  28. int wysokosc_panelu = p.Height;
  29.  
  30. int dlugosc_x1 = losowa.Next(p.Width);
  31. int wysokosc_y1 = losowa.Next(p.Height);
  32.  
  33.  
  34. int dlugosc_x2 = losowa.Next(p.Width);
  35. int wysokosc_y2 = losowa.Next(p.Height);
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. int x1 = losowa.Next(szerokosc_panelu);
  43. int x2 = losowa.Next(szerokosc_panelu);
  44.  
  45. int y1 = losowa.Next(wysokosc_panelu);
  46. int y2 = losowa.Next(wysokosc_panelu);
  47.  
  48. alamakota(ref x1, ref x2);
  49. alamakota(ref y1, ref y2);
  50.  
  51.  
  52. p.CreateGraphics().FillRectangle(Brushes.White, 0, 0, szerokosc_panelu, wysokosc_panelu);
  53.  
  54.  
  55. int w3 = Math.Max(x1 + dlugosc_x1, x2 + dlugosc_x2) - x1;
  56. int h3 = Math.Max(y1 + wysokosc_y1, y2 + wysokosc_y2) - y1;
  57.  
  58. var rysuj = p.CreateGraphics();
  59. rysuj.FillRectangle(Brushes.Pink, x1, y1, w3, h3);
  60. rysuj.FillRectangle(Brushes.Cyan, x1, y1, dlugosc_x1, wysokosc_y1);
  61. rysuj.FillRectangle(Brushes.Green, x2, y2, dlugosc_x2, wysokosc_y2);
  62.  
  63. };
  64.  
  65.  
  66.  
  67.  
  68. var f = new Form { Text = "Y" };
  69. f.Controls.Add(b);
  70. f.Controls.Add(p);
  71. Application.Run(f);
  72.  
  73. }
  74.  
  75. static void alamakota(ref int a, ref int b)
  76. {
  77. int pomocnicza;
  78.  
  79. if (a > b)
  80. {
  81. pomocnicza = a;
  82. a = b;
  83. b = pomocnicza;
  84. }
  85.  
  86. }
  87. }
Add Comment
Please, Sign In to add comment