void HandlePasting(object sender, sw.DataObjectPastingEventArgs e) { if (e.FormatToApply == sw.DataFormats.Bitmap && !AllowImages) { // don't allow images by default e.CancelCommand(); } }
private static void tb_Pasting(object sender, DataObjectPastingEventArgs e) { var pastedText = e.DataObject.GetData(typeof(string)) as string; if (!IsTextAllowed(pastedText)) { e.CancelCommand(); } }
private void UcQuery_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; ucQuery.Tag = !string.IsNullOrWhiteSpace(text); }
private void OnPasted(object sender, DataObjectPastingEventArgs e) { myWordsAdded = true; mySelectionStartPosition = Selection.Start; mySelectionEndPosition = Selection.IsEmpty ? Selection.End.GetPositionAtOffset(0, LogicalDirection.Forward) : Selection.End; // Hyperlink detection will be done in OnTextChanged() }
private static void IntegerTextBox_PastingHandler(object sender, DataObjectPastingEventArgs e) { var Sender = sender as IntegerTextBox; if (Sender == null) return; Sender.OnPaste(e); }
private void OnPaste(object sender, DataObjectPastingEventArgs e) { var pastedText = (string) e.SourceDataObject.GetData(DataFormats.UnicodeText); if (ProductIdIsNotValid(pastedText)) { e.CancelCommand(); } }
public static void IntegerPastingHandler(ref object sender, ref DataObjectPastingEventArgs e) { if (e.DataObject.GetDataPresent(typeof(String))) { String text = (String)e.DataObject.GetData(typeof(String)); if (!HandlingUserInput.IsIntegerText(text)) e.CancelCommand(); } else e.CancelCommand(); }
private void Key_Pasting(object sender, DataObjectPastingEventArgs e) { Regex r = new Regex("[^a-zA-Z]"); if (r.IsMatch(e.DataObject.GetData(typeof(string)).ToString())) { MessageBox.Show(this, "Keys can only contain alphabetic letters!"); e.CancelCommand(); } }
private void RichTextBox_Pasting(object sender, DataObjectPastingEventArgs e) { RichTextBox richTextBox = sender as RichTextBox; string textData = (e.DataObject.GetData(DataFormats.UnicodeText) as string).Replace("\n", " ").Replace("\r", ""); new TextRange(richTextBox.Selection.Start, richTextBox.Selection.End).Text = string.Empty; richTextBox.CaretPosition = richTextBox.CaretPosition.GetPositionAtOffset(0, LogicalDirection.Forward) ?? richTextBox.CaretPosition; richTextBox.CaretPosition.InsertTextInRun(textData); e.CancelCommand(); }
private void OnPaste(object sender, DataObjectPastingEventArgs e) { var isText = e.SourceDataObject.GetDataPresent(System.Windows.DataFormats.Text, true); if (!isText) return; var text = e.SourceDataObject.GetData(DataFormats.Text) as string; }
private static void PastingHandler(object sender, DataObjectPastingEventArgs e) { if (e.DataObject.GetDataPresent(typeof(String))) { var text = (String)e.DataObject.GetData(typeof(String)); if (!IsTextAllowed(text)) e.CancelCommand(); } else e.CancelCommand(); }
private void noPaste(object sender, DataObjectPastingEventArgs e) { if (e.DataObject.GetDataPresent(typeof(String))) { String text = (String)e.DataObject.GetData(typeof(String)); if (textAllowed(text)) e.CancelCommand(); } else e.CancelCommand(); }
private void OnPaste(object sender, DataObjectPastingEventArgs e) { if (!(sender is RichTextBox)) return; string textData = e.DataObject.GetData(DataFormats.Text) as string; (sender as RichTextBox).Document.ContentEnd.InsertTextInRun(textData); (sender as RichTextBox).CaretPosition = (sender as RichTextBox).Document.ContentEnd; e.CancelCommand(); }
/// <summary> /// This method handles paste and drag/drop events onto the TextBox. It restricts the character /// set to numerics and ensures we have consistent behavior. /// </summary> /// <param name="sender">TextBox sender</param> /// <param name="e">EventArgs</param> private static void OnClipboardPaste(object sender, DataObjectPastingEventArgs e) { string text = e.SourceDataObject.GetData(e.FormatToApply) as string; if (!string.IsNullOrEmpty(text)) { if (text.Count(ch => !Char.IsNumber(ch)) == 0) return; } e.CancelCommand(); }
private void textBoxNumeric_Pasting(object sender, DataObjectPastingEventArgs e) { string input = string.Empty; if (e.DataObject.GetDataPresent(typeof(string))) { if (!this.isNumericInput((string)e.DataObject.GetData(typeof(string)))) e.CancelCommand(); } else e.CancelCommand(); }
private void IPTextBox_Paste(object sender, DataObjectPastingEventArgs e) { if (e.DataObject.GetDataPresent(typeof(string))) { string value = e.DataObject.GetData(typeof(string)).ToString(); setIP(value); } e.CancelCommand(); }
protected virtual void OnPaste(DataObjectPastingEventArgs e) { var IsTextPresent = e.SourceDataObject.GetDataPresent(System.Windows.DataFormats.Text, true); if (IsTextPresent) { var TextValue = e.SourceDataObject.GetData(DataFormats.Text) as string; if (CheckTextFormat(TextValue)) return; } e.CancelCommand(); }
private static void TextBoxPastingEventHandler(object sender, DataObjectPastingEventArgs e) { var textBox = (sender as TextBox); var clipboard = e.DataObject.GetData(typeof(string)) as string; // TODO : clipboard = ValidateValue(clipboard); if (textBox != null && !string.IsNullOrEmpty(clipboard)) { textBox.Text = clipboard; } e.CancelCommand(); e.Handled = true; }
private void CheckPasteFormat(object sender, DataObjectPastingEventArgs e) { var isText = e.SourceDataObject.GetDataPresent(System.Windows.DataFormats.Text, true); if (isText) { var text = e.SourceDataObject.GetData(DataFormats.Text) as string; if (CheckFormat(text)) { return; } } e.CancelCommand(); }
private void TextBoxPaste_CheckNumbers(object sender, DataObjectPastingEventArgs e) { if (e.DataObject.GetDataPresent(typeof(String))) { String text = (String)e.DataObject.GetData(typeof(String)); if (!StringHelpers.IsTextAllowed(text)) { e.CancelCommand(); } } else { e.CancelCommand(); } }
private void OnDataObjectPasting(object sender, DataObjectPastingEventArgs e) { if (this.ConstraintPredicate != null) { if (e.DataObject.GetDataPresent(typeof(string))) { string input = e.DataObject.GetData(typeof(string)) as string; if (this.ConstraintPredicate(input)) { return; } } e.CancelCommand(); } }
private void TextBoxPasting(object sender, DataObjectPastingEventArgs e) { if (e.DataObject.GetDataPresent(typeof(String))) { var text = (String)e.DataObject.GetData(typeof(String)); if (!IsTextAllowed(text)) { e.CancelCommand(); } } else { e.CancelCommand(); } }
// Use the DataObject.Pasting Handler private void TextBoxPasting(object sender, DataObjectPastingEventArgs e) { int value; if (e.DataObject.GetDataPresent(typeof(string))) { string text = (string)e.DataObject.GetData(typeof(string)); if (int.TryParse(text, out value)) { e.CancelCommand(); } } else { e.CancelCommand(); } }
/// <summary> /// Method checks if pasted string contains input that is invalid and cancels /// past command if string is not conforming to regular expression. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void OnPaste(object sender, DataObjectPastingEventArgs e) { if (e.DataObject.GetDataPresent(DataFormats.Text)) { var RegularExpression = AllowableCharactersTextBoxBehavior.GetRegularExpressionProperty(sender as TextBox); string text = System.Convert.ToString(e.DataObject.GetData(DataFormats.Text)); if (!IsValid(text, true, RegularExpression)) { e.CancelCommand(); } } else { e.CancelCommand(); } }
private void RichTextBox_Pasting(object sender, DataObjectPastingEventArgs e) { //不是字符串的粘贴都取消 if (e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText)) { //重新获取字符串并设置DataObject var text = e.SourceDataObject.GetData(DataFormats.UnicodeText); var dataObj = new DataObject(); dataObj.SetData(DataFormats.UnicodeText, text); e.DataObject = dataObj; } else e.CancelCommand(); //if (e.FormatToApply != "Bitmap") //{ //e.CancelCommand(); //} }
private void OnHexPaste(object sender, DataObjectPastingEventArgs e) { e.CancelCommand(); var isText = e.SourceDataObject.GetDataPresent(System.Windows.DataFormats.Text, true); if (!isText) return; var text = e.SourceDataObject.GetData(DataFormats.Text) as string; string ret = ""; string oldT = ""; foreach (char c in text.Replace("\r","").Replace("\n","")) { if (c != ' ') { oldT += c; if (oldT.Length == 2) { ret += oldT + " "; oldT = ""; } } else { if (oldT != "") { ret += oldT.PadLeft(2, '0') + " "; oldT = ""; } } } if (oldT != "") { ret += oldT.PadLeft(2, '0') + " "; oldT = ""; } txtTelegrammHex.Text = ret; e.Handled = true; }
private void NumberBox_Pasting(object sender, DataObjectPastingEventArgs e) { if (e.DataObject.GetDataPresent(typeof(string))) { string paste = (string)e.DataObject.GetData(typeof(string)); Trace.WriteLine("Parsing paste: '" + paste + "'"); Trace.WriteLineIf(Regex.IsMatch(paste, "^[0-9]+$"), "Paste is matching :)"); Trace.WriteLineIf(!Regex.IsMatch(paste, "^[0-9]+$"), "Paste is not matching :("); if (!Regex.IsMatch(paste, "^[0-9]+$")) e.CancelCommand(); } else { Trace.WriteLine("Paste was not text :("); e.CancelCommand(); } }
private void OnPaste(object sender, DataObjectPastingEventArgs e) { if (!ApplicationSettings.AllowMarkupPastedLinks) return; if (!e.SourceDataObject.GetDataPresent(DataFormats.Text, true)) return; var pasteText = e.SourceDataObject.GetData(DataFormats.Text) as string; if (string.IsNullOrWhiteSpace(pasteText)) return; // only auto-markup links if (!(pasteText.StartsWith("http://") || pasteText.StartsWith("https://")) || pasteText.Contains(" ")) return; e.CancelCommand(); if (string.IsNullOrWhiteSpace(Entry.SelectedText)) { var formattedPaste = $"[url={pasteText}][/url]"; var caretPasteIndex = Entry.CaretIndex; Entry.Text = Entry.Text.Insert(Entry.CaretIndex, formattedPaste); Entry.CaretIndex = caretPasteIndex + formattedPaste.IndexOf("[/url]", StringComparison.Ordinal); } else { var oldText = Entry.SelectedText; var newPasteText = $"[url={pasteText}]{oldText}[/url]"; Entry.SelectedText = newPasteText; // why invoke? Entry.Text doesn't update immediately, it's updated on a scheduler or something // this just schedules it after that Dispatcher.BeginInvoke((Action) (() => { var startIndex = Entry.Text.IndexOf($"{oldText}[/url]", StringComparison.Ordinal); if (startIndex == -1) return; // don't want to crash if something weird happens Entry.Select(startIndex, oldText.Length); })); } }
public void AutoCompleteComboBox_TextPasted(object sender, DataObjectPastingEventArgs e) { if (e.SourceDataObject.GetDataPresent(DataFormats.Text, true) == false) { return; } string args = e.DataObject.GetData(typeof(string)) as string; args = Regex.Replace(args, @"\t|\n|\r", ""); if (_maxLength != -1) { if (args.Length == _maxLength) { this.IsTextSearchEnabled = true; } else { this.IsTextSearchEnabled = false; } } if (_acm.AutoCompleting) { return; } }
private void OnInputTextBoxPasting(object sender, DataObjectPastingEventArgs e) { if (e.DataObject.GetDataPresent(typeof(string))) { string text = (string)e.DataObject.GetData(typeof(string)); if (!TextBoxTextAllowed(text)) { e.CancelCommand(); } } else { e.CancelCommand(); } }
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)); double number; if (!ValidateText(newText, out number)) { e.CancelCommand(); } }
private void Text_Pasting(object sender, System.Windows.DataObjectPastingEventArgs e) { //禁止Pasting e.CancelCommand(); }