Esempio n. 1
0
        private void PopupForm_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.Return:
            case Keys.Tab:
                DialogResult = DialogResult.OK;
                Close();
                break;

            case Keys.Escape:
                DialogResult = DialogResult.Cancel;
                Close();
                break;

            case Keys.F1:
                if (!(_Intellisense.Help?.SupportsHelp ?? false))
                {
                    return;
                }

                var item = SelectedItem;
                if (item == null)
                {
                    return;
                }

                string htmlContent = null;
                var    taskContent = Task.Run(() => htmlContent = _Intellisense.Help.GetHelpHtmlContent(item));

                var commentForm = new RichTextViewer()
                {
                    Location = _Editor.PointToScreen(new Point(_Editor.Right + 20, _Editor.Top)),
                    Height   = Math.Max(Convert.ToInt32(_Editor.Height), 500)
                };

                var screen = Screen.FromControl(_Editor);
                if (commentForm.Bottom > screen.WorkingArea.Bottom)
                {
                    commentForm.Top = Math.Max(screen.WorkingArea.Bottom - commentForm.Height, 10);
                }
                if (commentForm.Right > screen.WorkingArea.Right)
                {
                    commentForm.Left = Math.Max(screen.WorkingArea.Right - commentForm.Width, 10);
                }

                commentForm.FormClosed += (s, e) =>
                {
                    commentForm.Dispose();
                };

                commentForm.Show(_Editor);

                taskContent.Wait();
                commentForm.LoadHtmlText(htmlContent);

                Close();

                commentForm.Activate();
                break;

            case Keys.F2:
                if (!(_Intellisense.Help?.SupportsOnlineHelp ?? false))
                {
                    return;
                }

                var selItem = SelectedItem;
                if (selItem == null)
                {
                    return;
                }

                _Intellisense.Help.ShowOnlineHelp(selItem);
                break;

            case Keys.Left:
            case Keys.Right:
            case Keys.Up:
            case Keys.Down:
                break;

            default:
                if (_Editor != null && _Editor.ActiveViewControl != null)
                {
                    typeof(Control).InvokeMember(nameof(OnKeyDown),
                                                 BindingFlags.InvokeMethod | BindingFlags.NonPublic |
                                                 BindingFlags.Instance,
                                                 null, _Editor.ActiveViewControl, new object[] { e });
                }
                break;
            }
        }