Editor commands are the commands for text manipulation when editing in a text field, text area or WYSIWYG editor. Also, these commands include more common commands like Cut, Copy, Paste, SelectAll, Undo, Redo, which can be executed for the frame in the loaded web page.


DotNetBrowser 1.8.1 brings support for a number of such editor commands. 


The following sample demonstrates how to perform Google Search via the editor commands only.

C#

using System;
using System.Windows;
using DotNetBrowser;
using DotNetBrowser.Events;
using DotNetBrowser.WPF;

namespace ExecuteCommandSample
{
    /// <summary>
    /// This sample demonstrates how to execute Browser commands such as Cut, Copy,
    /// Paste, Undo, SelectAll, InsertText etc.
    /// </summary>
    class Program
    {
        public class WindowMain : Window
        {
            private WPFBrowserView browserView;

            public WindowMain()
            {
                BrowserContext browserContext = BrowserContext.DefaultContext;

                Browser browser = BrowserFactory.Create(browserContext);

                browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e)
                {
                    if (e.IsMainFrame)
                    {
                        // Inserts "TeamDev DotNetBrowser" text into Google Search field.
                        browser.ExecuteCommand(EditorCommand.INSERT_TEXT, "TeamDev DotNetBrowser");
                        // Inserts a new line into Google Search field to simulate Enter.
                        browser.ExecuteCommand(EditorCommand.INSERT_NEW_LINE);
                    }

                };

                browserView = new WPFBrowserView(browser);
                Content = browserView;

                Width = 1024;
                Height = 768;
                this.Loaded += WindowMain_Loaded;
            }

            void WindowMain_Loaded(object sender, RoutedEventArgs e)
            {
                browserView.Browser.LoadURL("http://www.google.com");
            }

            [STAThread]
            public static void Main()
            {
                Application app = new Application();

                WindowMain wnd = new WindowMain();
                app.Run(wnd);

                var browser = wnd.browserView.Browser;
                wnd.browserView.Dispose();
                browser.Dispose();
            }
        }
    }
}

VB.NET

Imports System.Windows
Imports DotNetBrowser
Imports DotNetBrowser.Events
Imports DotNetBrowser.WPF

Module Module1
    '' <summary>
    '' This sample demonstrates how to execute Browser commands such as Cut, Copy,
    '' Paste, Undo, SelectAll, InsertText etc.
    '' </summary>
    Public Class WindowMain
        Inherits Window

        Public browserView As WPFBrowserView

        Sub New()

            Dim browserContext As BrowserContext = BrowserContext.DefaultContext

            Dim browser As Browser = BrowserFactory.Create(browserContext)

            AddHandler browser.FinishLoadingFrameEvent,
                Sub(sender As Object, e As FinishLoadingEventArgs)
                    If e.IsMainFrame Then

                        ' Inserts "TeamDev DotNetBrowser" text into Google Search field.
                        browser.ExecuteCommand(EditorCommand.INSERT_TEXT, "TeamDev DotNetBrowser")
                        ' Inserts a New line into Google Search field to simulate Enter.
                        browser.ExecuteCommand(EditorCommand.INSERT_NEW_LINE)
                    End If
                End Sub

            browserView = New WPFBrowserView(browser)
            Content = browserView

            Width = 1024
            Height = 768
            AddHandler Me.Loaded, AddressOf WindowMain_Loaded
        End Sub

        Private Sub WindowMain_Loaded(o As Object, e As RoutedEventArgs)
            browserView.Browser.LoadURL("http://www.google.com")
        End Sub
    End Class
    <STAThread>
    Sub Main()
        Dim app As Application = New Application()

        Dim wnd As WindowMain = New WindowMain()
        app.Run(wnd)

        Dim browser = wnd.browserView.Browser
        wnd.browserView.Dispose()
        browser.Dispose()
    End Sub
End Module