While I usually do not suggest abandoning the low-level Windows API, and this may not be the only way to do this, it does the trick:
using System; using System.Windows.Forms; public class ClipboardEventArgs : EventArgs { public string ClipboardText { get; set; } public ClipboardEventArgs(string clipboardText) { ClipboardText = clipboardText; } } class MyTextBox : TextBox { public event EventHandler<ClipboardEventArgs> Pasted; private const int WM_PASTE = 0x0302; protected override void WndProc(ref Message m) { if (m.Msg == WM_PASTE) { var evt = Pasted; if (evt != null) { evt(this, new ClipboardEventArgs(Clipboard.GetText()));
Ultimately, WinForms toolkit is not very good. This is a thin shell around Win32 and Common Controls. It provides 80% of the API, which is most useful. The remaining 20% ββis often absent or not exposed in an obvious way. I would suggest dropping WinForms and WPF if possible, since WPF seems to be the best architecture for the .NET GUI.
orj
source share