WinForms
C#
Form1.cs
using DotNetBrowser; using DotNetBrowser.WinForms; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WinForms.FindTextSample { public partial class Form1 : Form { private Browser browser; private BrowserView browserView; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { browserView = new WinFormsBrowserView(); browser = browserView.Browser; browser.LoadURL("google.com"); panel1.Controls.Add((Control)browserView); } private void find_Click(object sender, EventArgs e) { if (findTextBox.Text != String.Empty) { SearchParams searchParams = new SearchParams(findTextBox.Text); if (browser.FindText(searchParams).NumberOfMatches == 0) { MessageBox.Show("No matches!"); } } } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (!browser.IsDisposed()) { browserView.Dispose(); browserView.Browser.Dispose(); } } private void clear_Click(object sender, EventArgs e) { browser.StopFindingText(StopFindAction.CLEAR_SELECTION); findTextBox.Text = ""; } } }
VB.NET
Form1.vb
Imports DotNetBrowser Imports DotNetBrowser.WinForms Public Partial Class Form1 Inherits Form Private browser As Browser Private browserView As BrowserView Public Sub New() InitializeComponent() End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) browserView = New WinFormsBrowserView() browser = browserView.Browser browser.LoadURL("google.com") panel1.Controls.Add(CType(browserView, Control)) End Sub Private Sub find_Click(ByVal sender As Object, ByVal e As EventArgs) If findTextBox.Text <> String.Empty Then Dim searchParams As SearchParams = New SearchParams(findTextBox.Text) If browser.FindText(searchParams).NumberOfMatches = 0 Then MessageBox.Show("No matches!") End If End If End Sub Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) If Not browser.IsDisposed() Then browserView.Dispose() browserView.Browser.Dispose() End If End Sub Private Sub clear_Click(ByVal sender As Object, ByVal e As EventArgs) browser.StopFindingText(StopFindAction.CLEAR_SELECTION) findTextBox.Text = "" End Sub End Class
WPF
MainWindow.xaml
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WPF.FindTextSample" xmlns:WPF="clr-namespace:DotNetBrowser.WPF;assembly=DotNetBrowser" x:Class="WPF.FindTextSample.MainWindow" mc:Ignorable="d" Title="MainWindow" Height="677" Width="1269" Closing="Window_Closing"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="25*"/> <RowDefinition Height="30 "/> </Grid.RowDefinitions> <WPF:WPFBrowserView Name="browserView" Grid.Row="0" /> <Grid Name="gridPanel" Grid.Row="1" Height="30"> <Grid.ColumnDefinitions> <ColumnDefinition Width="150*"/> <ColumnDefinition Width="76"/> <ColumnDefinition Width="76"/> <ColumnDefinition Width="400*"/> </Grid.ColumnDefinitions> <TextBox x:Name="textBox" Grid.Column="0" Height="22" TextWrapping="Wrap" Margin="20, 4, 15, 4"/> <Button x:Name="findButton" Grid.Column="1" Content="Find/Next" HorizontalAlignment="Center" VerticalAlignment="Center" Width="75" Height="22" Click="findButton_Click" Margin="0,0,1,0"/> <Button x:Name="clearButton" Grid.Column="2" Content="Clear" HorizontalAlignment="Center" VerticalAlignment="Center" Width="75" Height="22" Click="clearButton_Click" Margin="1,0,0,0"/> </Grid> </Grid> </Window>
C#
MainWindow.xaml.cs
using DotNetBrowser; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WPF.FindTextSample { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); browserView.Browser.LoadURL("google.com"); } private void findButton_Click(object sender, RoutedEventArgs e) { if (textBox.Text != String.Empty) { if (browserView.Browser.FindText(new SearchParams(textBox.Text)).NumberOfMatches == 0) { MessageBox.Show("No matches!"); } } } private void clearButton_Click(object sender, RoutedEventArgs e) { browserView.Browser.StopFindingText(StopFindAction.CLEAR_SELECTION); textBox.Text = ""; } private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (!browserView.Browser.IsDisposed()) { browserView.Dispose(); browserView.Browser.Dispose(); } } } }
VB.NET
MainWindow.xaml.vb
Imports DotNetBrowser Namespace WPF.FindTextSample Public Partial Class MainWindow Inherits Window Public Sub New() InitializeComponent() browserView.Browser.LoadURL("google.com") End Sub Private Sub findButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) If textBox.Text <> String.Empty Then If browserView.Browser.FindText(New SearchParams(textBox.Text)).NumberOfMatches = 0 Then MessageBox.Show("No matches!") End If End If End Sub Private Sub clearButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) browserView.Browser.StopFindingText(StopFindAction.CLEAR_SELECTION) textBox.Text = "" End Sub Private Sub Window_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) If Not browserView.Browser.IsDisposed() Then browserView.Dispose() browserView.Browser.Dispose() End If End Sub End Class End Namespace