Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace Cigle4
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- List<Cigla> cigle = new List<Cigla>();
- private void Form1_Load(object sender, EventArgs e)
- {
- int a = 40;
- int b = 20;
- Cigla c;
- for (int i = 0; i < ClientRectangle.Width; i += a)
- {
- c = new Cigla(a, b, i, 0);
- cigle.Add(c);
- }
- timer1.Start();
- //Refresh();
- }
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- foreach (Cigla c in cigle)
- {
- c.NacrtajCiglu(e.Graphics);
- }
- }
- private void Form1_MouseClick(object sender, MouseEventArgs e)
- {
- foreach (Cigla c in cigle)
- {
- if (c.pripada(e.X, e.Y))
- c.pomerajY = c.B;
- }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- foreach (Cigla c in cigle)
- c.PovecajY();
- Refresh();
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Drawing;
- namespace Cigle4
- {
- class Cigla
- {
- int a;
- int b;
- int x, y;
- public int pomerajY;
- public Cigla()
- {
- }
- public Cigla(int a, int b, int x, int y)
- {
- this.a = a;
- this.b = b;
- this.x = x;
- this.y = y;
- }
- public int A
- {
- get { return a; }
- set { a = value; }
- }
- public int B
- {
- get { return b; }
- set { b = value; }
- }
- public void PovecajY()
- {
- this.y += pomerajY;
- }
- public void NacrtajCiglu(Graphics g)
- {
- g.FillRectangle(Brushes.DarkRed, x, y, a, b);
- Pen p = new Pen(Color.Brown, 1);
- g.DrawRectangle(p, x, y, a, b);
- }
- public bool pripada(int x, int y)
- {
- return x > this.x && x < this.x + a && this.y < y && y < this.y + b;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement