警報窗口與HTML模板
受web啟發的HTML和CSS模板允許您設計具有任何自定義外觀和布局的警報。

創建靜態警報模板
點擊AlertControl.HtmlTemplate屬性旁邊的省略號按鈕來調用模板編輯器。

如果您需要多個模板,請填充AlertControl.HtmlTemplates集合,也可以使用此集合在顯示通知之前切換活動模板。
C#:
alertControl1.HtmlTemplate.Assign(alertControl1.HtmlTemplates[1]);
點擊復制
VB.NET:
alertControl1.HtmlTemplate.Assign(alertControl1.HtmlTemplates(1))
點擊復制
<img>標簽允許您向模板添加圖標。用矢量圖像填充SvgImageCollection,并將其分配給AlertControl.HtmlImages屬性。當一個圖像集合被分配給Alert控件時,可以在模板語法編輯器中按Ctrl+Space來瀏覽存儲在該集合中的圖標列表,并將所需的圖像分配給<img>標簽的src屬性。
HTML:
c<img src="message_icon_2"/>
點擊復制
要用靜態模板顯示通知,請使用AlertControl.Show(Form)方法,該方法只接受父對象(Form)作為參數。
C#:
alertControl1.Show(this);
點擊復制
VB.NET:
alertControl1.Show(Me)
點擊復制
用可變數據創建模板
除了帶有靜態標題和文本字符串的模板之外,還可以創建帶有值占位符的HTML元素。
HTML:
<div class="text">${Caption}</div> <div class="text">${Text}</div>
點擊復制
使用AlertControl.Show方法重載" Caption "和" Text "參數來傳遞真實值給這些HTML元素。因此,您可以對各種通知使用相同的模板設計。
C#:
alertControl1.Show(this, "Sample caption", "Sample notification text");
點擊復制
VB.NET:
alertControl1.Show(Me, "Sample caption", "Sample notification text")
點擊復制
您還可以對AlertInfo參數使用重載,這個重載允許將字符串和圖像數據傳遞給HTML元素。
HTML:
<div class="text">${Caption}</div> <div class="text">${Text}</div> <img src="${SvgImage}"/>
點擊復制
C#:
AlertInfo aInfo = new AlertInfo("Sample notification", "This text is stored in the AlertInfo object"); aInfo.ImageOptions.SvgImage = svgImageCollection1[0]; alertControl1.Show(this, aInfo);
點擊復制
VB.NET:
Dim aInfo As New AlertInfo("Sample notification", "This text is stored in the AlertInfo object") aInfo.ImageOptions.SvgImage = svgImageCollection1(0) alertControl1.Show(Me, aInfo)
點擊復制
如果需要具有多個數據綁定元素的復雜模板,請創建自定義數據存儲。要將數據從這個對象傳遞給HTML元素,使用相應的Show方法重載或處理AlertControl.BeforeFormShow事件。
HTML:
<div class="title-main">${Title}</div> <div class="title-sub">${Subtitle}</div> <div class="text">${PrimaryText}</div> <div class="text">${SecondaryText}</div>
點擊復制
C#:
alertControl1.Show(this, new AlertData("Sample Title", "Sample Subtitle", "Primary Text Block", "Secondary Text Block")); // or alertControl1.Show(this); private void AlertControl1_BeforeFormShow(object sender, AlertFormEventArgs e) { e.HtmlPopup.DataContext = new AlertData("Sample Title", "Sample Subtitle", "Primary Text Block", "Secondary Text Block"); } // Custom class whose instances are used as DataContext public class AlertData { public AlertData(string title, string subtitle, string primaryText, string secondaryText) { Title = title; Subtitle = subtitle; PrimaryText = primaryText; SecondaryText = secondaryText; } public string Title { get; set; } public string Subtitle { get; set; } public string PrimaryText { get; set; } public string SecondaryText { get; set; } }
點擊復制
VB.NET:
alertControl1.Show(Me, New AlertData("Sample Title", "Sample Subtitle", "Primary Text Block", "Secondary Text Block")) ' or alertControl1.Show(Me) private void AlertControl1_BeforeFormShow(Object sender, AlertFormEventArgs e) e.HtmlPopup.DataContext = New AlertData("Sample Title", "Sample Subtitle", "Primary Text Block", "Secondary Text Block") ' Custom class whose instances are used as DataContext public class AlertData public AlertData(String title, String subtitle, String primaryText, String secondaryText) Title = title Subtitle = subtitle PrimaryText = primaryText SecondaryText = secondaryText public String Title {get;set;} public String Subtitle {get;set;} public String PrimaryText {get;set;} public String SecondaryText {get;set;}
點擊復制
管理通知
所有的AlertControl設置指定的位置和行為的常規警報窗口也可以用于模板警報:
- FormLocation
- AutoFormDelay
- FormDisplaySpeed
- FormShowingEffect
- FormMaxCount
要關閉和固定模板警報,您可以創建具有唯一id的按鈕,并處理AlertControl.HtmlElementMouseClick事件。
HTML:
<div id="pinButton" class="button">Pin</div> <div id="closeButton" class="button">Close</div>
點擊復制
C#:
private void OnHtmlElementMouseClick(object sender, AlertHtmlElementMouseEventArgs e) { if (e.ElementId == "pinButton") e.HtmlPopup.Pinned = !e.HtmlPopup.Pinned; if (e.ElementId == "closeButton") e.HtmlPopup.Close(); }
點擊復制
VB.NET:
Private Sub OnHtmlElementMouseClick(ByVal sender As Object, ByVal e As AlertHtmlElementMouseEventArgs) If e.ElementId = "pinButton" Then e.HtmlPopup.Pinned = Not e.HtmlPopup.Pinned End If If e.ElementId = "closeButton" Then e.HtmlPopup.Close() End If End Sub
點擊復制
RaiseHtmlElementClick方法允許手動觸發與所需HTML元素相關的操作(使用唯一的元素id來標識HTML元素)。
C#:
alertControl1.RaiseHtmlElementClick("closeButton", e.HtmlPopup);
點擊復制
VB.NET:
alertControl1.RaiseHtmlElementClick("closeButton", e.HtmlPopup)
點擊復制