PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Forms disable context menu for text boxes

Reply

disable context menu for text boxes

 
Thread Tools Rate Thread
Old 10-12-2003, 03:30 PM   #1
Henrik
Guest
 
Posts: n/a
Default disable context menu for text boxes


Hi,

If one right-clicks in a text box, a context menu is
displayed with the usual options (cut, copy, paste et.c.).
Is there any way to disable this?
I have my own textbox like this:

public class MyTextBox : System.Windows.Forms.TextBox
{
public MyTextBox()
{
this.ContextMenu = null;
}

....
}

However, this doesn't work. It works fine for forms though
(setting it to null removes the menu).

Is there any other way to do it?


Thanks,

Henrik

  Reply With Quote
Old 10-12-2003, 05:47 PM   #2
Eric Cadwell
Guest
 
Posts: n/a
Default Re: disable context menu for text boxes

Set it to an empty context menu:

ContextMenu contextMenu1 = new ContextMenu();
textBox1.ContextMenu = contextMenu1;

HTH;
Eric Cadwell
http://www.origincontrols.com


  Reply With Quote
Old 10-12-2003, 06:27 PM   #3
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
Default Re: disable context menu for text boxes

* "Henrik" <anonymous@discussions.microsoft.com> scripsit:
> If one right-clicks in a text box, a context menu is
> displayed with the usual options (cut, copy, paste et.c.).
> Is there any way to disable this?
> I have my own textbox like this:
>
> public class MyTextBox : System.Windows.Forms.TextBox
> {
> public MyTextBox()
> {
> this.ContextMenu = null;
> }
>
> ....
> }
>
> However, this doesn't work. It works fine for forms though
> (setting it to null removes the menu).


Override the control's 'WndProc' and listen for 'WM_CONTEXTMENU'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off