How to get rid of default context menu

G

Guest

I am developing a custom text box and with the kind help from here I added some additional features
But I cannot get rid of the right-click menu from .NET. I got rid of it by overriding WndProc and trapping WM_LBUTTONUP, but I was wondering if there was a way to do it in .NET only, without using Win32 SDK

Thank you
 
T

Tim Wilson

A relatively simple way is to just assign the TextBox a ContextMenu object
that does not have any items. For example:
textBox1.ContextMenu = new ContextMenu();

Another way, along the lines of what you were doing before, is to just "eat"
the WM_CONTEXTMENU message:

private const int WM_CONTEXTMENU = 0x007B;

protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_CONTEXTMENU:
{
return;
}
}
base.WndProc(ref m);
}

--
Tim Wilson
..Net Compact Framework MVP
{cf147fdf-893d-4a88-b258-22f68a3dbc6a}

john smith said:
I am developing a custom text box and with the kind help from here I added some additional features.
But I cannot get rid of the right-click menu from .NET. I got rid of it by
overriding WndProc and trapping WM_LBUTTONUP, but I was wondering if there
was a way to do it in .NET only, without using Win32 SDK.
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?am9obiBzbWl0aA==?= said:
I am developing a custom text box and with the kind help from here I added some additional features.
But I cannot get rid of the right-click menu from .NET. I got rid of
it by overriding WndProc and trapping WM_LBUTTONUP, but I was wondering
if there was a way to do it in .NET only, without using Win32 SDK.

I don't think so. You can assing a contextmenu to the control's
'ContextMenu' property, or you can "eat" 'WM_CONTEXTMENU'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top