using System; using System.Collections.Generic; using System.ComponentModel; using System.Windows.Forms; using System.Drawing; using System.Data; using System.Text; using System.Runtime.InteropServices; namespace TestWndProc { public partial class MyTextBox : TextBox { public event EventHandler SelectionChange; public MyTextBox() { InitializeComponent(); } public MyTextBox(IContainer container) { container.Add(this); InitializeComponent(); } private void OnSelectionChange() { if (SelectionChange != null) SelectionChange(this, new EventArgs()); } const int WM_IME_NOTIFY = 0x282; const int IMN_SETCOMPOSITIONWINDOW = 11; /// /// Allow SelectionChange /// /// protected override void WndProc(ref Message m) { // Watch for SelectionChange Message if (m.Msg == WM_IME_NOTIFY && m.WParam.ToInt32() == IMN_SETCOMPOSITIONWINDOW) OnSelectionChange(); base.WndProc(ref m); } } }