XVBAWindowObject 定義多種使用者介面互動功能,均受 UserInteractive 屬性控制(ASP.NET/Windows Service 環境下自動停用)。
private string GetDisplayText(object obj) => obj == null ? "[null]" : Convert.ToString(obj);
public void Alert(object text) {
if (!bolUserInteractive) return;
MessageBox.Show(myParentWindow, GetDisplayText(text), SystemName, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public void AlertError(object text) {
if (!bolUserInteractive) return;
MessageBox.Show(myParentWindow, GetDisplayText(text), SystemName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
public bool Confirm(object text) {
if (!bolUserInteractive) return false;
return MessageBox.Show(myParentWindow, GetDisplayText(text), SystemName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes;
}
public string Prompt(object caption, object defaultValue) {
if (!bolUserInteractive) return null;
return dlgInputBox.InputBox(myParentWindow, GetDisplayText(caption), SystemName, GetDisplayText(defaultValue));
}
public string BrowseFile(object caption, object filter) {
using (OpenFileDialog dlg = new OpenFileDialog()) {
dlg.CheckFileExists = true;
if (caption != null) dlg.Title = GetDisplayText(caption);
if (filter != null) dlg.Filter = GetDisplayText(filter);
return dlg.ShowDialog(myParentWindow) == DialogResult.OK ? dlg.FileName : null;
}
}
public string BrowseFolder(object caption) {
using (FolderBrowserDialog dlg = new FolderBrowserDialog()) {
if (caption != null) dlg.Description = GetDisplayText(caption);
dlg.RootFolder = Environment.SpecialFolder.MyComputer;
return dlg.ShowDialog(myParentWindow) == DialogResult.OK ? dlg.SelectedPath : null;
}
}
GetDisplayText 處理 null 與型別轉換bolUserInteractive,非互動環境直接返回預設值Alert 而非 VB 內建 MsgBox,前者受引擎控制