The following sample demonstrates how to customize JavaScript Alert dialog by registering custom DialogHandler implementation. Using same technique you can override other dialogs such as JavaScript Confirmation, Prompt, Before Unload, Reload POST data, File Open/Save dialogs, etc.

C#

Form1.cs

using DotNetBrowser;
using DotNetBrowser.WinForms;
using System;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinForms.CustomDialogsSample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            // Initialize BrowserView
            var browser = BrowserFactory.Create();
            BrowserView browserView = new WinFormsBrowserView(browser);
            Controls.Add((Control)browserView);

            browser.DialogHandler = new CustomDialogHandler((Control)browserView, WindowsFormsSynchronizationContext.Current);
            
            browser.LoadHTML("<html><body><p>Click the button to display an alert box.</p><button onclick='myFunction()'>Try it</button><script>function myFunction() { alert('Hello! I am an alert box!');}</script></body></html>");
        }
    }
}


CustomDialogHandler.cs

using DotNetBrowser;
using DotNetBrowser.WinForms;
using System;
using System.Threading;
using System.Windows.Forms;

namespace WinForms.CustomDialogsSample
{
    class CustomDialogHandler : DialogHandler
    {
        private WinFormsDefaultDialogHandler handler;
        private Control control;
        private SynchronizationContext synchronizationContext;

        public CustomDialogHandler(Control control,System.Threading.SynchronizationContext synchronizationContext)
        {
            this.control = control;
            this.synchronizationContext = synchronizationContext;
            handler = new WinFormsDefaultDialogHandler(control);
        }

        public void OnAlert(DialogParams parameters)
        {
            synchronizationContext.Send(new SendOrPostCallback(
               delegate(object state)
               {
                   String url = parameters.Url;
                   String title = "Message from \"" + url + "\"";
                   String message = parameters.Message;
                   MessageBox.Show(control, message, title);
               }), parameters);
        }

        public CloseStatus OnBeforeUnload(UnloadDialogParams parameters)
        {
            return handler.OnBeforeUnload(parameters);
        }

        public CloseStatus OnConfirmation(DialogParams parameters)
        {
            return handler.OnConfirmation(parameters);
        }

        public CloseStatus OnFileChooser(FileChooserParams parameters)
        {
            return handler.OnFileChooser(parameters);
        }

        public CloseStatus OnPrompt(PromptDialogParams parameters)
        {
            return handler.OnPrompt(parameters);
        }

        public CloseStatus OnReloadPostData(ReloadPostDataParams parameters)
        {
            return handler.OnReloadPostData(parameters);
        }

        public CloseStatus OnColorChooser(ColorChooserParams parameters)
        {
            return handler.OnColorChooser(parameters);
        }

        public CloseStatus OnSelectCertificate(CertificatesDialogParams parameters)
        {
            return handler.OnSelectCertificate(parameters);
        }
    }
}


VB.NET

Form1.vb

Imports DotNetBrowser
Imports DotNetBrowser.WinForms

Public Partial Class Form1
    Inherits Form

    Public Sub New()
        InitializeComponent()
        Dim browser = BrowserFactory.Create()
        Dim browserView As BrowserView = New WinFormsBrowserView(browser)
        CType(browserView, Control).Dock = DockStyle.Fill

        Controls.Add(CType(browserView, Control))
        browser.DialogHandler = New CustomDialogHandler(CType(browserView, Control),
                                                        WindowsFormsSynchronizationContext.Current)
        browser.LoadHTML(
            "<html>
                <body>
                    <p>Click the button to display an alert box.</p>
                    <button onclick='myFunction()'>Try it</button>
                    <script>function myFunction() { alert('Hello! I am an alert box!');}</script>
                </body>
            </html>")
    End Sub
End Class


CustomDialogHandler.vb

Imports System.Threading
Imports DotNetBrowser
Imports DotNetBrowser.WinForms


Class CustomDialogHandler
    Implements DialogHandler

    Private handler As WinFormsDefaultDialogHandler
    Private control As Control
    Private synchronizationContext As SynchronizationContext

    Public Sub New(ByVal control As Control, ByVal synchronizationContext As System.Threading.SynchronizationContext)
        Me.control = control
        Me.synchronizationContext = synchronizationContext
        handler = New WinFormsDefaultDialogHandler(control)
    End Sub

    Public Sub OnAlert(ByVal parameters As DialogParams) _
        Implements DialogHandler.OnAlert
        synchronizationContext.Send(New SendOrPostCallback(Sub(ByVal state As Object)
            Dim url As String = parameters.Url
            Dim title As String = "Message from """ & url & """"
            Dim message As String = parameters.Message
            MessageBox.Show(control, message, title)
        End Sub), parameters)
    End Sub

    Public Function OnBeforeUnload(ByVal parameters As UnloadDialogParams) As CloseStatus _
        Implements DialogHandler.OnBeforeUnload
        Return handler.OnBeforeUnload(parameters)
    End Function

    Public Function OnConfirmation(ByVal parameters As DialogParams) As CloseStatus _
        Implements DialogHandler.OnConfirmation
        Return handler.OnConfirmation(parameters)
    End Function

    Public Function OnFileChooser(ByVal parameters As FileChooserParams) As CloseStatus _
        Implements DialogHandler.OnFileChooser
        Return handler.OnFileChooser(parameters)
    End Function

    Public Function OnPrompt(ByVal parameters As PromptDialogParams) As CloseStatus _
        Implements DialogHandler.OnPrompt
        Return handler.OnPrompt(parameters)
    End Function

    Public Function OnReloadPostData(ByVal parameters As ReloadPostDataParams) As CloseStatus _
        Implements DialogHandler.OnReloadPostData
        Return handler.OnReloadPostData(parameters)
    End Function

    Public Function OnColorChooser(ByVal parameters As ColorChooserParams) As CloseStatus _
        Implements DialogHandler.OnColorChooser
        Return handler.OnColorChooser(parameters)
    End Function

    Public Function OnSelectCertificate(ByVal parameters As CertificatesDialogParams) As CloseStatus _
        Implements DialogHandler.OnSelectCertificate
        Return handler.OnSelectCertificate(parameters)
    End Function
End Class