分析c#中消息模拟工作流程

上传人:j****9 文档编号:45448242 上传时间:2018-06-16 格式:DOC 页数:5 大小:33KB
返回 下载 相关 举报
分析c#中消息模拟工作流程_第1页
第1页 / 共5页
分析c#中消息模拟工作流程_第2页
第2页 / 共5页
分析c#中消息模拟工作流程_第3页
第3页 / 共5页
分析c#中消息模拟工作流程_第4页
第4页 / 共5页
分析c#中消息模拟工作流程_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《分析c#中消息模拟工作流程》由会员分享,可在线阅读,更多相关《分析c#中消息模拟工作流程(5页珍藏版)》请在金锄头文库上搜索。

1、分析分析 C#中消息模拟工作流程中消息模拟工作流程C#中消息的工作流程:C#中的消息被 Application 类从应用程序消息队列中取出,然后分发到消息对应的窗体,窗体对象的第一个响应函数是对象中的 protected override void WndProc(ref System.Windows.Forms.Message e)方法。它再根据消息的类型调用默认的消息响应函数(如 OnMouseDown),默认的响应函数然后根据对象的事件字段(如 this.MouseDown )中的函数指针列表,调用用户所加入的响应函数(如 Form1_MouseDown1 和 Form1_MouseDo

2、wn2),而且调用顺序和用户添加顺序一致。根据这个流程,我做了个模仿程序,有不足的地方还请大家提供更完善的补充。using System;/创建一个委托,返回类型 void,两个参数public delegate void KeyDownEventHandler(object sender, KeyEventArgs e);/数据参数类class KeyEventArgs : EventArgsprivate char keyChar;public KeyEventArgs(char keyChar): base()this.keyChar = keyChar;public char KeyC

3、harget return keyChar; /模仿 Application 类class M_Applicationpublic static void Run(M_Form form)bool finished = false;doConsole.WriteLine(“Input a char“);string response = Console.ReadLine();char responseChar = (response = “) ? : char.ToUpper(response0);switch (responseChar)case X:finished = true;brea

4、k;default:/得到按键信息的参数KeyEventArgs keyEventArgs = new KeyEventArgs(responseChar);/向窗体发送一个消息form.WndProc(keyEventArgs);break; while (!finished);/模仿窗体类class M_Form/定义事件public event KeyDownEventHandler KeyDown;public M_Form()this.KeyDown += new KeyDownEventHandler(this.M_Form_KeyDown);/事件处理函数private void M_Form_KeyDown(object sender, KeyEventArgs e)Console.WriteLine(“Capture key:0“, e.KeyChar);/窗体处理函数public void WndProc(KeyEventArgs e)KeyDown(this, e);/主程序运行class MainEntryPointstatic void Main()M_Application.Run(new M_Form();

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 初中教育

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号