ZForge.Controls.TreeViewAdv.NumericTextBox.WndProc C# (CSharp) Method

WndProc() protected method

Method invoked when Windows sends a message.
This is over-ridden so that the user can not use cut or paste operations to bypass the TextChanging event. This catches ContextMenu Paste, Shift+Insert, Ctrl+V, While it is generally frowned upon to override WndProc, no other simple mechanism was apparent to simultaneously and transparently intercept so many different operations.
protected WndProc ( Message &m ) : void
m Message Message from Windows.
return void
        protected override void WndProc(ref Message m)
        {
            // Switch to handle message...
            switch (m.Msg)
            {
                case WM_PASTE:
                    {
                        // Get clipboard object to paste
                        IDataObject clipboardData = Clipboard.GetDataObject();

                        // Get text from clipboard data
                        string pasteText = (string)clipboardData.GetData(
                                DataFormats.UnicodeText);

                        // Get the number of characters to replace
                        int selectionLength = SelectionLength;

                        // If no replacement or insertion, we are done
                        if (pasteText.Length == 0)
                        {
                            break;
                        }
                        else if (selectionLength != 0)
                        {
                            base.Text = base.Text.Remove(SelectionStart, selectionLength);
                        }

                        bool containsInvalidChars = false;
                        foreach (char c in pasteText)
                        {
                            if (containsInvalidChars)
                            {
                                break;
                            }
                            else if (invalidNumeric(c))
                            {
                                containsInvalidChars = true;
                            }
                        }

                        if (!containsInvalidChars)
                        {
                            base.Text = base.Text.Insert(SelectionStart, pasteText);
                        }

                        return;
                    }

            }
            base.WndProc(ref m);
        }