How to disable the pop-up control/system menu?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In the Form there is the Control/System menu.
I wish to prevent this system menu from poping-up although the minimize,
maximize and close buttons is still shown on the Form caption bar.

How can I do that?
 
Hi Sharon,
In the Form there is the Control/System menu.
I wish to prevent this system menu from poping-up although the minimize,
maximize and close buttons is still shown on the Form caption bar.

The obvious solution for this problem would be to set the ControlBox
property of the form to false. However, the problem with this method is that
the minimize and maximize buttons get lost also. Secondly, you could try
changing the FormBorderStyle property, in case this would be appropriate in
your case.

Since these simple solutions probably aren't what you are looking for, I
believe you need to do quite a lot of coding yourself. Unless you want to
get into the business of drawing the whole window title bar yourself (the
"non-client area") which gives you the ultimate control, I'm quite certain
your only possibilities are to fiddle with Windows messages, such as
WM_NCHITTEST and WM_SYSCOMMAND, among others (for example to disable
keyboard functionality).

However, before you proceed with this quest, I would really suggest thinking
twice whether you really want to do it. Frankly said, I'd hate to use an
application with the Control menu disabled, because that would also disable
Alt+Space, the often-used shortcut to manipulate the window. Not all people
use just the mouse.

Sorry that I don't have a definite answer nor any code available this time,
but I hope this gives you a pointer where to start.

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
(e-mail address removed)
http://www.saunalahti.fi/janij/
 
Hi Sharon,

Thanks for your post.

Yes, I also agree with Mr. Jani Järvinen that we'd better do not disable
this system context menu, which is a big convinient for user. Also, this
will cause inconsistent UI experience for end user.

Anyway, if you really want get this done. If you use Spy++ to monitor the
windows messages, we will see that we can disable WM_SYSCOMMAND with
SC_MOUSEMENU to get what you want. Like this:
int WM_SYSCOMMAND=0x112;
protected override void WndProc(ref Message m)
{
if(m.Msg==WM_SYSCOMMAND)
{
if((int)m.WParam==0xF093)
{
m.Result=IntPtr.Zero;
return;
}
}
base.WndProc (ref m);
}
Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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

Back
Top