❄ 正文
在进行Bentley二次开发的时候,通常我们需要向用户输出一些信息,比如操作的提示,错误的提示等等。可以采用以下方式:
❄ 1、通知管理器(Notification Manager)
NotificationManager控制与用户的交互。可以用此类来生成提示、错误消息和警报对话框。
dll名称:Bentley.DgnPlatformNET.dll
命名空间:Bentley.DgnPlatformNET
类名:NotificationManager
//打开消息弹窗
public static MessageBoxValue OpenMessageBox(MessageBoxType mbType, string message, MessageBoxIconType icon);
//向MS的底部通知栏写入提示
public static StatusInt OutputMessage(NotifyMessageDetails message);
public static void OutputPrompt(string prompt);
//设置一个标志来分配(value==true时)事件,以便在执行费时算法时,刷新界面,从而不卡顿。
public static void SetDispatchEvents(bool value);
public enum MessageBoxType
{
YesNo = -121,
LargeOk = -119,
YesNoCancel = -113,
MediumAlert = -112,
Ok = -97,
OkCancel = -13,
None = 0
}
public enum MessageBoxIconType
{
NoSymbol = 0,
Information = 1,
Question = 2,
Warning = 3,
Critical = 4
}
public enum MessageBoxValue
{
None = 0,
Apply = 1,
Reset = 2,
Ok = 3,
Cancel = 4,
Default = 5,
Yes = 6,
No = 7,
Retry = 8,
Stop = 9,
Help = 10,
YesToAll = 11,
NoToAll = 12
}
❄ 2、消息中心(MessageCenter)
Bentley在Bentley.MstnPlatformNET中也存在与消息管理器一样的类以供调用向用户传递消息。
dll名称:ustation.dll
命名空间:Bentley.MstnPlatformNET
类名:MessageCenter
public class MessageCenter
{
public static MessageCenter Instance { get; }
public string StatusWarning { set; }
public string StatusMessage { set; }
public string StatusPrompt { set; }
public string StatusCommand { get; set; }
public static string GetStringFromMessageListResource(int listId, int stringId);
public void ShowDebugMessage(string briefMessage, string detailedMessage, bool openAlertBox);
public void ShowDebugMessage(string briefMessage, string detailedMessage, MessageAlert alertType);
public void ShowErrorMessage(string briefMessage, string detailedMessage, bool openAlertBox);
public void ShowErrorMessage(string briefMessage, string detailedMessage, MessageAlert alertType);
public void ShowInfoMessage(string briefMessage, string detailedMessage, bool openAlertBox);
public void ShowInfoMessage(string briefMessage, string detailedMessage, MessageAlert alertType);
public void ShowMessage(MessageType messageType, string briefMessage, string detailedMessage, MessageAlert alertType);
}
❄ 3、测试代码
附上Notification Manager测试代码的链接,加载编译之后的ArticleSourceCode.dll,调用Key-in:test message manager。弹出一个操作窗体,通过选择不同选项,即可查看相应方法的效果。
❄ 4、使用方法
- OpenMessageBox方法
private void NotificationManagerOpenMessageBox()
{
NotificationManager.OpenMessageBox(NotificationManager.MessageBoxType.MediumAlert, "Medium alert",NotificationManager.MessageBoxIconType.Warning);
}
- OutputMessage方法
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);
}
- OutputPrompt方法
private void NotificationManagerOutputPrompt()
{
NotificationManager.OutputPrompt("this is ouput prompt");
}
未经授权,禁止转载哦~