Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace Cigle4
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18.  
  19. List<Cigla> cigle = new List<Cigla>();
  20. private void Form1_Load(object sender, EventArgs e)
  21. {
  22. int a = 40;
  23. int b = 20;
  24. Cigla c;
  25. for (int i = 0; i < ClientRectangle.Width; i += a)
  26. {
  27. c = new Cigla(a, b, i, 0);
  28. cigle.Add(c);
  29. }
  30. timer1.Start();
  31. //Refresh();
  32. }
  33.  
  34. private void Form1_Paint(object sender, PaintEventArgs e)
  35. {
  36. foreach (Cigla c in cigle)
  37. {
  38. c.NacrtajCiglu(e.Graphics);
  39. }
  40. }
  41.  
  42.  
  43. private void Form1_MouseClick(object sender, MouseEventArgs e)
  44. {
  45. foreach (Cigla c in cigle)
  46. {
  47. if (c.pripada(e.X, e.Y))
  48. c.pomerajY = c.B;
  49. }
  50. }
  51.  
  52. private void timer1_Tick(object sender, EventArgs e)
  53. {
  54. foreach (Cigla c in cigle)
  55. c.PovecajY();
  56. Refresh();
  57. }
  58.  
  59. }
  60. }
  61.  
  62.  
  63. using System;
  64. using System.Collections.Generic;
  65. using System.Linq;
  66. using System.Text;
  67. using System.Drawing;
  68.  
  69. namespace Cigle4
  70. {
  71. class Cigla
  72. {
  73. int a;
  74. int b;
  75. int x, y;
  76. public int pomerajY;
  77.  
  78. public Cigla()
  79. {
  80.  
  81. }
  82. public Cigla(int a, int b, int x, int y)
  83. {
  84. this.a = a;
  85. this.b = b;
  86. this.x = x;
  87. this.y = y;
  88. }
  89. public int A
  90. {
  91. get { return a; }
  92. set { a = value; }
  93. }
  94. public int B
  95. {
  96. get { return b; }
  97. set { b = value; }
  98. }
  99. public void PovecajY()
  100. {
  101. this.y += pomerajY;
  102. }
  103. public void NacrtajCiglu(Graphics g)
  104. {
  105. g.FillRectangle(Brushes.DarkRed, x, y, a, b);
  106. Pen p = new Pen(Color.Brown, 1);
  107. g.DrawRectangle(p, x, y, a, b);
  108. }
  109. public bool pripada(int x, int y)
  110. {
  111. return x > this.x && x < this.x + a && this.y < y && y < this.y + b;
  112.  
  113. }
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement