加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C#是否具有相当于Delphi的消息关键字?

发布时间:2020-12-15 17:44:00 所属栏目:百科 来源:网络整理
导读:在delphi中,我可以创建我自己的消息, const MY_MESSAGE = WM_USER+100;procedure MyMessage(var Msg: TMessage); message MY_MESSAGE;procedure TForm1.MyMessage(var Msg: TMessage);begin....end; 在c#中我可以这样做 public static uint ms;protected ove
在delphi中,我可以创建我自己的消息,
const MY_MESSAGE = WM_USER+100;
procedure MyMessage(var Msg: TMessage); message MY_MESSAGE;

procedure TForm1.MyMessage(var Msg: TMessage);
begin
....
end;

在c#中我可以这样做

public static uint ms;
protected override void WndProc(ref Message m)
{       
 if(m.Msg == ms) 
    MessageBox.Show("example");
    else
    base.WndProc(ref m);        
}

void Button1Click(object sender,EventArgs e)
{
    PostMessage(HWND_BROADCAST,ms,IntPtr.Zero,IntPtr.Zero);
}

但我不想覆盖WndProc(),我想创建我自己的MyMessage()函数,当我发布消息它将运行.

我怎样才能做到这一点?
谢谢.

解决方法

这是Delphi的一个特殊功能,在C#中没有模拟.在C#中,需要覆盖WndProc().

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读