Disbaling RightMouse Button Click

  • Thread starter Thread starter Karuppasamy
  • Start date Start date
K

Karuppasamy

Hi

In Windows Application (C#), on RightMouse Button click in a Textbox, a
Popup menu with Cut / Copy / Paste is appearing. How to disable this
behaviour. I dont want to allow the user to copy and paste using the
rightmouse button.

How to do that?

waiting for your reply

Regards
Karuppasamy Natarajan
 
That context menu is built in to Windows
You'll need to override WndProc and suppress all WM_CONTEXTMENU messages

Here's VB-code that does this. Should be easy to translate to C#

Public Class TextBoxEx
Inherits TextBox
Private Const WM_CONTEXTMENU As Integer = &H7B
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_CONTEXTMENU AndAlso Me.ContextMenu Is Nothing Then
m.Result = IntPtr.Zero
Else
MyBase.WndProc(m)
End If
End Sub
End Class

/claes
 
First off - please do NOT crosspost to a whole slew of newsgroups!
Post it to one, maybe two RELEVANT newsgroups ONLY. Thanks.
In Windows Application (C#), on RightMouse Button click in a Textbox, a
Popup menu with Cut / Copy / Paste is appearing. How to disable this
behaviour. I dont want to allow the user to copy and paste using the
rightmouse button.

You could always override the MouseDown event for that TextBox, and
just "swallow" the mouse event (not do anything with it) - that should
disable the system-default behaviour.

Select your textbox on the design surface, and select the "Events"
page in your property inspector. Find the "MouseDown" event,
double-click to create a stub event handler, and then write something
like:

private void textBox1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
// do nothing
}
}

Marc

================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
even if you override mouse down and doing nothing in the
even handler, after processing your own event handler,
control will go to the windows' own event handler for the
right mouse button click... so doing nothing inside your
event handler won;t help....

Sunil
 
Back
Top