Example #1
0
 private void ButtonViewImage_Click(object sender, EventArgs e)
 {
     if (image != null)
     {
         Form       currentImageForm = new Form();
         PictureBox picture          = new PictureBox
         {
             Image    = BitmapHelper.CreateBitmapImage(image, groupBoxPuzzle.Width, groupBoxPuzzle.Height),
             SizeMode = PictureBoxSizeMode.AutoSize
         };
         currentImageForm.Controls.Add(picture);
         currentImageForm.Size          = new Size(groupBoxPuzzle.Width, groupBoxPuzzle.Height + 30);
         currentImageForm.StartPosition = FormStartPosition.CenterScreen;
         currentImageForm.MinimizeBox   = false;
         currentImageForm.MaximizeBox   = false;
         currentImageForm.ShowDialog();
     }
 }
Example #2
0
        private void ButtonShuffle_Click(object sender, EventArgs e)
        {
            numberOfRows     = Convert.ToInt32(numericUpDownRows.Value);
            numberOfColumns  = Convert.ToInt32(numericUpDownColumns.Value);
            countOfFragments = numberOfRows * numberOfColumns;

            if (pictureboxPuzzle != null)
            {
                groupBoxPuzzle.Controls.Remove(pictureboxPuzzle);
                pictureboxPuzzle.Dispose();
                pictureboxPuzzle = null;
            }

            if (mysteryBoxes == null)
            {
                images       = new Image[countOfFragments];
                mysteryBoxes = new MysteryBox[countOfFragments];
            }
            else
            {
                for (int j = 0; j < mysteryBoxes.Length; j++)
                {
                    //images[j].Dispose();
                    images[j] = null;

                    //mysteryBoxes[j].Dispose();
                    mysteryBoxes[j] = null;
                }

                images       = new Image[countOfFragments];
                mysteryBoxes = new MysteryBox[countOfFragments];
            }

            int unitX = groupBoxPuzzle.Width / numberOfColumns;
            int unitY = groupBoxPuzzle.Height / numberOfRows;

            int[] indice = new int[countOfFragments];

            for (int i = 0; i < countOfFragments; i++)
            {
                indice[i] = i;

                if (mysteryBoxes[i] != null)
                {
                    mysteryBoxes[i].BorderStyle = BorderStyle.Fixed3D;
                    groupBoxPuzzle.Controls.Remove(mysteryBoxes[i]);
                    mysteryBoxes[i] = null;
                }

                if (mysteryBoxes[i] == null)
                {
                    mysteryBoxes[i]             = new MysteryBox();
                    mysteryBoxes[i].Click      += new EventHandler(OnPuzzleClick);
                    mysteryBoxes[i].BorderStyle = BorderStyle.Fixed3D;
                    mysteryBoxes[i].SizeMode    = PictureBoxSizeMode.CenterImage;
                    mysteryBoxes[i].Width       = unitX;
                    mysteryBoxes[i].Height      = unitY;
                }

                mysteryBoxes[i].Index = i;
                BitmapHelper.CreateBitmapImage(image, images, i, numberOfColumns, unitX, unitY);
                mysteryBoxes[i].Location = new Point(unitX * (i % numberOfColumns), unitY * (i / numberOfColumns));

                if (!groupBoxPuzzle.Controls.Contains(mysteryBoxes[i]))
                {
                    groupBoxPuzzle.Controls.Add(mysteryBoxes[i]);
                }
            }

            Shuffle(ref indice);

            listOfShuffledImages = new List <Bitmap>(countOfFragments);

            for (int i = 0; i < countOfFragments; i++)
            {
                listOfShuffledImages.Add((Bitmap)images[indice[i]]);
                mysteryBoxes[i].ImageIndex = indice[i];
                mysteryBoxes[i].Image      = images[indice[i]];
            }

            numericUpDownRows.Enabled             = false;
            numericUpDownColumns.Enabled          = false;
            buttonCheck.Enabled                   = true;
            buttonAutomaticAssemblyPuzzle.Enabled = true;
        }