sdee3

TVP - v6

Dec 1st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.27 KB | None | 0 0
  1. // Zadatak 1
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Windows.Forms;
  11.  
  12. namespace vezba6
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.  
  17.         private float broj = 0;
  18.  
  19.         public Form1()
  20.         {
  21.             InitializeComponent();
  22.         }
  23.  
  24.         private void Form1_Paint(object sender, PaintEventArgs e)
  25.         {
  26.             e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
  27.  
  28.             e.Graphics.DrawEllipse(Pens.Black, new Rectangle(150, 100, 100, 100));
  29.             e.Graphics.FillEllipse(Brushes.Blue, new Rectangle(150, 100, 100, 100));
  30.             e.Graphics.DrawEllipse(Pens.Black, new Rectangle(20, 100, 100, 100));        
  31.         }
  32.  
  33.         void Crtanje(object sender, PaintEventArgs e)
  34.         {
  35.             Rectangle r = new Rectangle(150, 100, 100, 100);
  36.  
  37.             e.Graphics.FillEllipse(Brushes.Blue, r);
  38.             e.Graphics.FillPie(Brushes.Red, r, -90, broj);
  39.         }
  40.  
  41.         private void button1_Click(object sender, EventArgs e)
  42.         {
  43.             if (float.TryParse(textBox1.Text, out broj))
  44.             {
  45.                 this.Paint += Crtanje;
  46.                 broj *= (float)3.6;
  47.                 this.Invalidate();
  48.             }
  49.             else {
  50.                 MessageBox.Show("Neispravan unos!");
  51.             }
  52.                
  53.  
  54.  
  55.         }
  56.     }
  57. }
  58.  
  59. // Zadatak 2
  60.  
  61. // Form1.cs
  62.  
  63. using System;
  64. using System.Collections.Generic;
  65. using System.ComponentModel;
  66. using System.Data;
  67. using System.Drawing;
  68. using System.Linq;
  69. using System.Text;
  70. using System.Windows.Forms;
  71.  
  72. namespace vezba6
  73. {
  74.     public partial class Form1 : Form
  75.     {
  76.         Random random;
  77.         int sirina, visina;
  78.         Rectangle r;
  79.  
  80.         public delegate void PronadjenPravougaonik(object sender, Rectangle rect, bool nadjen);
  81.         public event PronadjenPravougaonik generisanje;
  82.  
  83.         public Form1()
  84.         {
  85.             random = new Random();
  86.             sirina = visina = 30;
  87.             this.generisanje += GenerisiPravougaonik;
  88.             //timer1.Enabled = true; --- NE RADI NA VS 2010
  89.            
  90.             InitializeComponent();
  91.         }
  92.  
  93.         void GenerisiPravougaonik(object sender, Rectangle rect, bool nadjen)
  94.         {
  95.             int x = random.Next(0, this.ClientRectangle.Width - sirina - 1);
  96.             int y = random.Next(0, this.ClientRectangle.Height - visina - 1);
  97.  
  98.             r = new Rectangle(x, y, sirina, visina);
  99.            
  100.         }
  101.  
  102.         private void timer1_Tick(object sender, EventArgs e)
  103.         {
  104.             generisanje(this, r, false);
  105.         }
  106.  
  107.         private void Form1_MouseMove(object sender, MouseEventArgs e)
  108.         {
  109.             if (r.Contains(e.Location))
  110.                 generisanje(this, r, true);
  111.         }
  112.  
  113.         private void Form1_Load(object sender, EventArgs e)
  114.         {
  115.             Form2 form2 = new Form2(this);
  116.             form2.Size = this.Size;
  117.             form2.Show();
  118.         }
  119.  
  120.     }
  121. }
  122.  
  123. // Form2.cs
  124.  
  125. using System;
  126. using System.Collections.Generic;
  127. using System.ComponentModel;
  128. using System.Data;
  129. using System.Drawing;
  130. using System.Linq;
  131. using System.Text;
  132. using System.Windows.Forms;
  133.  
  134. namespace vezba6
  135. {
  136.     public partial class Form2 : Form
  137.     {
  138.         Form1 form1;
  139.         List<Rectangle> lista;
  140.  
  141.         public Form2()
  142.         {
  143.             InitializeComponent();
  144.         }
  145.         // Dobra praksa down below:
  146.         public Form2(Form1 form1) : this()
  147.         {
  148.             this.form1 = form1;
  149.             this.lista = new List<Rectangle>();
  150.         }
  151.  
  152.         private void Form2_Load(object sender, EventArgs e)
  153.         {
  154.             this.form1.generisanje += Pronalazenje;
  155.         }
  156.  
  157.         void Pronalazenje(object sender, Rectangle rect, bool nadjen) {
  158.             if (nadjen) {
  159.                 lista.Add(rect);
  160.                 this.Invalidate();
  161.             }
  162.         }
  163.  
  164.         void Crtanje(Graphics g) {
  165.             foreach (Rectangle r in lista)
  166.                 g.FillRectangle(Brushes.Red, r);
  167.         }
  168.  
  169.         private void Form2_Paint(object sender, PaintEventArgs e)
  170.         {
  171.             Crtanje(e.Graphics);
  172.         }
  173.     }
  174. }
Add Comment
Please, Sign In to add comment