首页 > 解决方案 > 在 C# 中引发 .NET“OK”事件?

问题描述

在 Siemens TIA-Portal Openness API 的文档中,您可以阅读以下内容:

截图西门子 API

有一个事件,当确认框打开时,以及当用户给出确认时的事件。

//Register event handler for Notification-Event
....
tiaPortal.Notification += TiaPortal_Notification;
....
private static void TiaPortal_Notification(object sender, NotificationEventArgs e)
{
....
}
//Register event handler for Confirmation-Event
....
tiaPortal.Confirmation += TiaPortal_Confirmation;
....
private static void TiaPortal_Confirmation(object sender, ConfirmationEventArgs e)
{
....
}

该文档提供了有关对事件做出反应的大量信息

在此处输入图像描述

我想对通知事件做出反应。但是 NotificationEventArgs 类不包含我可以写入的结果属性,也不包含任何发送确认的方法。只有一个可写属性,称为 IsHandled。但是如果我写信什么都不会发生,所以我建议这只是一个内部确认

在此处输入图像描述

我对 api 文档的理解是,它是 c#/.net 的原生内容?也许是某种功能,以引起对事件的反应?

标签: c#.net

解决方案


我认为这只是德语的(不是最佳的)翻译。他们的意思是你需要在你得到的事件参数中设置一个字段。这是 .NET 中的正常模式。

像这样的东西(没有用于语法检查的库,但你应该明白我的意思):

private static void TiaPortal_Confirmation(object sender, ConfirmationEventArgs e)
{
    // do your thing, open a confirmation dialog or something, then:
    e.Result = Choices.OK;
}

推荐阅读