How to handle Form caption right click

后端 未结 6 897
感情败类
感情败类 2021-01-07 10:09

I\'d like a context menu on the caption bar right click

any tips/samples pref in c# ?

UPDATE - for various reasons, right click on the form won\'t work becau

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-07 11:06

    You can override WndProc of the form and capture the WM_NCRBUTTONDOWN message:

       protected override void WndProc(ref Message m)
       {
           const int WM_NCRBUTTONDOWN = 0xA4;
    
           if (m.Msg == WM_NCRBUTTONDOWN)
           {
               MessageBox.Show("Caption right clicked!");
           }
           else
           {
               base.WndProc(ref m);
           }
       }
    

    This code will suppress the window's context menu, however. You may not wish this. The WM_NCRBUTTONDOWN message will also be sent if you right click the window borders as well. You may not desire this either.

提交回复
热议问题