Beispiel #1
0
        // Perform the command associated with MenuIndex on the specified TextBoxBase.
        private void DoTextBoxCommand(TextBoxBase textbox, MenuIndex menuIndex)
        {
            switch (menuIndex)
            {
            case MenuIndex.Undo:            textbox.Undo();                         break;

            case MenuIndex.Redo:
                if (textbox is RichTextBox)
                {
                    RichTextBox rt = (RichTextBox)textbox;
                    rt.Redo();
                }
                break;

            case MenuIndex.Cut:                     textbox.Cut();                          break;

            case MenuIndex.Copy:            textbox.Copy();                         break;

            case MenuIndex.Paste:           textbox.Paste();                        break;

            case MenuIndex.Delete:          textbox.SelectedText = "";      break;

            case MenuIndex.SelectAll:       textbox.SelectAll();            break;

            case MenuIndex.Properties:                                                              break;
            }
        }
Beispiel #2
0
        private void processKbdCtrlShortcuts(object sender, KeyEventArgs e)
        {
            TextBoxBase t = (TextBoxBase)sender;

            if (e.KeyData == (Keys.C | Keys.Control))
            {
                t.Copy();
                e.Handled = true;
            }
            else if (e.KeyData == (Keys.X | Keys.Control))
            {
                t.Cut();
                e.Handled = true;
            }
            else if (e.KeyData == (Keys.V | Keys.Control))
            {
                t.Paste();
                e.Handled = true;
            }
            else if (e.KeyData == (Keys.A | Keys.Control))
            {
                t.SelectAll();
                e.Handled = true;
            }
            else if (e.KeyData == (Keys.Z | Keys.Control))
            {
                t.Undo();
                e.Handled = true;
            }
        }
Beispiel #3
0
 private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (ActiveControl is TextBoxBase)
     {
         TextBoxBase tb = (TextBoxBase)ActiveControl;
         tb.Paste();
     }
 }
Beispiel #4
0
        public void Paste()
        {
            TextBoxBase textBox = FindFocusedTextBox();

            if (textBox != null)
            {
                textBox.Paste();
            }
        }
Beispiel #5
0
 public void Paste()
 {
     if (isFc)
     {
         fc.Paste();
     }
     else
     {
         tb.Paste();
     }
 }
 public void Paste()
 {
     textBox.Paste();
 }
Beispiel #7
0
        public static void ProcessTextContextMenu(TextBoxBase textbox, object sender)
        {
            var tsmi = sender as ToolStripMenuItem;

            if (tsmi == null)
            {
                return;
            }

            var cmd = tsmi.Tag as string;

            var text = string.Empty;

            try
            {
                if (cmd == FormStringKeys.STR_MENU_ITEM_COPY_ALL.ToString())
                {
                    if (textbox.Text != "")
                    {
                        Clipboard.SetText(textbox.Text);
                    }
                }
                else if (cmd == FormStringKeys.STR_MENU_ITEM_COPY.ToString())
                {
                    if (textbox.SelectedText != "")
                    {
                        Clipboard.SetText(textbox.SelectedText);
                    }
                }
                else if (cmd == FormStringKeys.STR_MENU_ITEM_CUT.ToString())
                {
                    if (textbox.SelectedText != "")
                    {
                        textbox.Cut();
                    }
                }
                else if (cmd == FormStringKeys.STR_MENU_ITEM_PASTE.ToString())
                {
                    if (Clipboard.ContainsText())
                    {
                        //TODO no RTF
                        textbox.Paste();
                    }
                }
                else if (cmd == FormStringKeys.STR_MENU_ITEM_SELECT_ALL.ToString())
                {
                    textbox.Focus();
                    textbox.SelectAll();
                }
                else if (cmd == FormStringKeys.STR_MENU_ITEM_CLEAR.ToString())
                {
                    textbox.Clear();
                }
                else if (cmd == FormStringKeys.STR_MENU_ITEM_DELETE.ToString())
                {
                    if (textbox.SelectionLength > 0)
                    {
                        var oldStart = textbox.SelectionStart;
                        textbox.Text           = textbox.Text.Remove(textbox.SelectionStart, textbox.SelectionLength);
                        textbox.SelectionStart = oldStart;
                    }
                }
                else if (cmd == FormStringKeys.STR_MENU_ITEM_SAVE.ToString())
                {
                    var sfd = new SaveFileDialog();
                    sfd.Filter = ResxManager.GetResourceString(FormStringKeys.STR_TEXT_SAVE_FILTER);
                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        File.WriteAllText(sfd.FileName, textbox.Text);
                    }
                }
                else if (cmd == FormStringKeys.STR_MENU_ITEM_WORDWRAP.ToString())
                {
                    textbox.WordWrap = !tsmi.Checked;
                }
                else if (cmd == FormStringKeys.STR_MENU_ITEM_SEND_TO_SOURCE.ToString())
                {
                    //TODO STR_MENUITEM_SEND_TO_SOURCE
                }
                else if (cmd == FormStringKeys.STR_MENU_ITEM_UNDO.ToString())
                {
                    if (textbox.CanUndo)
                    {
                        textbox.Undo();
                    }
                }
                else if (cmd == FormStringKeys.STR_MENU_ITEM_COPY_AS_REGEX.ToString())
                {
                    text = textbox.SelectedText;
                    if (text != string.Empty)
                    {
                        IRegexAnalyst ra = new RegexAnalyst();
                        text = ra.ToSimpleRegexString(text);
                        Clipboard.SetText(text);
                    }
                }
                else if (cmd == FormStringKeys.STR_MENU_ITEM_TO_REGEX_FORMAT.ToString())
                {
                    text = textbox.SelectedText;

                    if (text == string.Empty)
                    {
                        text = textbox.Text;
                    }

                    if (text != string.Empty)
                    {
                        IRegexAnalyst ra = new RegexAnalyst();
                        text = ra.ToSimpleRegexString(text);

                        if (textbox.SelectedText.Length > 0)
                        {
                            if (text != textbox.SelectedText)
                            {
                                //TODO it can be undo,but affect the clipboard
                                Clipboard.SetText(text);
                                textbox.Paste();
                                Clipboard.Clear();
                            }
                        }
                        else
                        {
                            if (text != textbox.Text)
                            {
                                //TODO it can be undo,but affect the clipboard
                                Clipboard.SetText(text);
                                textbox.SelectAll();
                                textbox.Paste();
                                Clipboard.Clear();
                            }
                        }
                    }
                }
                else if (cmd == FormStringKeys.STR_MENU_ITEM_SELECTION_ONLY.ToString())
                {
                    tsmi.Checked = !tsmi.Checked;
                    //textbox.HideSelection = !tsmi.Checked;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Beispiel #8
0
 public static void PasteText(TextBoxBase textBox) => textBox.Paste();