? 正文
?在進行Bentley二次開發(fā)的時候,通常我們需要向用戶輸出一些信息腐缤,比如操作的提示,錯誤的提示等等肛响×朐粒可以采用以下方式:
? 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);
//設(shè)置一個標志來分配(value==true時)事件偿渡,以便在執(zhí)行費時算法時臼寄,刷新界面霸奕,從而不卡頓溜宽。
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中也存在與消息管理器一樣的類以供調(diào)用向用戶傳遞消息质帅。
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煤惩,調(diào)用Key-in:test message manager嫉嘀。彈出一個操作窗體,通過選擇不同選項魄揉,即可查看相應(yīng)方法的效果剪侮。
? 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");
}
未經(jīng)授權(quán)洛退,禁止轉(zhuǎn)載哦~