Facebook
From orlik, 4 Years ago, written in Plain Text.
This paste is a reply to piu_15.01 from orlik - view diff
Embed
Download Paste or View Raw
Hits: 244
  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.  
  11.  
  12.  
  13. namespace zaj4
  14. {
  15.  
  16.  
  17.     public partial class Form1 : Form
  18.     {
  19.  
  20.         int R = 0, G = 0, B = 0;
  21.         int figura;
  22.         Random rnd = new Random();
  23.         Timer czas = new Timer();
  24.  
  25.         public Form1()
  26.         {
  27.  
  28.             InitializeComponent();
  29.             DoubleBuffered = true;
  30.         }
  31.  
  32.         private void button1_Click(object sender, EventArgs e)
  33.         {
  34.             figura = 1;
  35.             this.Invalidate();
  36.             //Graphics formGraphics = this.CreateGraphics();
  37.  
  38.             // int j = 0;
  39.             // int k = 0;
  40.             // for (int i = 0; i < 100; i++)
  41.             // {
  42.             //     if (j == 10)
  43.             //     {
  44.             //         k++;
  45.             //         j = 0;
  46.             //     }
  47.             //     R = rnd.Next(0, 255);
  48.             //     G = rnd.Next(0, 255);
  49.             //     B = rnd.Next(0, 255);
  50.             //     System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(Color.FromArgb(R, G, B));
  51.             //     formGraphics.FillRectangle(myBrush, new Rectangle(new Point(10 + 30 * j, 120 + 30 * k), new Size(25, 25)));
  52.             //     j++;
  53.             //  }
  54.  
  55.  
  56.         }
  57.  
  58.         private void button2_Click(object sender, EventArgs e)
  59.         {
  60.            
  61.  
  62.             figura = 2;
  63.             this.Invalidate();
  64.            
  65.         }
  66.  
  67.  
  68.  
  69.         private void button3_Click(object sender, EventArgs e)
  70.         {
  71.  
  72.             figura = 3;
  73.             this.Invalidate();
  74.            
  75.         }
  76.         private void button4_Click(object sender, EventArgs e)
  77.         {
  78.         }
  79.  
  80.         private void Form1_Load(object sender, EventArgs e)
  81.         {
  82.  
  83.         }
  84.  
  85.         private void Form1_Paint(object sender, PaintEventArgs e)
  86.         {
  87.          
  88.             Graphics formGraphics = this.CreateGraphics();
  89.             int j = 0;
  90.             int k = 0;
  91.             for (int i = 0; i < 100; i++)
  92.             {
  93.                 if (j == 10)
  94.                 {
  95.                     k++;
  96.                     j = 0;
  97.                 }
  98.                 R = rnd.Next(0, 255);
  99.                 G = rnd.Next(0, 255);
  100.                 B = rnd.Next(0, 255);
  101.  
  102.                 switch (figura)
  103.                 {
  104.                     case 1:
  105.                         {
  106.                             System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(Color.FromArgb(R, G, B));
  107.                             formGraphics.FillRectangle(myBrush, new Rectangle(new Point(10 + 30 * j, 120 + 30 * k), new Size(25, 25)));
  108.                             j++;
  109.                         }
  110.  
  111.                         break;
  112.                     case 2:
  113.                         {
  114.                             Point[] p = new Point[3];
  115.                             p[0] = new Point(10 + 30 * j, 140 + 30 * k);
  116.                             p[1] = new Point(30 + 30 * j, 140 + 30 * k);
  117.                             p[2] = new Point(20 + 30 * j, 120 + 30 * k);
  118.  
  119.                             formGraphics.FillPolygon(Brushes.Fuchsia, p);
  120.                             System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(Color.FromArgb(R, G, B));
  121.                             formGraphics.FillPolygon(myBrush, p);
  122.                             j++;
  123.                         }
  124.                         break;
  125.                     case 3:
  126.                         {
  127.                             System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(Color.FromArgb(R, G, B));
  128.                             formGraphics.FillEllipse(myBrush, new Rectangle(new Point(10 + 30 * j, 120 + 30 * k), new Size(25, 25)));
  129.                             j++;
  130.                         }
  131.                         break;
  132.                 }
  133.             }
  134.  
  135.         }
  136.     }
  137. }
  138.