Click here to Skip to main content
15,113,970 members
Home / Discussions / C#
   

C#

 
AnswerRe: can't found provider sqlserver Pin
Wes Aday2-May-12 2:45
professionalWes Aday2-May-12 2:45 
GeneralRe: can't found provider sqlserver Pin
MemberDotNetting2-May-12 3:06
MemberMemberDotNetting2-May-12 3:06 
AnswerRe: can't found provider sqlserver Pin
egenis2-May-12 3:03
Memberegenis2-May-12 3:03 
Questionc# windows form & google api v3 Pin
mrx1002-May-12 1:39
Membermrx1002-May-12 1:39 
AnswerRe: c# windows form & google api v3 Pin
Richard MacCutchan2-May-12 3:42
mveRichard MacCutchan2-May-12 3:42 
GeneralRe: c# windows form & google api v3 Pin
mrx1002-May-12 5:38
Membermrx1002-May-12 5:38 
GeneralRe: c# windows form & google api v3 Pin
mrx1002-May-12 5:49
Membermrx1002-May-12 5:49 
AnswerRe: c# windows form & google api v3 Pin
loyal ginger2-May-12 10:21
Memberloyal ginger2-May-12 10:21 
Your C# WinForm application with webbrowser control embedded in the form can use the following ways to achieve two-way communication between your C# code and the JavaScript code loaded by the webbrowser control.

From JavaScript to C#, follow these steps:

1. Create a member function in C#. In this example, suppose we have a function called "report_location":

C#
public void report_location(double latitude, double longitude)
{
    //you can do whatever you want to do in your C# function here
}

2. From your JavaScript code whenever you need to call the above C# function, do it like this:

JavaScript
window.external.report_location(...);

In the above function call the "..." represents the arguments you pass to the function. Use whatever arguments you need to use. For example if you are using Google Maps API and you add a listener to the map's click event, the function will be like this:

JavaScript
google.maps.event.addListener(
    map,
    'click',
    function(event){
        window.external.report_location(
            event.latLng.lat(),
            event.latLng.lng()
        );
    }
);

Your C# code will be able to get the clicked location's latitude/longitude.

From C# to JavaScript, follow these steps: (These will answer your specific question.)

1. In your JavaScript code create a function. In this example, suppose we have a function called "set_location":

JavaScript
function set_location(latitude, longitude){
    //this is your existing statement
    //var myLatlng = new google.maps.LatLng(30.050144, 31.240042);
    //this is the new statement
    var myLatlng = new google.maps.LatLng(latitude, longitude);
    //do whatever you want to do...
}

2. In your C# code whenever you need to call the above function to set the location, do it like this (suppose your webbrowser control is represented by the variable wb_map:

C#
wb_map.Document.InvokeScript(
    "set_location",
    new string[]{
        "30.050144",
        "31.240042"
    }
);

Of course if the numbers are stored in variables such as latitude, longitude, the above call will be

C#
wb_map.Document.InvokeScript(
    "set_location",
    new string[]{
        latitude.ToString(),
        longitude.ToString()
    }
);

Hope this answers your question. Happy programming!
GeneralRe: c# windows form & google api v3 Pin
mrx1003-May-12 8:39
Membermrx1003-May-12 8:39 
GeneralRe: c# windows form & google api v3 Pin
loyal ginger3-May-12 16:51
Memberloyal ginger3-May-12 16:51 
GeneralRe: c# windows form & google api v3 Pin
mrx1004-May-12 2:32
Membermrx1004-May-12 2:32 
GeneralRe: c# windows form & google api v3 Pin
loyal ginger4-May-12 3:32
Memberloyal ginger4-May-12 3:32 
GeneralRe: c# windows form & google api v3 Pin
mrx1007-May-12 2:50
Membermrx1007-May-12 2:50 
QuestionNeed help in writing code on establish a PPTP (VPN Tunnel) connection in c#. Pin
kalyan_vb2-May-12 1:14
Memberkalyan_vb2-May-12 1:14 
AnswerRe: Need help in writing code on establish a PPTP (VPN Tunnel) connection in c#. Pin
Richard MacCutchan2-May-12 3:41
mveRichard MacCutchan2-May-12 3:41 
QuestionRequesting for a snippet that can be used in LINQ to SQL query Pin
Nadia Monalisa1-May-12 21:48
MemberNadia Monalisa1-May-12 21:48 
AnswerRe: Requesting for a snippet that can be used in LINQ to SQL query Pin
Keith Barrow2-May-12 3:23
professionalKeith Barrow2-May-12 3:23 
GeneralRe: Requesting for a snippet that can be used in LINQ to SQL query Pin
Nadia Monalisa2-May-12 5:32
MemberNadia Monalisa2-May-12 5:32 
QuestionSIFT Pin
ri19871-May-12 21:05
Memberri19871-May-12 21:05 
AnswerRe: SIFT Pin
AmbiguousName1-May-12 21:09
MemberAmbiguousName1-May-12 21:09 
AnswerRe: SIFT Pin
egenis1-May-12 21:09
Memberegenis1-May-12 21:09 
AnswerRe: SIFT Pin
Abhinav S1-May-12 21:27
MemberAbhinav S1-May-12 21:27 
GeneralRe: SIFT Pin
ri19871-May-12 22:48
Memberri19871-May-12 22:48 
GeneralRe: SIFT Pin
ri19872-May-12 22:13
Memberri19872-May-12 22:13 
GeneralRe: SIFT Pin
ri19872-May-12 22:16
Memberri19872-May-12 22:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.