예제 #1
0
        private void undo_Click(object sender, EventArgs e)
        {
            if (_commandStack.Count > 0)
            {
                // Remove the last command
                iCommand lastCommand = _commandStack.Pop();

                //jika command adalah freehandcommand
                if (Convert.ToString(lastCommand).Contains("freehand"))
                {
                    while (Convert.ToString(lastCommand).Contains("freehand") && _commandStack.Count > 0)
                    {
                        lastCommand = _commandStack.Pop();
                        lastCommand.Undo();

                        //jika ternyata lastcommand tidak freehand lagi
                        if (!Convert.ToString(lastCommand).Contains("freehand"))
                        {
                            //kembalikan ke stack
                            _commandStack.Push(lastCommand);
                        }
                    }
                }
                else
                {
                    lastCommand.Undo();
                }
                panel1.Refresh();
            }
        }
예제 #2
0
        private void erase_button_Click(object sender, EventArgs e)
        {
            if (_commandStack.Count > 0)
            {
                while (_commandStack.Count > 0)
                {
                    iCommand lastCommand = _commandStack.Pop();

                    lastCommand.Undo();
                }
                panel1.Refresh();
            }
        }