c# - C# 是否具有与 Delphi 的消息关键字等效的功能?

标签 c# delphi windows-messages

在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()

关于c# - C# 是否具有与 Delphi 的消息关键字等效的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5707832/

相关文章:

c# - 在 WPF 用户控件中附加 ICommand

c# - 在滚动查看器中保持位置

windows - 寻找查看 Windows 消息的程序

winforms - 捕获某个按钮点击的WndProc消息

c# - HttpClient JsonReaderException 解析值时出现意外字符

c# - 将数据从 SQLite 数据库输入 ListView

delphi - 使用 TChromium,Delphi Chromium 嵌入式

delphi - TForm 上的 RTTI GetFields 和 GetAttributes

delphi - 如何从 COM 服务器返回 WideString?

c# - 使用任务管理器终止程序时收到的消息