amarek

OOP LV7 - Zadatak2

Nov 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.35 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.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace LV7___Zadatak_2
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         Graphics g;
  16.         Pen p;
  17.  
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.             g = pbDrawing.CreateGraphics();
  22.         }
  23.  
  24.         private void pbDrawing_Click(object sender, EventArgs e)
  25.         {
  26.  
  27.         }
  28.  
  29.         private void pbDrawing_MouseUp(object sender, MouseEventArgs e)
  30.         {
  31.             if (rbRed.Checked == true)
  32.             {
  33.                 p = new Pen(Color.Red, sbThickness.Value);
  34.             }
  35.             else if (rbGreen.Checked == true)
  36.             {
  37.                 p = new Pen(Color.Green, sbThickness.Value);
  38.             }
  39.             else if (rbBlue.Checked == true)
  40.             {
  41.                 p = new Pen(Color.Blue, sbThickness.Value);
  42.             }
  43.  
  44.             if (rbCircle.Checked == true)
  45.             {
  46.                 Circle c = new Circle();
  47.                 c.draw(g, p, e.X, e.Y);
  48.             }
  49.             else if (rbSquare.Checked == true)
  50.             {
  51.                 Square s = new Square();
  52.                 s.draw(g, p, e.X, e.Y);
  53.             }
  54.             else if (rbTriangle.Checked == true)
  55.             {
  56.                 Triangle t = new Triangle();
  57.                 t.draw(g, p, e.X, e.Y);
  58.             }            
  59.         }
  60.     }
  61.  
  62.     class Circle
  63.     {
  64.         int r;
  65.         public Circle()
  66.         {
  67.             r = 10;
  68.         }
  69.         public void draw(Graphics g, Pen p, int x, int y)
  70.         {
  71.             g.DrawEllipse(p, x, y, r, r);
  72.         }
  73.     }
  74.  
  75.     class Square
  76.     {
  77.         int a, b;
  78.         public Square()
  79.         {
  80.             a = 10;
  81.             b = 10;
  82.         }
  83.         public void draw(Graphics g, Pen p, int x, int y)
  84.         {
  85.             g.DrawRectangle(p, x, y, a, b);
  86.         }
  87.     }
  88.  
  89.     class Triangle
  90.     {
  91.         int a;
  92.         public Triangle()
  93.         {
  94.         }
  95.         public void draw(Graphics g, Pen p, int x, int y)
  96.         {
  97.             Point[] points = { new Point(x, y), new Point(x + 90, y), new Point(x + 40, y + 90) };
  98.             g.DrawPolygon(p, points);
  99.         }
  100.     }
  101. }
Add Comment
Please, Sign In to add comment