当前位置: 首页>>代码示例>>C#>>正文


C# History.Undo方法代码示例

本文整理汇总了C#中History.Undo方法的典型用法代码示例。如果您正苦于以下问题:C# History.Undo方法的具体用法?C# History.Undo怎么用?C# History.Undo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在History的用法示例。


在下文中一共展示了History.Undo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShouldCorrectlyUndo

        public void ShouldCorrectlyUndo()
        {
            var history = new History();
            var element = new Ball() { X = 0, Y = 0 };
            var change = new TranslationChange(element, 5, 5);

            history.AddAndDo(change);
            history.Undo();

            Assert.IsFalse(history.CanUndo());
            Assert.IsTrue(history.CanRedo());

            Assert.AreEqual(0, element.X, 0.1);
            Assert.AreEqual(0, element.Y, 0.1);
        }
开发者ID:EusthEnoptEron,项目名称:Sketchball,代码行数:15,代码来源:HistoryTests.cs

示例2: ShouldRaiseEvents

        public void ShouldRaiseEvents()
        {
            var eventsRaised = 0;
            var history = new History();
            var element = new Ball() { X = 0, Y = 0 };
            var change = new TranslationChange(element, 5, 5);

            // Bind closure expression
            history.Change += () =>
            {
                eventsRaised++;
            };

            // Act
            history.AddAndDo(change);
            history.Undo();
            history.Redo();

            Assert.AreEqual(3, eventsRaised);
        }
开发者ID:EusthEnoptEron,项目名称:Sketchball,代码行数:20,代码来源:HistoryTests.cs

示例3: Test

        private static void Test()
        {
            int numberOfOperations = 20;
            Random random = new Random(DateTime.UtcNow.Millisecond);
            History<string> applicationHistory = new History<string>(null);
            string operationName = string.Empty;

            Console.WriteLine("Enter the number of random operations you'd like to add to the history:");

            if (!int.TryParse(Console.ReadLine(), out numberOfOperations))
            {
                numberOfOperations = 20;
            }

            Console.WriteLine("Testing with {0} random operation{1}...", numberOfOperations, numberOfOperations == 1 ? string.Empty : "s");

            for (int i = 0; i < numberOfOperations; i++)
            {
                operationName = GetOperation(random.Next());
                applicationHistory.AddItemToHistory(operationName);

                Console.WriteLine("Adding operation {0} to history...", operationName);
            }

            for (int i = 0; i < numberOfOperations; i++)
            {
                string op = applicationHistory.Undo();
                Console.WriteLine("Undoing operation {0} from history...", op);
            }

            for (int i = 0; i < numberOfOperations; i++)
            {
                string op = applicationHistory.Redo();
                Console.WriteLine("Redoing operation {0} from history...", op);
            }

            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("");
        }
开发者ID:longda,项目名称:HistorySystem,代码行数:40,代码来源:Program.cs

示例4: Interactive

        private static void Interactive()
        {
            History<string> appHistory = new History<string>();
            bool interactiveMode = true;
            string input = string.Empty;

            Console.WriteLine("");

            while (interactiveMode)
            {
                Console.Write("hist> ");
                input = Console.ReadLine();

                switch (input.ToLower())
                {
                    case "exit":
                        interactiveMode = false;
                        Console.WriteLine("hist> Exiting hist program... Thanks for playing!");
                        Console.WriteLine("");
                        Console.WriteLine("");
                        Console.WriteLine("");
                        break;

                    case "help":
                        Console.WriteLine("hist> Commands:");
                        Console.WriteLine("hist> exit - exit the hist program");
                        Console.WriteLine("hist> help - display this help text");
                        Console.WriteLine("hist> add - add input to the application history at the next prompt");
                        Console.WriteLine("hist> undo - undo the last input from the application history");
                        Console.WriteLine("hist> redo - redo the last input from the application history");
                        break;

                    case "add":
                        Console.WriteLine("hist> Enter text to add to history:");
                        Console.Write("hist> ");

                        input = Console.ReadLine();
                        Console.WriteLine("hist> Adding {0} to history...", input);
                        appHistory.AddItemToHistory(input);
                        break;

                    case "undo":
                        string undo = appHistory.Undo();

                        if (undo != null)
                        {
                            Console.WriteLine("hist> Undo {0} from application...", undo);
                        }
                        else
                        {
                            Console.WriteLine("hist> Nothing to undo...");
                        }
                        break;

                    case "redo":
                        string redo = appHistory.Redo();

                        if (redo != null)
                        {
                            Console.WriteLine("hist> Redo {0} to application...", redo);
                        }
                        else
                        {
                            Console.WriteLine("hist> Nothing to redo...");
                        }
                        break;

                    default:
                        Console.Beep();
                        Console.WriteLine("hist> Command not recognized...  Please try again.");
                        break;
                }
            }
        }
开发者ID:longda,项目名称:HistorySystem,代码行数:74,代码来源:Program.cs


注:本文中的History.Undo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。