WinForms
C#
Form1.cs
using System; using System.Windows.Forms; using DotNetBrowser; using DotNetBrowser.WinForms; namespace PasswordSaveSample { public partial class Form1 : Form { public Form1() { InitializeComponent(); BrowserView browserView = new WinFormsBrowserView(); Controls.Add((Control)browserView); browserView.Browser.PasswordManagerClient.PasswordSubmitted += PasswordManagerClient_PasswordSubmitted; browserView.Browser.PasswordManagerClient.UpdatePasswordSubmitted += PasswordManagerClient_UpdatePasswordSubmitted; browserView.Browser.LoadURL("gmail.com"); } private void PasswordManagerClient_UpdatePasswordSubmitted(object sender, PasswordEventArgs e) { Form window = this; window.Invoke((Action)(() => { DialogResult result = MessageBox.Show(window, "Do you want to update password for " + e.Login + "?\nWebsite: " + e.Url, "Update Password", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); switch (result) { case DialogResult.Yes: e.Action = SaveAction.Update; break; } })); } private void PasswordManagerClient_PasswordSubmitted(object sender, PasswordEventArgs e) { Form window = this; window.Invoke((Action)(() => { DialogResult result = MessageBox.Show(window, "Do you want to save password for " + e.Login + "?\nWebsite: " + e.Url, "Save Password", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3); switch (result) { case DialogResult.Yes: e.Action = SaveAction.Save; break; case DialogResult.No: e.Action = SaveAction.Blacklist; break; } })); } } }
VB.NET
Form1.vb
Imports DotNetBrowser Imports DotNetBrowser.WinForms Public Partial Class Form1 Inherits Form Public Sub New() InitializeComponent() Dim browserView = New WinFormsBrowserView With{ .Dock = DockStyle.Fill } Controls.Add(browserView) AddHandler browserView.Browser.PasswordManagerClient.PasswordSubmitted, AddressOf PasswordManagerClient_PasswordSubmitted AddHandler browserView.Browser.PasswordManagerClient.UpdatePasswordSubmitted, AddressOf PasswordManagerClient_UpdatePasswordSubmitted browserView.Browser.LoadURL("gmail.com") End Sub Private Sub PasswordManagerClient_UpdatePasswordSubmitted(ByVal sender As Object, ByVal e As PasswordEventArgs) Dim window As Form = Me window.Invoke(CType((Sub() Dim result As DialogResult = MessageBox.Show(window, "Do you want to update password for " & e.Login & "?" & vbLf & "Website: " + e.Url, "Update Password", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) Select Case result Case DialogResult.Yes e.Action = SaveAction.Update End Select End Sub), Action)) End Sub Private Sub PasswordManagerClient_PasswordSubmitted(ByVal sender As Object, ByVal e As PasswordEventArgs) Dim window As Form = Me window.Invoke(CType((Sub() Dim result As DialogResult = MessageBox.Show(window, "Do you want to save password for " & e.Login & "?" & vbLf & "Website: " + e.Url, "Save Password", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3) Select Case result Case DialogResult.Yes e.Action = SaveAction.Save Case DialogResult.No e.Action = SaveAction.Blacklist End Select End Sub), Action)) End Sub End Class
WPF
MainWindow.xaml
<Window x:Class="PasswordSaveSample.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wpf="clr-namespace:DotNetBrowser.WPF;assembly=DotNetBrowser" Title="MainWindow" Height="350" Width="525"> <Grid> <wpf:WPFBrowserView Name="BrowserView" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/> </Grid> </Window>
C#
MainWindow.xaml.cs
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; using DotNetBrowser; namespace PasswordSaveSample { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); BrowserView.Browser.PasswordManagerClient.PasswordSubmitted += PasswordManagerClient_PasswordSubmitted; BrowserView.Browser.PasswordManagerClient.UpdatePasswordSubmitted += PasswordManagerClient_UpdatePasswordSubmitted; BrowserView.Browser.LoadURL("gmail.com"); } void PasswordManagerClient_PasswordSubmitted(object sender, PasswordEventArgs e) { var window = this; Application.Current.Dispatcher.Invoke(() => { var result = MessageBox.Show(window, "Do you want to save password for " + e.Login + "?\nWebsite: " + e.Url, "Save Password", MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Cancel); switch (result) { case MessageBoxResult.Yes: e.Action = SaveAction.Save; break; case MessageBoxResult.No: e.Action = SaveAction.Blacklist; break; } }); } void PasswordManagerClient_UpdatePasswordSubmitted(object sender, PasswordEventArgs e) { var window = this; Application.Current.Dispatcher.Invoke(() => { var result = MessageBox.Show(window, "Do you want to update password for " + e.Login + "?\nWebsite: " + e.Url, "Update Password", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Cancel); switch (result) { case MessageBoxResult.Yes: e.Action = SaveAction.Update; break; } }); } } }
VB.NET
MainWindow.xaml.vb
Imports DotNetBrowser Namespace PasswordSaveSample Public Partial Class MainWindow Inherits Window Public Sub New() InitializeComponent() AddHandler BrowserView.Browser.PasswordManagerClient.PasswordSubmitted, AddressOf PasswordManagerClient_PasswordSubmitted AddHandler BrowserView.Browser.PasswordManagerClient.UpdatePasswordSubmitted, AddressOf PasswordManagerClient_UpdatePasswordSubmitted BrowserView.Browser.LoadURL("gmail.com") End Sub Private Sub PasswordManagerClient_PasswordSubmitted(ByVal sender As Object, ByVal e As PasswordEventArgs) Dim window = Me Application.Current.Dispatcher.Invoke(sub() Dim result = MessageBox.Show(window, "Do you want to save password for " & e.Login & "?" & vbLf & "Website: " + e.Url, "Save Password", MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Cancel) Select Case result Case MessageBoxResult.Yes e.Action = SaveAction.Save Case MessageBoxResult.No e.Action = SaveAction.Blacklist End Select End sub) End Sub Private Sub PasswordManagerClient_UpdatePasswordSubmitted(ByVal sender As Object, ByVal e As PasswordEventArgs) Dim window = Me Application.Current.Dispatcher.Invoke(sub() Dim result = MessageBox.Show(window, "Do you want to update password for " & e.Login & "?" & vbLf & "Website: " + e.Url, "Update Password", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Cancel) Select Case result Case MessageBoxResult.Yes e.Action = SaveAction.Update End Select End sub) End Sub End Class End Namespace