Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace MelhorPuzzelDoMundo
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- int[] valores = new int[9];
- int tag;
- private void Form1_Load(object sender, EventArgs e)
- {
- CreatePictureBox();
- }
- protected void numerosRandom()
- {
- int j;
- Random rnd = new Random();
- int indice = 0;
- for (j = 0; j < 9; j++)
- {
- int valorSorteado = rnd.Next(1, 9);
- while (indice < j)
- {
- if (valores[indice] == valorSorteado)
- {
- indice = 0;
- valorSorteado = rnd.Next(1, 9);
- }
- else indice++;
- }
- indice = 0;
- valores[j] = valorSorteado;
- }
- }
- protected void CreatePictureBox()
- {
- numerosRandom();
- for (int i = 1; i <= 9; i++)
- {
- string name = i.ToString();
- // tag = i;
- PictureBox picbox = new PictureBox
- {
- Name = name,
- // Tag = tag,
- Size = new Size(100, 100),
- //ImageLocation = @"C:\Users\a14062.CIC\source\repos\MelhorPuzzelDoMundo\MelhorPuzzelDoMundo\Resources\" + valores[i - 1] + ".png",
- SizeMode = PictureBoxSizeMode.StretchImage
- };
- if (i <= 3) picbox.Location = new System.Drawing.Point(i * 100, 100);
- else if (i > 3 && i <= 6) picbox.Location = new System.Drawing.Point((i - 3) * 100, 200);
- else picbox.Location = new System.Drawing.Point((i - 6) * 100, 300);
- Controls.Add(picbox);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment