コード例 #1
0
        // Use the DataObject.Pasting Handler

        /// <summary>
        /// The text box on pasting.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void TextBoxOnPasting([CanBeNull] object sender, [CanBeNull] DataObjectPastingEventArgs e)
        {
            if (e != null && e.DataObject.GetDataPresent(typeof(string)))
            {
                var text = (string)e.DataObject.GetData(typeof(string));
                if (!IsTextAllowed(text ?? throw new InvalidOperationException()))
                {
                    e.CancelCommand();
                }
            }
            else
            {
                e?.CancelCommand();
            }
        }
コード例 #2
0
        private void OnValueTextBoxPaste(object sender, DataObjectPastingEventArgs e)
        {
            var    textBox     = (TextBox)sender;
            string textPresent = textBox.Text;

            var isText = e.SourceDataObject.GetDataPresent(DataFormats.Text, true);

            if (!isText)
            {
                return;
            }

            var text = e.SourceDataObject.GetData(DataFormats.Text) as string;

            string newText = string.Concat(textPresent.Substring(0, textBox.SelectionStart), text, textPresent.Substring(textBox.SelectionStart + textBox.SelectionLength));
            double number;

            if (!ValidateText(newText, out number))
            {
                e.CancelCommand();
            }
        }
コード例 #3
0
        private void txtInput_Pasting(object sender, DataObjectPastingEventArgs e)
        {
            if (e.DataObject.GetDataPresent(typeof(string)))
            {
                var text = e.DataObject.GetData(typeof(string)) as string;
                if (text.Contains(Environment.NewLine))
                {
                    e.CancelCommand();

                    var parts = text.Split(Environment.NewLine.ToCharArray()).Where((s) => s.Trim().Length > 0).ToArray();
                    if (parts.Length > App.Settings.Current.Buffer.MaximumPasteLines)
                    {
                        Dispatcher.BeginInvoke((Action)(() =>
                        {
                            if (!App.Confirm(_window, string.Format("Are you sure you want to paste more than {0} lines?",
                                                                    App.Settings.Current.Buffer.MaximumPasteLines), "Paste Warning"))
                            {
                                return;
                            }
                            foreach (var part in parts)
                            {
                                txtInput.Text = txtInput.Text.Substring(0, txtInput.SelectionStart);
                                txtInput.Text += part;
                                this.SubmitInput();
                            }
                        }));
                    }
                    else
                    {
                        foreach (var part in parts)
                        {
                            txtInput.Text  = txtInput.Text.Substring(0, txtInput.SelectionStart);
                            txtInput.Text += part;
                            this.SubmitInput();
                        }
                    }
                }
            }
        }
コード例 #4
0
        private void PastingHandler(object sender, DataObjectPastingEventArgs e)
        {
            TextBox textBox = sender as TextBox;

            if (textBox == null)
            {
                return;
            }

            if (e.DataObject.GetDataPresent(typeof(string)))
            {
                //Read input
                string pasteText = e.DataObject.GetData(typeof(string)) as string;
                // Kommt ein neuer String zurück, wird dieser eingefügt und die ursprüngliche Operation abgebrochen.
                if (!string.IsNullOrEmpty(pasteText))
                {
                    // Neuen Text einbringen
                    textBox.Text = pasteText;
                    // Restliches Einfügen abbrechen
                    e.CancelCommand();
                }
            }
        }
コード例 #5
0
        private void PasteCommand(object sender, DataObjectPastingEventArgs args)
        {
            var text = (string)args.DataObject.GetData(typeof(string));

            if (!string.IsNullOrEmpty(text))
            {
                if (Selection.Start != Selection.End)
                {
                    Selection.Start.DeleteTextInRun(Selection.Text.Length);
                    Selection.Start.InsertTextInRun(text);

                    var selectionEnd = Selection.Start.GetPositionAtOffset(text.Length);
                    CaretPosition = selectionEnd;
                }
                else
                {
                    AddLine(text);
                }
            }

            args.CancelCommand();
            args.Handled = true;
        }
コード例 #6
0
 private void OnPaste(object sender, DataObjectPastingEventArgs e)
 {
     if (e.DataObject.GetDataPresent(DataFormats.Text))
     {
         try
         {
             var currentTimeSpan = TimeSpanParse(Convert.ToString(e.DataObject.GetData(DataFormats.Text)).Trim(), _timerFormat == TimerFormats.Minutes);
             if (currentTimeSpan > _maxTimeSpan)
             {
                 currentTimeSpan = _maxTimeSpan;
             }
             if (currentTimeSpan < TimeSpan.Zero)
             {
                 currentTimeSpan = TimeSpan.Zero;
             }
             SetValue(_textBox, currentTimeSpan);
             _textBox.Text           = TimeSpanFormat(currentTimeSpan, _formatString);
             _textBox.SelectionStart = 0;
         }
         catch { }
     }
     e.CancelCommand();
 }
コード例 #7
0
        /// <summary>
        /// Pasting prüft ob korrekte Daten reingepastet werden
        /// </summary>
        private void Pasting(object sender, DataObjectPastingEventArgs e)
        {
            //nur strg+c zulassen kein drag&drop
            if (e.DataObject.GetDataPresent(typeof(string)) && !e.IsDragDrop)
            {
                var pastedText = HandleCharacterCasing((string)e.DataObject.GetData(typeof(string)));

                this.TreatSelectedText();

                var position = GetNextCharacterPosition(AssociatedObject.CaretIndex);
                if (!this.Provider.InsertAt(pastedText, position))
                {
                    System.Media.SystemSounds.Beep.Play();
                }
                else
                {
                    this.RefreshText(position);
                    this.AssociatedObject.Focus();
                }
            }

            e.CancelCommand();
        }
コード例 #8
0
        private void OnPaste(object sender, DataObjectPastingEventArgs e)
        {
            var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true);

            if (!isText)
            {
                return;
            }

            var text = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string;

            if (sender == txtPTR)
            {
                txtPTR.Text = text;
                SetRef(text);
            }
            else if (sender == txtREF)
            {
                txtREF.Text = text;
                SetPtr(text);
            }
            e.CancelCommand();
        }
コード例 #9
0
        /// <summary>
        /// Проверка и очистка текста, вставляемого из буфера обмена
        /// </summary>
        /// <param name="sender">TextBox получивший данные из буфера обмена</param>
        /// <param name="e"></param>
        private void OnPaste(object sender, DataObjectPastingEventArgs e)
        {
            if (modifiedPaste == false)
            {
                modifiedPaste = true;
                var tb = sender as TextBox;

                var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true);
                if (!isText)
                {
                    return;
                }

                var text = (e.SourceDataObject.GetData(DataFormats.UnicodeText) as string).ToUpper();


                var alphabet = (int)cbAlphabet.SelectedIndex == 0 ? "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ " : "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";

                var newText = string.Empty;

                foreach (var item in text)
                {
                    if (alphabet.IndexOf(item) > -1)
                    {
                        newText += item;
                    }
                }

                e.CancelCommand();
                Clipboard.SetData(DataFormats.UnicodeText, newText);
                ApplicationCommands.Paste.Execute(newText, tb);
            }
            else
            {
                modifiedPaste = false;
            }
        }
コード例 #10
0
        private void OnPaste(object sender, DataObjectPastingEventArgs e)
        {
            var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true);

            if (!isText)
            {
                return;
            }

            string pastedText = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string;

            for (int i = 0; i < pastedText.Length; i++)
            {
                char target = pastedText[i];

                if (IsDoubleByteChar(target))
                {
                    continue;
                }

                string textInTextBox = AppendTextForCheck(target.ToString());

                if (SelectionLength != 0)
                {
                    CaretIndex = SelectionStart;
                }

                int previousCaretIndex = CaretIndex;
                if (CanUpdateText(textInTextBox))
                {
                    Text       = textInTextBox;
                    CaretIndex = previousCaretIndex + 1;
                }
            }

            e.CancelCommand();
        }
コード例 #11
0
        /// <summary>
        /// <c>DataObject.Pasting</c> 添付イベントを処理するメソッドを表します。
        /// </summary>
        /// <param name="sender">対象の <see cref="DependencyObject"/>。</param>
        /// <param name="e">イベントのデータ。</param>
        private static void UIElement_PastingEventHandler(object sender, DataObjectPastingEventArgs e)
        {
            // 貼り付けようとしている文字列を取得
            string clipboard = e.DataObject.GetData(typeof(string)) as string;

            // 許容された文字列のみになるよう、フィルターする
            clipboard = ValidText(sender, clipboard);

            // フィルタの結果、貼り付けるべき文字列がなくなったら、コマンド自体をキャンセルする
            if (string.IsNullOrEmpty(clipboard) == true)
            {
                e.CancelCommand();
                e.Handled = true;
            }

            // 貼り付けるべきデータをフィルター済みの文字列に差し替える
            // DataObject は Freeze されているので、新たに DataObject を生成してセットする
            DataObject d = new DataObject();

            d.SetData(DataFormats.Text, clipboard);
            e.DataObject = d;

            return;
        }
コード例 #12
0
        private static void OnPaste(object sender, DataObjectPastingEventArgs e)
        {
            var textBox = (TextBox)sender;

            e.CancelCommand();

            bool notText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true) == false;

            if (notText)
            {
                return;
            }

            string text               = e.SourceDataObject.GetData(DataFormats.UnicodeText, true) as string;
            string pattern            = GetKeyRestrictionPattern(textBox);
            bool   noInvalidCharacter = System.Text.RegularExpressions.Regex.IsMatch(text, pattern) == false;

            if (noInvalidCharacter)
            {
                return;
            }

            textBox.Text = System.Text.RegularExpressions.Regex.Replace(text, pattern, "");
        }
コード例 #13
0
ファイル: ZoomComboBox.cs プロジェクト: zheng1748/wpf
        /// <summary>
        /// This will validate incoming strings pasted into the textbox, only pasting
        /// valid (all digit) strings.
        /// </summary>
        /// <param name="sender">A reference to the sender of the event.</param>
        /// <param name="e">Arguments to the event, used to determine the input.</param>
        private void OnPaste(object sender, DataObjectPastingEventArgs e)
        {
            // Validate the parameters, return if data is null.
            if ((e == null) || (e.DataObject == null) || (String.IsNullOrEmpty(e.FormatToApply)))
            {
                return;
            }

            // Acquire a reference to the new string.
            string incomingString = e.DataObject.GetData(e.FormatToApply) as string;

            if (IsValidInputString(incomingString))
            {
                // Since the new content is valid set the ZoomComboBox as in edit mode
                // and allow the text to be processed normally (ie don't CancelCommand).
                _isEditingText = true;
            }
            else
            {
                // Cancel the paste if the string is null, empty, or otherwise invalid.
                e.Handled = true;
                e.CancelCommand();
            }
        }
コード例 #14
0
 private void DisablePasting(object sender, DataObjectPastingEventArgs e)
 {
     e.CancelCommand();
 }
コード例 #15
0
 private void PolynomialDataGrid_Pasting(object sender, DataObjectPastingEventArgs e)
 {
     e.CancelCommand();
 }
コード例 #16
0
        private static void TextBox_PasteEventHandler(object sender, DataObjectPastingEventArgs e)
        {
            var textBox = (TextBox)sender;

            if (e.DataObject.GetDataPresent(typeof(string)))
            {
                var clipboardText = (string)e.DataObject.GetData(typeof(string));

                var newText = textBox.Text.Insert(textBox.SelectionStart, clipboardText);

                var evenOddConstraint = GetEvenOddConstraint(textBox);

                switch (GetOnlyNumeric(textBox))
                {
                case NumericFormat.Double:
                {
                    if (double.TryParse(newText, out double number))
                    {
                        switch (evenOddConstraint)
                        {
                        case EvenOddConstraint.OnlyEven:

                            if (number % 2 != 0)
                            {
                                e.CancelCommand();
                            }

                            break;

                        case EvenOddConstraint.OnlyOdd:

                            if (number % 2 == 0)
                            {
                                e.CancelCommand();
                            }

                            break;
                        }
                    }
                    else
                    {
                        e.CancelCommand();
                    }

                    break;
                }

                case NumericFormat.Int:
                {
                    if (int.TryParse(newText, out int number))
                    {
                        switch (evenOddConstraint)
                        {
                        case EvenOddConstraint.OnlyEven:

                            if (number % 2 != 0)
                            {
                                e.CancelCommand();
                            }

                            break;

                        case EvenOddConstraint.OnlyOdd:

                            if (number % 2 == 0)
                            {
                                e.CancelCommand();
                            }

                            break;
                        }
                    }
                    else
                    {
                        e.CancelCommand();
                    }

                    break;
                }

                case NumericFormat.Uint:
                {
                    if (uint.TryParse(newText, out uint number))
                    {
                        switch (evenOddConstraint)
                        {
                        case EvenOddConstraint.OnlyEven:

                            if (number % 2 != 0)
                            {
                                e.CancelCommand();
                            }

                            break;

                        case EvenOddConstraint.OnlyOdd:

                            if (number % 2 == 0)
                            {
                                e.CancelCommand();
                            }

                            break;
                        }
                    }
                    else
                    {
                        e.CancelCommand();
                    }

                    break;
                }

                case NumericFormat.Natural:
                {
                    if (uint.TryParse(newText, out uint number))
                    {
                        if (number == 0)
                        {
                            e.CancelCommand();
                        }
                        else
                        {
                            switch (evenOddConstraint)
                            {
                            case EvenOddConstraint.OnlyEven:

                                if (number % 2 != 0)
                                {
                                    e.CancelCommand();
                                }

                                break;

                            case EvenOddConstraint.OnlyOdd:

                                if (number % 2 == 0)
                                {
                                    e.CancelCommand();
                                }

                                break;
                            }
                        }
                    }
                    else
                    {
                        e.CancelCommand();
                    }

                    break;
                }
                }
            }
            else
            {
                e.CancelCommand();
            }
        }
