Whether you wanted to forbid users to paste like crazy within textboxes or you wanted to create your own, the default textbox context menu should be deactivated. It’s a good example of overriding the default WndProc method (which corresponds to the WindowProc windows function) and filtering the incoming messages. For our example we will listen and wait for the WM_CONTEXTMENU, then we will simply cancel it, here is VB.NET sample, the code below should be used typically in a custom control (text box) definition class:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) If m.Msg = &H7B Then 'WM_CONTEXTMENU Return 'Do nothing Else Call MyBase.WndProc(m) 'Process the message normally End If End Sub
Here is another example written in C# and taken from the MSDN community, it uses the WM_NCHITTEST to allow moving a form directly from the client area, making windows “think” that the click occurred on the title bar:
private const int WM_NCHITTEST = 0x84; private const int HTCAPTION = 2; private const int HTCLIENT = 1; protected override void WndProc(ref Message m){ base.WndProc(ref m); if (m.Msg == WM_NCHITTEST && m.Result == new IntPtr(HTCLIENT)) { m.Result = new IntPtr(HTCAPTION); } }
See also - Voir aussi :

