c# - 在 C# 中引发 .NET“OK”事件?
问题描述
在 Siemens TIA-Portal Openness 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 的原生内容?也许是某种功能,以引起对事件的反应?
解决方案
我认为这只是德语的(不是最佳的)翻译。他们的意思是你需要在你得到的事件参数中设置一个字段。这是 .NET 中的正常模式。
像这样的东西(没有用于语法检查的库,但你应该明白我的意思):
private static void TiaPortal_Confirmation(object sender, ConfirmationEventArgs e)
{
// do your thing, open a confirmation dialog or something, then:
e.Result = Choices.OK;
}
推荐阅读
- postgresql - Postgres/Flyway:如何在 sql 文件中包装长常量字符串?
- string - 用不同大小的字符串替换字符串 python 的切片,但保持结构
- python - 如何使用线程名称从 /proc 中识别线程?
- javascript - 事件侦听器未从 HTML 导入中的 JS 脚本触发
- javascript - 为什么我的算法在我的数组中找不到索引?
- python - 将`print`的输出直接复制到剪贴板
- python - 如何键入提示在函数的本地范围中定义的返回值?
- java - Spring Cloud @SqsListener MessageConversionException:无法从 [java.lang.String] 转换为 GenericMessage
- python - 从不同的文件调用具有相同名称的函数
- floating-point - 通过 HTTP 发送原始浮点值会发生什么情况?