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

The DialogHandler is responsible for displaying the JavaScript dialogs like alert or prompt, so your custom implementation can be used to disable them completely.

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 Class Form1
    Sub New
        InitializeComponent()

        Dim browser = BrowserFactory.Create()
        Dim browserView = new WinFormsBrowserView(browser)
        Controls.Add(browserView)

        browser.DialogHandler = New CustomDialogHandler(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>")
    End Sub
End Class


CustomDialogHandler.vb

Imports System.Threading
Imports DotNetBrowser
Imports DotNetBrowser.WinForms

Friend Class CustomDialogHandler
    Implements DialogHandler

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

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

    Public Sub OnAlert(parameters As DialogParams) Implements DialogHandler.OnAlert


        synchronizationContext.Send(New SendOrPostCallback(Sub(state)

            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 OnConfirmation(parameters As DialogParams) As CloseStatus Implements DialogHandler.OnConfirmation
        return handler.OnConfirmation(parameters)
    End Function

    Public Function OnPrompt(parameters As PromptDialogParams) As CloseStatus Implements DialogHandler.OnPrompt
        return handler.OnPrompt(parameters)
    End Function

    Public Function OnFileChooser(parameters As FileChooserParams) As CloseStatus Implements DialogHandler.OnFileChooser
        return handler.OnFileChooser(parameters)
    End Function

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

    Public Function OnSelectCertificate(parameters As CertificatesDialogParams) As CloseStatus _
        Implements DialogHandler.OnSelectCertificate
        return handler.OnSelectCertificate(parameters)
    End Function

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

    Public Function OnColorChooser(parameters As ColorChooserParams) As CloseStatus _
        Implements DialogHandler.OnColorChooser
        return handler.OnColorChooser(parameters)
    End Function
End Class