HtmlWindow.Confirm(String) 方法

定义

显示一个包含一则消息和多个按钮的对话框以请求作出“是”/“否”等响应。

public:
 bool Confirm(System::String ^ message);
public bool Confirm (string message);
member this.Confirm : string -> bool
Public Function Confirm (message As String) As Boolean

参数

message
String

要显示给用户的文本。

返回

如果用户单击“是”,则为 true;如果用户单击“否”或关闭对话框,则为 false

示例

复制以下 HTML 并将其保存到名为 orderForm.htm 的窗体中:

<HTML>
<BODY>
<FORM name="NewOrderForm">
Select Part Type:
<SELECT name="PartType">
  <OPTION>AZ-3700
  <OPTION>AZ-3701
  <OPTION>AZ-3702
</SELECT><br/>
Quantity: <INPUT type="text" name="PartQty" size="2" maxsize="2" /><br/>
Building/Desk:
<INPUT type="text" name="PartBuilding" size="2" maxsize="2"/> /
<INPUT type="text" name="PartDesk" size="2" maxsize="2"/><p/>
<INPUT type="submit" value="Transmit Order"/>
</FORM>
</BODY>
</HTML>

以下示例在用户提交 NewOrderForm时显示一个Confirm对话框。

HtmlWindow orderWindow;
HtmlElement formElement;

private void LoadOrderForm()
{
    if (!(webBrowser1.Document == null)) 
    {
        HtmlDocument doc = webBrowser1.Document;
        orderWindow = doc.Window.OpenNew(new Uri("file://C:\\orderForm.htm"), "");

        //!TODO: Perform this in the load event handler!
        // Get order form. 
        HtmlElementCollection elemCollection = doc.All.GetElementsByName("NewOrderForm");
        if (elemCollection.Count == 1) 
        {
            formElement = elemCollection[0];
            //!TODO: Awaiting DCR
            //formElement.AttachEventHandler("onsubmit", new HtmlElementEventHandler(Form_Submit));
        }
    }
}

private void Form_Submit(object sender, HtmlElementEventArgs e)
{
    bool doOrder = orderWindow.Confirm("Once you transmit this order, you cannot cancel it. Submit?");
    if (!doOrder)
    {
        //Cancel the submit. 
        e.ReturnValue = false;
        orderWindow.Alert("Submit cancelled.");
    }
}
Dim OrderWindow As HtmlWindow
Dim FormElement As HtmlElement

Private Sub NewOrderButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewOrderButton.Click
    LoadOrderForm()
End Sub

Private Sub LoadOrderForm()
    If (WebBrowser1.Document IsNot Nothing) Then
        With WebBrowser1.Document
            OrderWindow = .Window.OpenNew(New Uri("file://C:\\orderForm.htm"), "")

            ' !TODO: Perform this in the load event handler!
            ' Get order form. 
            Dim ElemCollection As System.Windows.Forms.HtmlElementCollection = .All.GetElementsByName("NewOrderForm")
            If (ElemCollection.Count = 1) Then
                FormElement = ElemCollection(0)
                ' TODO: Resolve this. 
                'FormElement.AttachEventHandler("onsubmit", New HtmlElementEventHandler(AddressOf Form_Submit))
            End If
        End With

    End If
End Sub

Private Sub Form_Submit(ByVal sender As Object, ByVal e As HtmlElementEventArgs)
    Dim DoOrder As Boolean = OrderWindow.Confirm("Once you transmit this order, you cannot cancel it. Submit?")
    If (Not DoOrder) Then
        ' Cancel the submit. 
        e.ReturnValue = False
        OrderWindow.Alert("Submit cancelled.")
    End If
End Sub

注解

Confirm 显示模式对话框;如果不首先关闭此对话框,用户将无法访问基础 HTML 页。

适用于

另请参阅