Click here to Skip to main content
15,879,239 members
Home / Discussions / C#
   

C#

 
AnswerRe: can't found provider sqlserver Pin
Wes Aday2-May-12 1:45
professionalWes Aday2-May-12 1:45 
GeneralRe: can't found provider sqlserver Pin
MemberDotNetting2-May-12 2:06
MemberDotNetting2-May-12 2:06 
AnswerRe: can't found provider sqlserver Pin
egenis2-May-12 2:03
egenis2-May-12 2:03 
Questionc# windows form & google api v3 Pin
mrx1002-May-12 0:39
mrx1002-May-12 0:39 
AnswerRe: c# windows form & google api v3 Pin
Richard MacCutchan2-May-12 2:42
mveRichard MacCutchan2-May-12 2:42 
GeneralRe: c# windows form & google api v3 Pin
mrx1002-May-12 4:38
mrx1002-May-12 4:38 
GeneralRe: c# windows form & google api v3 Pin
mrx1002-May-12 4:49
mrx1002-May-12 4:49 
AnswerRe: c# windows form & google api v3 Pin
loyal ginger2-May-12 9:21
loyal ginger2-May-12 9: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 7:39
mrx1003-May-12 7:39 
GeneralRe: c# windows form & google api v3 Pin
loyal ginger3-May-12 15:51
loyal ginger3-May-12 15:51 
GeneralRe: c# windows form & google api v3 Pin
mrx1004-May-12 1:32
mrx1004-May-12 1:32 
GeneralRe: c# windows form & google api v3 Pin
loyal ginger4-May-12 2:32
loyal ginger4-May-12 2:32 
GeneralRe: c# windows form & google api v3 Pin
mrx1007-May-12 1:50
mrx1007-May-12 1:50 
QuestionNeed help in writing code on establish a PPTP (VPN Tunnel) connection in c#. Pin
kalyan_vb2-May-12 0:14
kalyan_vb2-May-12 0:14 
AnswerRe: Need help in writing code on establish a PPTP (VPN Tunnel) connection in c#. Pin
Richard MacCutchan2-May-12 2:41
mveRichard MacCutchan2-May-12 2:41 
QuestionRequesting for a snippet that can be used in LINQ to SQL query Pin
Nadia Monalisa1-May-12 20:48
Nadia Monalisa1-May-12 20:48 
AnswerRe: Requesting for a snippet that can be used in LINQ to SQL query Pin
Keith Barrow2-May-12 2:23
professionalKeith Barrow2-May-12 2:23 
GeneralRe: Requesting for a snippet that can be used in LINQ to SQL query Pin
Nadia Monalisa2-May-12 4:32
Nadia Monalisa2-May-12 4:32 
QuestionSIFT Pin
ri19871-May-12 20:05
ri19871-May-12 20:05 
AnswerRe: SIFT Pin
AmbiguousName1-May-12 20:09
AmbiguousName1-May-12 20:09 
AnswerRe: SIFT Pin
egenis1-May-12 20:09
egenis1-May-12 20:09 
AnswerRe: SIFT Pin
Abhinav S1-May-12 20:27
Abhinav S1-May-12 20:27 
GeneralRe: SIFT Pin
ri19871-May-12 21:48
ri19871-May-12 21:48 
GeneralRe: SIFT Pin
ri19872-May-12 21:13
ri19872-May-12 21:13 
GeneralRe: SIFT Pin
ri19872-May-12 21:16
ri19872-May-12 21: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.