示例#1
0
        private void SetState(IPixmapSlicerState nextState)
        {
            this.stateControlToolStrip.SuspendLayout();

            // Tear down old state
            if (this.state != null)
            {
                this.state.OnStateLeaving(EventArgs.Empty);

                // Unsubscribe from event handlers
                this.state.StateEndRequested    -= this.OnStateCancelled;
                this.state.StateChangeRequested -= this.OnStateChangeRequested;

                // Remove old states controls
                foreach (ToolStripItem item in this.state.StateControls)
                {
                    this.stateControlToolStrip.Items.Remove(item);
                }
            }

            this.state      = nextState;
            this.state.View = this.pixmapView;
            this.state.StateEndRequested    += this.OnStateCancelled;
            this.state.StateChangeRequested += this.OnStateChangeRequested;

            // Add controls for the given state
            if (this.state.StateControls != null && this.state.StateControls.Count > 0)
            {
                foreach (ToolStripItem item in this.state.StateControls)
                {
                    this.stateControlToolStrip.Items.Add(item);
                }
            }

            this.stateControlToolStrip.ResumeLayout();

            this.UpdateIndicesButton();
            this.pixmapView.Invalidate();

            if (this.state != null)
            {
                this.state.OnStateEntered(EventArgs.Empty);
            }
        }
示例#2
0
        private void OnStateChangeRequested(object sender, PixmapSlicerStateEventArgs e)
        {
            IPixmapSlicerState newState = (IPixmapSlicerState)Activator.CreateInstance(e.StateType);

            this.SetState(newState);
        }