如何调用 Microstation 的消息管理器
在进行Bentley二次开发的时候,通常我们需要向用户输出一些信息,比如操作的提示,错误的提示等等,本文特对这些方式进行总结,方便下次随心所欲地使用。
通知管理器
通过使用 NotificationManager 向用户推送消息。可以用此类来生成提示、错误消息和警报对话框。
 
| DLL 名称 | 命名空间 | 类名 | 
|---|---|---|
| Bentley.DgnPlatformNET.dll | Bentley.DgnPlatformNET | NotificationManager | 
源码注解
| 1 | 
 | 
使用
- OpenMessageBox方法 - 1 
 2
 3
 4- private void NotificationManagerOpenMessageBox() 
 {
 NotificationManager.OpenMessageBox(NotificationManager.MessageBoxType.MediumAlert, "Medium alert",NotificationManager.MessageBoxIconType.Warning);
 }
- OutputMessage方法 - 1 
 2
 3
 4
 5
 6
 7
 8
 9- private void NotificationManagerOutputMessage() 
 {
 OutputMessagePriority outputMessagePriority = OutputMessagePriority.Information;
 string briefMsg = "this is a brief msg";
 string detailMsg = "this is a detail msg";
 NotifyTextAttributes notifyTextAttributes = NotifyTextAttributes.AlwaysBeveled;
 NotifyMessageDetails notifyMessageDetails = new NotifyMessageDetails(outputMessagePriority,briefMsg,detailMsg,notifyTextAttributes,OutputMessageAlert.Balloon);
 NotificationManager.OutputMessage(notifyMessageDetails);
 }![image-20220512074152131]()  
- OutputPrompt方法 - 1 
 2
 3
 4- private void NotificationManagerOutputPrompt() 
 {
 NotificationManager.OutputPrompt("this is ouput prompt");
 }![image-20220512073913334]()  
消息中心(MessageCenter)
在 Bentley.MstnPlatformNET 中也存在与消息管理器一样的类以供调用向用户传递消息。
| DLL 名称 | 命名空间 | 类名 | 
|---|---|---|
| ustation.dll | Bentley.MstnPlatformNET | MessageCenter | 
| 1 | // 其内部代码如下 | 
在使用时,通过单例来调用其中的实例方法:MessageCenter.Instance.xxx
测试代码
最后,附上 Notification Manager 测试代码的链接。
加载编译之后的 ArticleSourceCode.dll,调用
Key-in:test message manager,此时会弹出一个操作窗体,通过选择不同选项,即可查看相应方法的效果。
 
 
