| 
                ■No96736 (かつお さん) に返信 > keypressのイベントハンドラで[Ctrl]+V押された際、
  音声文字入力 / 手書き文字認識入力からのテキスト入力 キーボードの [Shift]+[Insert] での直接貼り付け キーボードの [Shift]+[F10] での貼り付けメニュー キーボードの [Application] からの貼り付けメニュー スタイラスのジェスチャーによる直接貼り付け タッチパッドの指2本タップからの貼り付けメニュー タッチパネルの長押しからの貼り付けメニュー
 
  > 「NativeWindow クラスの AssignHandle / WndProc」については、勉強不足すぎて、どういう風にコード書くべきかイメージできず模索中でございます。 こんな感じ。
  using System; using System.Data; using System.Linq; using System.Text.RegularExpressions; using System.Windows.Forms;
  namespace WindowsFormsApp1 {  public partial class Form1 : Form  {   private DataGridView dgv;   private EditorHook hook = null;   public Form1()   {    InitializeComponent();    Controls.Add(dgv = new DataGridView { Name = "dgv" });    dgv.Dock = DockStyle.Fill;    dgv.RowCount = 100;    dgv.ColumnCount = 8;    dgv.EditMode = DataGridViewEditMode.EditOnEnter;    dgv.EditingControlShowing += Dgv_EditingControlShowing;   }
    private void Dgv_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)   {    if (hook != null)    {     hook.ReleaseHandle();     hook = null;    }    var txt = e.Control as TextBoxBase;    if (txt != null)    {     hook = new EditorHook(txt);    }   }
    private class EditorHook : NativeWindow   {    private const int WM_PASTE = 0x302;    private TextBoxBase txt;    public EditorHook(TextBoxBase control)    {     AssignHandle((txt = control).Handle);    }    protected override void WndProc(ref Message m)    {     Console.WriteLine(m.ToString());     if (m.Msg == WM_PASTE)     {      txt.SelectedText = GetNarrowNumbers();      m.Result = new IntPtr(1);     }     else     {      base.WndProc(ref m);     }    }
     private string GetNarrowNumbers()    {     var rawText = Clipboard.GetText();     var replaced = Regex.Replace(rawText, "[0-9]", p => ((char)(p.Value[0] - '0' + '0')).ToString());     var filtered = replaced.Where("0123456789".Contains);     return new string(filtered.ToArray());    }   }  } }
  |