Exemple #1
0
        private void OpenFile()
        {
            try
            {
                // Get data from the saved file
                IFormatter      formatter  = new BinaryFormatter();
                Stream          stream     = new FileStream(m_currFilename, FileMode.Open, FileAccess.Read, FileShare.Read);
                DominoFileClass dominoFile = (DominoFileClass)formatter.Deserialize(stream);
                stream.Close();

                // Pass the data to the side bar
                m_imagesLibrary.ImportFromFile(dominoFile.m_imagesPaths);

                // Pass the data to the slots panel
                m_slotsPanel.ImportFromFile(
                    dominoFile.m_sourceRectangles,
                    dominoFile.m_rectangleColors,
                    dominoFile.m_bitmaps,
                    dominoFile.m_slotInd,
                    dominoFile.m_approvedSlots);

                // Pass the data to the crop panel
                m_cropPanel.DisplayImage(
                    dominoFile.m_bitmaps[dominoFile.m_slotInd],
                    dominoFile.m_sourceRectangles[dominoFile.m_slotInd]);
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, m_langDictionary["Open"], MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Exemple #2
0
        private void SaveFile()
        {
            try
            {
                // Save the necessary data for the serialization
                DominoFileClass dominoFile = new DominoFileClass();
                dominoFile.m_imagesPaths      = m_imagesLibrary.ImagesPaths;
                dominoFile.m_sourceRectangles = m_slotsPanel.SourceRectangles;
                dominoFile.m_rectangleColors  = m_slotsPanel.RectanglesColors;
                dominoFile.m_bitmaps          = m_slotsPanel.Bitmaps;
                dominoFile.m_slotInd          = m_slotsPanel.SlotIndex;
                dominoFile.m_approvedSlots    = m_slotsPanel.ApprovedSlots;

                // Serialize
                IFormatter formatter = new BinaryFormatter();
                Stream     stream    = new FileStream(m_currFilename, FileMode.Create, FileAccess.Write, FileShare.None);
                formatter.Serialize(stream, dominoFile);
                stream.Close();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, m_langDictionary["Save"], MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }