本文整理汇总了C#中System.Windows.DataObjectPastingEventArgs.CancelCommand方法的典型用法代码示例。如果您正苦于以下问题:C# DataObjectPastingEventArgs.CancelCommand方法的具体用法?C# DataObjectPastingEventArgs.CancelCommand怎么用?C# DataObjectPastingEventArgs.CancelCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DataObjectPastingEventArgs
的用法示例。
在下文中一共展示了DataObjectPastingEventArgs.CancelCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IntegerPastingHandler
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();
}
示例2: PastingHandler
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();
}
示例3: noPaste
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();
}
示例4: textBoxNumeric_Pasting
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();
}
示例5: TextBoxPasting
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();
}
}
示例6: TextBoxPaste_CheckNumbers
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();
}
}
示例7: TextBoxPasting
// 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();
}
}
示例8: tb_Pasting
private static void tb_Pasting(object sender, DataObjectPastingEventArgs e)
{
var pastedText = e.DataObject.GetData(typeof(string)) as string;
if (!IsTextAllowed(pastedText))
{
e.CancelCommand();
}
}
示例9: OnPaste
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();
}
示例10: OnPaste
/// <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();
}
}
示例11: Key_Pasting
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();
}
}
示例12: RichTextBox_Pasting
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();
}
示例13: OnPaste
private void OnPaste(object sender, DataObjectPastingEventArgs e)
{
var pastedText = (string) e.SourceDataObject.GetData(DataFormats.UnicodeText);
if (ProductIdIsNotValid(pastedText))
{
e.CancelCommand();
}
}
示例14: OnClipboardPaste
/// <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();
}
示例15: NumberBox_Pasting
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();
}
}