コード例 #17
0
 private static void PastingHandler(object sender, DataObjectPastingEventArgs e)
 {
     e.CancelCommand();
 }
コード例 #18
0
 private void OnPaste(object sender, DataObjectPastingEventArgs e)
 {
     e.CancelCommand();
 }
コード例 #19
0
 void PasteHandler(object sender, DataObjectPastingEventArgs e)
 {
     //最大值与最小值粘贴限制
     if (Type == 1)
     {
         if (!e.DataObject.GetDataPresent(typeof(String)))
         {
             e.CancelCommand();
             return;
         }
         String text = (String)e.DataObject.GetData(typeof(String));
         int    temp = 0;
         if (MaxValue != 0)
         {
             text += this.Text;
             if (!int.TryParse(text, out temp) || temp > MaxValue)
             {
                 e.CancelCommand();
             }
         }
         else
         {
             if (!int.TryParse(text, out temp))
             {
                 e.CancelCommand();
             }
         }
         if (MinValue < 0)
         {
             text += this.Text;
             if (!int.TryParse(text, out temp) || Math.Abs(temp) > Math.Abs(MinValue))
             {
                 e.CancelCommand();
             }
         }
         else
         {
             if (!int.TryParse(text, out temp))
             {
                 e.CancelCommand();
             }
         }
     }
     else if (Type == 2)
     {
         if (!e.DataObject.GetDataPresent(typeof(String)))
         {
             e.CancelCommand();
             return;
         }
         String text = (String)e.DataObject.GetData(typeof(String));
         text += this.Text;
         double temp = 0;
         if (MaxValue != 0)
         {
             if (!double.TryParse(text, out temp) || temp > MaxValue)
             {
                 e.CancelCommand();
             }
         }
         else
         {
             if (!double.TryParse(text, out temp))
             {
                 e.CancelCommand();
             }
         }
         if (MinValue < 0)
         {
             text += this.Text;
             if (!double.TryParse(text, out temp) || Math.Abs(temp) > Math.Abs(MinValue))
             {
                 e.CancelCommand();
             }
         }
         else
         {
             if (!double.TryParse(text, out temp))
             {
                 e.CancelCommand();
             }
         }
     }
 }
