C#屏蔽ComboBox系统右键菜单介绍(通过API拦截消息)
来源:互联网 发布:量子技术 知乎 编辑:程序博客网 时间:2024/06/05 19:56
C#屏蔽ComboBox系统右键菜单代码如下:
using System.Runtime.InteropServices; [DllImport("user32.dll")]public static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd);public const uint GW_CHILD= 5; private delegate IntPtr WndProcCallBack(IntPtr hwnd, int Msg, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll")]private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);[DllImport("user32.dll")]private static extern int GetWindowLong(IntPtr hWnd, int nIndex);[DllImport("User32.dll")]private static extern IntPtr CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);private int GWL_WNDPROC= -4;private static IntPtr prevWndFunc;private IntPtr newWndProc(IntPtr hWnd, int iMsg, IntPtr wParam, IntPtr lParam){ const int WM_CONTEXTMENU = 0x007B; switch (iMsg) { case WM_CONTEXTMENU: return IntPtr.Zero; } return CallWindowProc(prevWndFunc, hWnd, iMsg, wParam, lParam);}private IntPtr comboBoxEdit;private WndProcCallBack wndProcCallBack;private void Form1_Load(object sender, EventArgs e){ comboBoxEdit = GetWindow(comboBox1.Handle, GW_CHILD); prevWndFunc = new IntPtr(GetWindowLong(comboBoxEdit, GWL_WNDPROC)); wndProcCallBack = new WndProcCallBack(newWndProc); SetWindowLong(comboBoxEdit, GWL_WNDPROC, (int)Marshal.GetFunctionPointerForDelegate(wndProcCallBack));}
C#创建右键菜单范例说明:本范例讲解如何创建右键菜单,重点请注意菜单控件ContextMenuStrip的使用.
关键步骤:
1.创建一个新的Windows工程。
2.把ContextMenuStrip控件拖放到设计界面上,Name属性设置为cmMenu.
3.单击ContextMenuStrip控件的Type Here文本区域,可以输入菜单项的名称,如&new,然后回车.
4.添加RichTextBox控件,设置Name属性为"rchShow".
设置Form和RichTextBox的ContextMenuStript属性为“cmMenu”。
7.双击ContextMenuStrip控件的菜单项,添加Open事件。
/// <summary>
/// 右键菜单Open的处理事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void miOpen_Click(object sender, EventArgs e)
{
OpenFileDialog dlgOpen = new OpenFileDialog();dlgOpen.Filter = "文本文件(*.txt)|*.txt";
if (dlgOpen.ShowDialog() == DialogResult.OK)
{
this.rchShow.LoadFile(dlgOpen.FileName,RichTextBoxStreamType.PlainText);
}
}
private void Form1_Load(object sender, EventArgs e)
{
ContextMenuStrip cms = new ContextMenuStrip();
cms.Items.Add("第一个");
cms.Items.Add("第二个");
this.ContextMenuStrip = cms;
}
- C#屏蔽ComboBox系统右键菜单介绍(通过API拦截消息)
- 屏蔽ComboBox系统右键菜单
- 通过API函数屏蔽Flash的右键菜单(或者自定义Flash右键菜单)
- 完全屏蔽右键(包括系统菜单)
- 完全屏蔽右键(包括系统菜单)
- C#拦截系统消息
- 屏蔽右键菜单
- JS屏蔽右键菜单
- JS 屏蔽右键菜单
- JS 屏蔽右键菜单
- 屏蔽鼠标右键菜单
- 屏蔽FLEX右键菜单
- JS 屏蔽右键菜单 .
- 屏蔽右键菜单
- 屏蔽右键菜单
- js屏蔽右键菜单
- 网页屏蔽右键菜单
- 屏蔽右键菜单
- Java:谈谈protected访问权限
- sum MQ启动服务性指令
- 類似 搜索提示功能
- supermap objects 地图上添加 点线面图层 和删除图层 的类
- 宝马X3 xDrive28i性能测试
- C#屏蔽ComboBox系统右键菜单介绍(通过API拦截消息)
- Swing LookandFeel制作的总结
- 物流解决方案收集
- 关于Spring中dataSource的配置
- 正则表达式入门非常不错的讲解
- R12 Mapping Between Subledger Tables, SLA and GL Tables
- http://gekben.gitcd.com/blog/2012/07/11/collection-of-network-performance-tuning-tools/
- 地理(投影)坐标与屏幕坐标的转换!
- ILayerEffects接口用来设置一个要素图层的透明度,对比度,对比度