Пример #1
0
        /// <summary>
        /// Handles the key pressed by the user
        /// </summary>
        /// <param name="e"></param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            var shouldRefresh = false;

            // cache list of tools (it can change during execute of OnKeyDown)
            var toolsList = tools.ToList();

            foreach (var tool in toolsList)
            {
                if (e.KeyCode == Keys.Escape)
                {
                    // if the user presses the escape key first cancel an operation in progress
                    if (tool.IsBusy)
                    {
                        tool.Cancel();
                        shouldRefresh = true;
                    }
                    continue;
                }
                tool.OnKeyDown(e);
            }

            if ((!toolsList.Any(t => t.IsBusy)) && (e.KeyCode == Keys.Escape) && (!SelectTool.IsActive))
            {
                // if the user presses the escape key and there was no operation in progress switch to select.
                ActivateTool(SelectTool);
                shouldRefresh = true;
            }

            if (shouldRefresh)
            {
                Refresh();
            }
        }