示例#1
0
        /// <summary>
        /// Sets this <see cref="ImageBox"/> with a previously created memento.
        /// </summary>
        /// <param name="memento">Memento to set.</param>
        /// <remarks>
        /// This method restores the state of a <see cref="ImageBox"/> with
        /// a memento previously created by <see cref="ImageBox.CreateMemento"/>.
        /// </remarks>
        public virtual void SetMemento(object memento)
        {
            Platform.CheckForNullReference(memento, "memento");

            ImageBoxMemento imageBoxMemento = (ImageBoxMemento)memento;

            if (imageBoxMemento.Rows != this.Rows || imageBoxMemento.Columns != this.Columns)
            {
                _rows    = 0;
                _columns = 0;

                if (imageBoxMemento.Rows > 0 && imageBoxMemento.Columns > 0)
                {
                    this.SetTileGrid(imageBoxMemento.Rows, imageBoxMemento.Columns);
                }
            }

            _normalizedRectangle = RectangleF.Empty;

            DisplaySetLocked = false;
            this.DisplaySet  = imageBoxMemento.DisplaySet;
            if (this.DisplaySet != null)
            {
                this.DisplaySet.SetMemento(imageBoxMemento.DisplaySetMemento);
            }

            this.DisplaySetLocked = imageBoxMemento.DisplaySetLocked;

            this.NormalizedRectangle = imageBoxMemento.NormalizedRectangle;

            if (imageBoxMemento.TopLeftPresentationImageIndex != -1)
            {
                this.TopLeftPresentationImageIndex = imageBoxMemento.TopLeftPresentationImageIndex;
            }

            if (imageBoxMemento.IndexOfSelectedTile != -1)
            {
                ITile selectedTile = this.Tiles[imageBoxMemento.IndexOfSelectedTile];
                selectedTile.Select();
            }
        }
示例#2
0
        /// <summary>
        /// Creates a memento for this <see cref="ImageBox"/>.
        /// </summary>
        /// <returns>A memento for this <see cref="ImageBox"/>.</returns>
        /// <remarks>
        /// This method is used to remember the current state of a
        /// <see cref="ImageBox"/>.  The memento remembers the actual <see cref="Tile"/>
        /// <i>instances</i> contained in the <see cref="ImageBox"/>.  Calling
        /// <see cref="ImageBox.SetMemento"/> at a later time restores those instances.
        /// </remarks>
        public virtual object CreateMemento()
        {
            object displaySetMemento = null;

            if (this.DisplaySet != null)
            {
                displaySetMemento = this.DisplaySet.CreateMemento();
            }

            ImageBoxMemento imageBoxMemento =
                new ImageBoxMemento(this.DisplaySet,
                                    this.DisplaySetLocked,
                                    displaySetMemento,
                                    this.Rows,
                                    this.Columns,
                                    this.TopLeftPresentationImageIndex,
                                    this.NormalizedRectangle,
                                    this.IndexOfSelectedTile);

            return(imageBoxMemento);
        }