C#

using DotNetBrowser;
using DotNetBrowser.Events;
using DotNetBrowser.WPF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace GetSelectedTextSample
{
    /// <summary>
    /// The sample demonstrates how to get selected text on a web page.
    /// </summary>
    class Program
    {
        public class WindowMain : Window
        {
            private Button btnSelectedText;
            private Button btnSelectedHtml;
            private WPFBrowserView browserView;
            private Grid layout;

            public WindowMain()
            {
                layout = new Grid();
                ColumnDefinition gridCol1 = new ColumnDefinition();
                layout.ColumnDefinitions.Add(gridCol1);
                RowDefinition gridRow1 = new RowDefinition();
                gridRow1.Height = new GridLength(45);
                RowDefinition gridRow2 = new RowDefinition();
                gridRow2.Height = new GridLength(45);
                RowDefinition gridRow3 = new RowDefinition();

                layout.RowDefinitions.Add(gridRow1);
                layout.RowDefinitions.Add(gridRow2);
                layout.RowDefinitions.Add(gridRow3);

                Content = layout;

                btnSelectedText = new Button();
                btnSelectedText.Content = "Get Selected Text";
                btnSelectedText.Height = 23;
                btnSelectedText.Click += btnSelectedText_Click;
                Grid.SetRow(btnSelectedText, 0);
                Grid.SetColumn(btnSelectedText, 0);

                btnSelectedHtml = new Button();
                btnSelectedHtml.Content = "Get Selected HTML";
                btnSelectedHtml.Height = 23;
                btnSelectedHtml.Click += btnSelectedHtml_Click;
                Grid.SetRow(btnSelectedHtml, 1);
                Grid.SetColumn(btnSelectedHtml, 0);

                browserView = new WPFBrowserView(BrowserFactory.Create());
                Grid.SetRow(browserView, 2);
                Grid.SetColumn(browserView, 0);

                layout.Children.Add(btnSelectedText);
                layout.Children.Add(btnSelectedHtml);
                layout.Children.Add(browserView);

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

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

            void btnSelectedText_Click(object sender, RoutedEventArgs e)
            {
                Console.Out.WriteLine(browserView.Browser.GetSelectedText());
            }

            void btnSelectedHtml_Click(object sender, RoutedEventArgs e)
            {
                Console.Out.WriteLine(browserView.Browser.GetSelectedHTML());
            }

            [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 DotNetBrowser
Imports DotNetBrowser.WPF
Imports System.Windows
Imports System.Windows.Controls

Module GetSelectedTextSample
    ''' <summary>
    ''' The sample demonstrates how to get selected text on a web page.
    ''' </summary>

        Public Class WindowMain
        Inherits Window

        Private btnSelectedText As Button
        Private btnSelectedHtml As Button
        Private browserView As WPFBrowserView
        Private layout As Grid

        Public Sub New()
            layout = New Grid()
            Dim gridCol1 As ColumnDefinition = New ColumnDefinition()
            layout.ColumnDefinitions.Add(gridCol1)
            Dim gridRow1 As RowDefinition = New RowDefinition()
            gridRow1.Height = New GridLength(45)
            Dim gridRow2 As RowDefinition = New RowDefinition()
            gridRow2.Height = New GridLength(45)
            Dim gridRow3 As RowDefinition = New RowDefinition()

            layout.RowDefinitions.Add(gridRow1)
            layout.RowDefinitions.Add(gridRow2)
            layout.RowDefinitions.Add(gridRow3)

            Content = layout

            btnSelectedText = New Button()
            btnSelectedText.Content = "Get Selected Text"
            btnSelectedText.Height = 23
            AddHandler btnSelectedText.Click, AddressOf btnSelectedText_Click
            Grid.SetRow(btnSelectedText, 0)
            Grid.SetColumn(btnSelectedText, 0)

            btnSelectedHtml = New Button()
            btnSelectedHtml.Content = "Get Selected HTML"
            btnSelectedHtml.Height = 23
            AddHandler btnSelectedHtml.Click, AddressOf btnSelectedHtml_Click
            Grid.SetRow(btnSelectedHtml, 1)
            Grid.SetColumn(btnSelectedHtml, 0)

            browserView = New WPFBrowserView(BrowserFactory.Create())
            Grid.SetRow(browserView, 2)
            Grid.SetColumn(browserView, 0)

            layout.Children.Add(btnSelectedText)
            layout.Children.Add(btnSelectedHtml)
            layout.Children.Add(browserView)

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

        Private Sub WindowMain_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            browserView.Browser.LoadURL("http://www.teamdev.com")
        End Sub

        Private Sub btnSelectedText_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
            Console.Out.WriteLine(browserView.Browser.GetSelectedText())
        End Sub

        Private Sub btnSelectedHtml_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
            Console.Out.WriteLine(browserView.Browser.GetSelectedHTML())
        End Sub

        <STAThread>
        Public Shared 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 Class
End Module