0

Good day

I have made a small website for my google api( because I didn't find a way to use it in my C# Form program). The idea is that when I click on the map icon a event needs to trigger in side the C# Program. I am using the webbrowser tool on my C# From to show my website. I am really hoping this is even possible.

If the above is not possible or if any one has a better idea on how to implement a map on a forms application with icons/buttons it will really help.

I have looked at : Sharpmap -- but my employer doesn't like the look and : ThinkGeo] -- it costs money (still a option)

1

2 Answers 2

0

This documentation describes two-way communication between a web browser control and the form on which it resides, which includes raising events from the browser control to be handled by the form.

A few key details:

In the Form_Load event, the control's ObjectForScripting property is set to the form:

webBrowser1.ObjectForScripting = this;

In the HTML within the browser control, window.external is used to access methods in the 'object for scripting.'

webBrowser1.DocumentText =
        "<html><head><script>" +
        "function test(message) { alert(message); }" +
        "</script></head><body><button " +
        "onclick=\"window.external.Test('called from script code')\">" +
        "call client code from script code</button>" +
        "</body></html>";

So this:

window.external.Test('called from script code')

calls the Test method within the form, passing called from script code as an argument.

public void Test(String message)
{
    MessageBox.Show(message, "client code");
}
Sign up to request clarification or add additional context in comments.

Comments

0

Thx Scott I got the From to register my java Script events. All you have to do extra from what Scot said is add these namespaces:

using System.Runtime.InteropServices;
using System.Security.Permissions;

and this above your form obj

[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public partial class Form1 : Form
   {...}

I also didn't use webBrowser1.DocumentText I used webBrowser1.Url-- i made the website 1st and just added it. There is problem with this the website needs to be hosted so use XAMPP to local host it(for testing)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.