Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Zadatak 1
- 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 vezba6
- {
- public partial class Form1 : Form
- {
- private float broj = 0;
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- e.Graphics.DrawEllipse(Pens.Black, new Rectangle(150, 100, 100, 100));
- e.Graphics.FillEllipse(Brushes.Blue, new Rectangle(150, 100, 100, 100));
- e.Graphics.DrawEllipse(Pens.Black, new Rectangle(20, 100, 100, 100));
- }
- void Crtanje(object sender, PaintEventArgs e)
- {
- Rectangle r = new Rectangle(150, 100, 100, 100);
- e.Graphics.FillEllipse(Brushes.Blue, r);
- e.Graphics.FillPie(Brushes.Red, r, -90, broj);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (float.TryParse(textBox1.Text, out broj))
- {
- this.Paint += Crtanje;
- broj *= (float)3.6;
- this.Invalidate();
- }
- else {
- MessageBox.Show("Neispravan unos!");
- }
- }
- }
- }
- // Zadatak 2
- // Form1.cs
- 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 vezba6
- {
- public partial class Form1 : Form
- {
- Random random;
- int sirina, visina;
- Rectangle r;
- public delegate void PronadjenPravougaonik(object sender, Rectangle rect, bool nadjen);
- public event PronadjenPravougaonik generisanje;
- public Form1()
- {
- random = new Random();
- sirina = visina = 30;
- this.generisanje += GenerisiPravougaonik;
- //timer1.Enabled = true; --- NE RADI NA VS 2010
- InitializeComponent();
- }
- void GenerisiPravougaonik(object sender, Rectangle rect, bool nadjen)
- {
- int x = random.Next(0, this.ClientRectangle.Width - sirina - 1);
- int y = random.Next(0, this.ClientRectangle.Height - visina - 1);
- r = new Rectangle(x, y, sirina, visina);
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- generisanje(this, r, false);
- }
- private void Form1_MouseMove(object sender, MouseEventArgs e)
- {
- if (r.Contains(e.Location))
- generisanje(this, r, true);
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- Form2 form2 = new Form2(this);
- form2.Size = this.Size;
- form2.Show();
- }
- }
- }
- // Form2.cs
- 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 vezba6
- {
- public partial class Form2 : Form
- {
- Form1 form1;
- List<Rectangle> lista;
- public Form2()
- {
- InitializeComponent();
- }
- // Dobra praksa down below:
- public Form2(Form1 form1) : this()
- {
- this.form1 = form1;
- this.lista = new List<Rectangle>();
- }
- private void Form2_Load(object sender, EventArgs e)
- {
- this.form1.generisanje += Pronalazenje;
- }
- void Pronalazenje(object sender, Rectangle rect, bool nadjen) {
- if (nadjen) {
- lista.Add(rect);
- this.Invalidate();
- }
- }
- void Crtanje(Graphics g) {
- foreach (Rectangle r in lista)
- g.FillRectangle(Brushes.Red, r);
- }
- private void Form2_Paint(object sender, PaintEventArgs e)
- {
- Crtanje(e.Graphics);
- }
- }
- }
Add Comment
Please, Sign In to add comment