Update webbrowser sample (#173)

* Update webbrowser sample

As per suggestions https://github.com/dotnet/winforms/issues/4443#issuecomment-759333446

Resolves dotnet/winforms#4443

* fixup! Update webbrowser sample

* fixup! Update webbrowser sample

* Update dotnet-desktop-guide/framework/winforms/controls/implement-two-way-com-between-dhtml-and-client.md

Co-authored-by: Andy De George <[email protected]>

Co-authored-by: Andy De George <[email protected]>
This commit is contained in:
Igor Velikorossov
2021-01-27 14:21:32 -08:00
committed by GitHub
co-authored by Andy De George
parent 232f1b91e2
commit 1fe35d6424
5 changed files with 62 additions and 32 deletions
@@ -38,19 +38,14 @@ The <xref:System.Windows.Forms.WebBrowser> control lets you implement two-way co
[!code-csharp[System.Windows.Forms.WebBrowser.ObjectForScripting#3](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.WebBrowser.ObjectForScripting/CS/form1.cs#3)]
[!code-vb[System.Windows.Forms.WebBrowser.ObjectForScripting#3](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.WebBrowser.ObjectForScripting/vb/form1.vb#3)]
4. Set the <xref:System.Windows.Forms.WebBrowser.ObjectForScripting%2A> property in the form's constructor or a <xref:System.Windows.Forms.Form.Load> event handler.
4. Set the <xref:System.Windows.Forms.WebBrowser.ObjectForScripting%2A> property in the form's constructor or override the <xref:System.Windows.Forms.Form.OnLoad%2A> method.
The following code uses the form class itself for the scripting object.
> [!NOTE]
> Component Object Model (COM) must be able to access the scripting object. To make your form visible to COM, add the <xref:System.Runtime.InteropServices.ComVisibleAttribute> attribute to your form class.
[!code-csharp[System.Windows.Forms.WebBrowser.ObjectForScripting#4](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.WebBrowser.ObjectForScripting/CS/form1.cs#4)]
[!code-vb[System.Windows.Forms.WebBrowser.ObjectForScripting#4](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.WebBrowser.ObjectForScripting/vb/form1.vb#4)]
5. Implement public properties or methods in your application code that your script code will use.
For example, if you use the form class for the scripting object, add the following code to your form class.
5. Implement your scripting object.
[!code-csharp[System.Windows.Forms.WebBrowser.ObjectForScripting#5](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.WebBrowser.ObjectForScripting/CS/form1.cs#5)]
[!code-vb[System.Windows.Forms.WebBrowser.ObjectForScripting#5](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.WebBrowser.ObjectForScripting/vb/form1.vb#5)]