Пример #1
0
        private void FormSimVille_Load(object sender, EventArgs e)
        {
            #region images dans les contrôles

            radioButtonEnergie.ImageIndex = 2;
            radioButtonPolice.ImageIndex = 3;
            radioButtonHopital.ImageIndex = 4;
            radioButtonRésidentiel.ImageIndex = 5;
            radioButtonCommercial.ImageIndex = 6;
            radioButtonStade.ImageIndex = 7;
            radioButtonStatistiques.ImageIndex = 14;

            #endregion

            terrain = new Region(imageListImages);
            //PictureBoxRegion[]
            EventHandler evenementClick = new System.EventHandler(this.PictureBoxRegionClick);
            for (int i = 0; i < 20; i++)
            {
                for (int j = 0; j < 12; j++)
                {
                    pictureBoxRegion[i, j] = new PictureBox();
                    //On assigne un champ lors de la première génération
                    pictureBoxRegion[i, j].Dock = DockStyle.Fill;
                    pictureBoxRegion[i, j].Image = imageListImages.Images[terrain.ImageID(i, j)];
                    pictureBoxRegion[i, j].Margin = new Padding(0, 0, 0, 0);
                    tableLayoutPanelRegion.Controls.Add(pictureBoxRegion[i, j], i, j);
                    pictureBoxRegion[i, j].Click += evenementClick;
                }
            }
            terrain.Generation();
            UpdateImage();
            timerMinuterie.Start();
        }
Пример #2
0
        /// <summary>
        /// Ouvre un objet Région précédement enregistrer
        /// </summary>
        private void buttonOuvrir_Click(object sender, EventArgs e)
        {
            timerMinuterie.Stop();

            OpenFileDialog openFileDialog = new OpenFileDialog();
            DialogResult resultat = openFileDialog.ShowDialog();
            try
            {
                Stream flux = openFileDialog.OpenFile();

                if (resultat == DialogResult.OK)
                    try
                    {
                        BinaryFormatter formatter = new BinaryFormatter();
                        //Read
                        terrain = (Region)formatter.Deserialize(flux);
                        UpdateImage();
                        MessageBox.Show("Ouverture terminée!");
                        flux.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Erreur! " + Environment.NewLine + ex.Message);
                    }
                    finally
                    {
                        if (flux != null)
                            flux.Close();
                    }
                timerMinuterie.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erreur! " + Environment.NewLine + ex.Message);
            }
        }