如何处理窗体标题右击 [英] How to handle Form caption right click
本文介绍了如何处理窗体标题右击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想标题栏的上下文菜单右键点击
I'd like a context menu on the caption bar right click
任何提示/样品PREF在C#?
any tips/samples pref in c# ?
更新 - 由于种种原因,右键单击窗体上不会起作用,因为形式是不是空的形式动态合成左右....
UPDATE - for various reasons, right click on the form won't work because the form is not empty and the form is composited dynamically so....
推荐答案
您可以通过捕获该Windows发送当用户右键单击标题栏中的WM_NCRBUTTONDOWN通知做到这一点。控制类没有一个事件,你需要重写的WndProc()。这里有一个例子形式,你需要添加的ContextMenuStrip:
You can do this by trapping the WM_NCRBUTTONDOWN notification that Windows sends when the user right-clicks the title bar. The control class does not have an event for it, you'll need to override WndProc(). Here's an example form, you'll need to add a ContextMenuStrip:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
protected void OnTitlebarClick(Point pos) {
contextMenuStrip1.Show(pos);
}
protected override void WndProc(ref Message m) {
if (m.Msg == 0xa4) { // Trap WM_NCRBUTTONDOWN
Point pos = new Point(m.LParam.ToInt32() & 0xffff, m.LParam.ToInt32() >> 16);
OnTitlebarClick(pos);
return;
}
base.WndProc(ref m);
}
}
这篇关于如何处理窗体标题右击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文