Nerviie

pz

Dec 15th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 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 MelhorPuzzelDoMundo
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.         int[] valores = new int[9];
  20.         int tag;
  21.         private void Form1_Load(object sender, EventArgs e)
  22.         {
  23.             CreatePictureBox();
  24.         }
  25.         protected void numerosRandom()
  26.         {
  27.             int j;
  28.             Random rnd = new Random();
  29.             int indice = 0;
  30.  
  31.            
  32.             for (j = 0; j < 9; j++)
  33.             {
  34.                 int valorSorteado = rnd.Next(1, 9);
  35.                 while (indice < j)
  36.                 {
  37.                     if (valores[indice] == valorSorteado)
  38.                     {
  39.                         indice = 0;
  40.                         valorSorteado = rnd.Next(1, 9);
  41.                     }
  42.                     else indice++;
  43.                 }
  44.                 indice = 0;
  45.                 valores[j] = valorSorteado;
  46.             }
  47.         }
  48.          protected void CreatePictureBox()
  49.         {
  50.                 numerosRandom();
  51.  
  52.             for (int i = 1; i <= 9; i++)
  53.             {
  54.                
  55.                 string name = i.ToString();
  56.                // tag = i;
  57.                 PictureBox picbox = new PictureBox
  58.                 {
  59.                     Name = name,
  60.                    // Tag = tag,
  61.                     Size = new Size(100, 100),
  62.                     //ImageLocation = @"C:\Users\a14062.CIC\source\repos\MelhorPuzzelDoMundo\MelhorPuzzelDoMundo\Resources\" + valores[i - 1] + ".png",
  63.                     SizeMode = PictureBoxSizeMode.StretchImage
  64.                 };
  65.                
  66.                 if (i <= 3) picbox.Location = new System.Drawing.Point(i * 100, 100);
  67.                 else if (i > 3 && i <= 6) picbox.Location = new System.Drawing.Point((i - 3) * 100, 200);
  68.                 else picbox.Location = new System.Drawing.Point((i - 6) * 100, 300);
  69.                 Controls.Add(picbox);
  70.             }
  71.             }
  72.         }
  73.     }
Advertisement
Add Comment
Please, Sign In to add comment