mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-04 09:06:04 +02:00
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:
co-authored by
Andy De George
parent
232f1b91e2
commit
1fe35d6424
+21
-13
@@ -1,10 +1,7 @@
|
||||
//<snippet0>
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using System.Security.Permissions;
|
||||
|
||||
[PermissionSet(SecurityAction.Demand, Name="FullTrust")]
|
||||
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
|
||||
public class Form1 : Form
|
||||
{
|
||||
private WebBrowser webBrowser1 = new WebBrowser();
|
||||
@@ -25,11 +22,12 @@ public class Form1 : Form
|
||||
webBrowser1.Dock = DockStyle.Fill;
|
||||
Controls.Add(webBrowser1);
|
||||
Controls.Add(button1);
|
||||
Load += new EventHandler(Form1_Load);
|
||||
}
|
||||
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
base.OnLoad(e);
|
||||
|
||||
//<snippet1>
|
||||
webBrowser1.AllowWebBrowserDrop = false;
|
||||
//</snippet1>
|
||||
@@ -40,7 +38,7 @@ public class Form1 : Form
|
||||
webBrowser1.WebBrowserShortcutsEnabled = false;
|
||||
//</snippet3>
|
||||
//<snippet4>
|
||||
webBrowser1.ObjectForScripting = this;
|
||||
webBrowser1.ObjectForScripting = new MyScriptObject(this);
|
||||
//</snippet4>
|
||||
//<snippet9>
|
||||
// Uncomment the following line when you are finished debugging.
|
||||
@@ -56,13 +54,6 @@ public class Form1 : Form
|
||||
"</body></html>";
|
||||
}
|
||||
|
||||
//<snippet5>
|
||||
public void Test(String message)
|
||||
{
|
||||
MessageBox.Show(message, "client code");
|
||||
}
|
||||
//</snippet5>
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
//<snippet8>
|
||||
@@ -71,4 +62,21 @@ public class Form1 : Form
|
||||
//</snippet8>
|
||||
}
|
||||
}
|
||||
|
||||
//<snippet5>
|
||||
public class MyScriptObject
|
||||
{
|
||||
private Form1 _form;
|
||||
|
||||
public MyScriptObject(Form1 form)
|
||||
{
|
||||
_form = form;
|
||||
}
|
||||
|
||||
public void Test(string message)
|
||||
{
|
||||
MessageBox.Show(message, "client code");
|
||||
}
|
||||
}
|
||||
//</snippet5>
|
||||
//</snippet0>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFrameworks>net472;netcoreapp3.1;net5.0-windows</TargetFrameworks>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
+18
-12
@@ -1,9 +1,6 @@
|
||||
'<snippet0>
|
||||
Imports System.Windows.Forms
|
||||
Imports System.Security.Permissions
|
||||
|
||||
<PermissionSet(SecurityAction.Demand, Name:="FullTrust")> _
|
||||
<System.Runtime.InteropServices.ComVisibleAttribute(True)> _
|
||||
Public Class Form1
|
||||
Inherits Form
|
||||
|
||||
@@ -24,8 +21,8 @@ Public Class Form1
|
||||
Controls.Add(button1)
|
||||
End Sub
|
||||
|
||||
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
|
||||
Handles Me.Load
|
||||
Protected Overrides Sub OnLoad(e As EventArgs)
|
||||
MyBase.OnLoad(e)
|
||||
|
||||
'<snippet1>
|
||||
webBrowser1.AllowWebBrowserDrop = False
|
||||
@@ -37,7 +34,7 @@ Public Class Form1
|
||||
webBrowser1.WebBrowserShortcutsEnabled = False
|
||||
'</snippet3>
|
||||
'<snippet4>
|
||||
webBrowser1.ObjectForScripting = Me
|
||||
webBrowser1.ObjectForScripting = New MyScriptObject(Me)
|
||||
'</snippet4>
|
||||
'<snippet9>
|
||||
' Uncomment the following line when you are finished debugging.
|
||||
@@ -53,12 +50,6 @@ Public Class Form1
|
||||
"</body></html>"
|
||||
End Sub
|
||||
|
||||
'<snippet5>
|
||||
Public Sub Test(ByVal message As String)
|
||||
MessageBox.Show(message, "client code")
|
||||
End Sub
|
||||
'</snippet5>
|
||||
|
||||
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
|
||||
Handles button1.Click
|
||||
|
||||
@@ -70,4 +61,19 @@ Public Class Form1
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
'<snippet5>
|
||||
Public Class MyScriptObject
|
||||
Private _form As Form1
|
||||
|
||||
Public Sub New(ByVal form As Form1)
|
||||
_form = form
|
||||
End Sub
|
||||
|
||||
Public Sub Test(ByVal message As String)
|
||||
MessageBox.Show(message, "client code")
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
'</snippet5>
|
||||
'</snippet0>
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFrameworks>net472;net5.0-windows</TargetFrameworks>
|
||||
<RootNamespace>sample</RootNamespace>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<MyType>WindowsForms</MyType>
|
||||
<StartupObject>sample.Form1</StartupObject>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user