const string LineSelectedType = "MSDEVLineSelect"; // This is the type VS 2003 and 2005 use for flagging a whole line copy public static bool ConfirmDataFormat(TextArea textArea, DataObject dataObject, string format) { var e = new DataObjectSettingDataEventArgs(dataObject, format); textArea.RaiseEvent(e); return !e.CommandCancelled; }
private void listBox1_SettingData(object sender, DataObjectSettingDataEventArgs e) { }
public static void RmaInputCancelCommand(object sender, DataObjectSettingDataEventArgs e) { bool isAlphaNumeric = false; string AlphaNumberRegEx = "^[0-9]+$"; // Regular expression to check AlphaNumeric values string value = string.Empty; if (e.DataObject.GetDataPresent(typeof(string))) { // Get the copied value to the clipboard value = e.DataObject.GetData(typeof(string)).ToString(); // Verify with Alphanumeric Regular expression isAlphaNumeric = System.Text.RegularExpressions.Regex.IsMatch(value, AlphaNumberRegEx); } if (!isAlphaNumeric) { // Dont allow to paste e.CancelCommand(); } }
/// <summary> /// Called when [data setting]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.DataObjectSettingDataEventArgs"/> instance containing the event data.</param> private void OnDataSetting(object sender, DataObjectSettingDataEventArgs e) { RichTextBox richTextBox = sender as RichTextBox; if (richTextBox == null) { return; } StringToFlowDocumentConverter converter = new StringToFlowDocumentConverter(); TextSelection selection = richTextBox.Selection; string text = converter.ConvertFlowDocumentDataToStringWithinSelection(selection.Start, selection.End); e.DataObject.SetData(System.Windows.DataFormats.UnicodeText, text); }