コード例 #20
0
        private void TxtBox_Pasting(object sender, DataObjectPastingEventArgs e)
        {
            try
            {
                bool isPastedTextValid = false;

                if (e.DataObject.GetDataPresent(typeof(string)))
                {
                    var pasteText = e.DataObject.GetData(typeof(string)) as string;
                    if (pasteText.Contains(Comma))
                    {
                        pasteText = pasteText.Replace(Comma, Dot);
                    }

                    if (IsNumericWithDot(pasteText))
                    {
                        isPastedTextValid = true;

                        var inputText       = pasteText;
                        var inputLength     = pasteText.Length;
                        var selectionStart  = txtBox.SelectionStart;
                        var selectionLength = txtBox.SelectionLength;

                        if (!string.IsNullOrEmpty(txtBox.Text))
                        {
                            inputText = txtBox.Text.Remove(selectionStart, selectionLength);
                            inputText = inputText.Insert(selectionStart, pasteText);
                        }

                        if (inputText.Contains("%"))
                        {
                            inputText = inputText.Remove(inputText.IndexOf('%'), 1);
                        }

                        // this operation's needed for the proper
                        // TryParse functionality method
                        if (_currentCultureSeparator == ',')
                        {
                            inputText = inputText.Replace(Dot, Comma);
                        }

                        decimal result;
                        if (!decimal.TryParse(inputText, NumberStyles.Any, _currentCulture, out result))
                        {
                            isPastedTextValid = false;
                        }
                        else
                        {
                            // ToDecimal must always have
                            // separator point as a dot
                            if (inputText.Contains(Comma))
                            {
                                inputText = inputText.Replace(Comma, Dot);
                            }
                            var tmp = Convert.ToDecimal(inputText, CultureInfo.InvariantCulture);
                            if (!IsValidWithPrecision(inputText))
                            {
                                isPastedTextValid = false;
                            }
                            else
                            {
                                txtBox.Text       = tmp.ToString();
                                txtBox.CaretIndex = selectionStart + inputLength;
                                Value             = tmp;
                                isPastedTextValid = false;
                            }
                        }
                    }
                }

                txtBox.GetBindingExpression(TextBox.TextProperty).UpdateTarget();

                if (!isPastedTextValid)
                {
                    e.CancelCommand();
                }
            }
            catch (FormatException)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #21
0
 private void Input_PastingHandler(object sender, DataObjectPastingEventArgs e)
 {
     e.CancelCommand();
 }
コード例 #22
0
 private void Pasting(object sender, DataObjectPastingEventArgs e)
 {
     //einfügen nicht erlaubt
     System.Media.SystemSounds.Beep.Play();
     e.CancelCommand();
 }
コード例 #23
0
        private void pastingEvent(object sender, DataObjectPastingEventArgs e)
        {
            if (bgWorker != null && bgWorker.IsBusy == true)
            {
                e.CancelCommand();
                return;
            }

            if (Clipboard.ContainsImage() == true)
            {
                BitmapSource bitmapSource = null;
                try
                {
                    bitmapSource = Clipboard.GetImage();
                    if (bitmapSource != null)
                    {
                        byte[] byteArr_Image = null;

                        using (MemoryStream msOutput = new MemoryStream())
                        {
                            BitmapEncoder enc = new BmpBitmapEncoder();
                            enc.Frames.Add(BitmapFrame.Create(bitmapSource));
                            enc.Save(msOutput);
                            msOutput.Flush();
                            byteArr_Image = msOutput.ToArray();
                        }

                        if (bgWorker == null)
                        {
                            bgWorker                     = new BackgroundWorker();
                            bgWorker.DoWork             += BgWorker_DoWork;
                            bgWorker.RunWorkerCompleted += BgWorker_RunWorkerCompleted;
                        }

                        ucBusy.IsBusy      = true;
                        ucBusy.BusyContent = "分析中, 请稍候...";

                        this.MethodName   = "GeneralBasic";
                        this.CurrentImage = byteArr_Image;
                        bgWorker.RunWorkerAsync(byteArr_Image);
                    }
                    else
                    {
                        string          msg = "{0}".FormatWith("获取图片资源失败.");
                        Action <String> UI_ShowMessageBox_Action = new Action <string>(UI_ShowMessageBox);
                        this.Dispatcher.BeginInvoke(method: UI_ShowMessageBox_Action, args: new object[1] {
                            msg
                        });
                        e.CancelCommand();
                    }
                }
                catch (Exception ex)
                {
                    string          msg = "{0}{1}".FormatWith("获取图片资源失败.", ex.Message);
                    Action <String> UI_ShowMessageBox_Action = new Action <string>(UI_ShowMessageBox);
                    this.Dispatcher.BeginInvoke(method: UI_ShowMessageBox_Action, args: new object[1] {
                        msg
                    });
                    e.CancelCommand();
                }
            }
        }
コード例 #24
0
 private void letterToGuessTextBlock_OnPasting(object sender, DataObjectPastingEventArgs e)
 {
     e.CancelCommand();
 }
コード例 #25
0
 private void TxtDownloadPath_Pasting(object sender, DataObjectPastingEventArgs e)
 {
     e.CancelCommand();
 }
コード例 #26
0
 private void ThresholdTextBox_Pasting(object sender, DataObjectPastingEventArgs e)
 {
     e.CancelCommand();
 }
コード例 #27
0
ファイル: NumericBox.cs プロジェクト: AlbertMin/AlbertCAD
 private void Text_Pasting(object sender, DataObjectPastingEventArgs e)
 {
     //禁止Pasting
     e.CancelCommand();
 }
コード例 #28
0
ファイル: TEditComboBox.cs プロジェクト: xuhuo1234/FWindSoft
 public void m_DataObjectPastingEventHandler(object sender, DataObjectPastingEventArgs e)
 {
     e.CancelCommand();
 }
コード例 #29
0
 private void txt_Pasting(object sender, DataObjectPastingEventArgs e)
 {
     System.Diagnostics.Debug.WriteLine("txt_Pasting: " + txt.Text);
     e.CancelCommand();
 }
コード例 #30
0
 public override void AcceptPaste(DataObjectPastingEventArgs args)
 {
     args.CancelCommand();
 }