Confirm 方法
.NET Framework 类库
HtmlWindow..::.Confirm 方法

更新:2007 年 11 月

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

命名空间:  System.Windows.Forms
程序集:  System.Windows.Forms(在 System.Windows.Forms.dll 中)

Visual Basic(声明)
Public Function Confirm ( _
    message As String _
) As Boolean
Visual Basic (用法)
Dim instance As HtmlWindow
Dim message As String
Dim returnValue As Boolean

returnValue = instance.Confirm(message)
C#
public bool Confirm(
    string message
)
Visual C++
public:
bool Confirm(
    String^ message
)
J#
public boolean Confirm(
    String message
)
JScript
public function Confirm(
    message : String
) : boolean

参数

message
类型:System..::.String

返回值

类型:System..::.Boolean

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

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

虽然 Confirm 接受 Unicode 文本作为输入,但由于操作系统的限制,Internet Explorer 脚本提示不会在 Windows 95、Windows 98、Windows ME 或 Windows NT 上显示相应的非拉丁语言文本。有关更多信息,请参见“INFO: Internet Explorer Script Prompts and MBCS/Unicode”(信息:Internet Explorer 脚本提示和 MBCS/Unicode) (http://support.microsoft.com/default.aspx?scid=kb;en-us;211147)。

复制下面的 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 对话框。

Visual Basic
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
C#
        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.");
            }
        }

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

.NET Framework

受以下版本支持:3.5、3.0、2.0
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
Page view tracker