Microsoft WebBrowser control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill Cousert

    #1

    Microsoft WebBrowser control

    I have a Windows Form that uses the Microsoft WebBrowser control. If I load
    an HTML file into the control that contains Jscript code, can the Jscript
    code call a C# function in my Windows Form?


    --


    -Bill Cousert
    wrcousert@yahoo .com

    moderator of http://groups.yahoo.com/group/c-sharp-programming


  • Peter Torr \(MS\)

    #2
    Re: Microsoft WebBrowser control

    "Bill Cousert" <wrcousert@yaho o.com> wrote in message
    news:eupr1Y$QDH A.1564@TK2MSFTN GP12.phx.gbl...[color=blue]
    > I have a Windows Form that uses the Microsoft WebBrowser control. If I[/color]
    load[color=blue]
    > an HTML file into the control that contains Jscript code, can the Jscript
    > code call a C# function in my Windows Form?[/color]

    Hi Bill,

    Try adding your C# object as the "window.externa l" object. Then JScript
    should be able to manipulate it.

    Peter

    --
    Please post questions to the newsgroup - everyone benefits.
    This post is provided "AS IS" with no warranties, and confers no rights
    Sample code subject to http://www.microsoft.com/info/cpyright.htm


    Comment

    • Bill Cousert

      #3
      Re: Microsoft WebBrowser control


      "Peter Torr (MS)" <ptorr@microsof t.com> wrote in message
      news:uxiQUpBRDH A.2316@TK2MSFTN GP12.phx.gbl...[color=blue]
      > "Bill Cousert" <wrcousert@yaho o.com> wrote in message
      > news:eupr1Y$QDH A.1564@TK2MSFTN GP12.phx.gbl...[color=green]
      > > I have a Windows Form that uses the Microsoft WebBrowser control. If I[/color]
      > load[color=green]
      > > an HTML file into the control that contains Jscript code, can the[/color][/color]
      Jscript[color=blue][color=green]
      > > code call a C# function in my Windows Form?[/color]
      >
      > Hi Bill,
      >
      > Try adding your C# object as the "window.externa l" object. Then JScript
      > should be able to manipulate it.[/color]

      Hi Peter,

      Would I do this by adding a reference? Assume my function is named test. How
      would I call it from JScript?


      Thanks,

      -Bill Cousert
      wrcousert@yahoo .com

      [color=blue]
      >
      > Peter
      >
      > --
      > Please post questions to the newsgroup - everyone benefits.
      > This post is provided "AS IS" with no warranties, and confers no rights
      > Sample code subject to http://www.microsoft.com/info/cpyright.htm
      >
      >[/color]


      Comment

      • Peter Torr \(MS\)

        #4
        Re: Microsoft WebBrowser control

        "Bill Cousert" <wrcousert@yaho o.com> wrote in message
        news:u5stKvORDH A.2148@TK2MSFTN GP10.phx.gbl...[color=blue]
        > Hi Peter,
        >
        > Would I do this by adding a reference? Assume my function is named test.[/color]
        How[color=blue]
        > would I call it from JScript?[/color]

        Actually, I'm not sure how easy it will be to use the external object in C#
        with WinForms. Looking at:

        http://msdn.microsoft.com/workshop/b...w/overview.asp

        it seems you have to do work in an DocUIHost interface which (presumably)
        WinForms implements for you. Maybe you can figure out a way around that.

        Anyway, the next best option is to call into IE to get a handle on the
        script block, then use Reflection to invoke a member on the script that will
        accept a callback object (your C# object) for later use. Kind of messy, but
        it should work.

        Peter

        --
        Please post questions to the newsgroup - everyone benefits.
        This post is provided "AS IS" with no warranties, and confers no rights
        Sample code subject to http://www.microsoft.com/info/cpyright.htm


        Comment

        • Bill Cousert

          #5
          Re: Microsoft WebBrowser control


          "Peter Torr (MS)" <ptorr@microsof t.com> wrote in message
          news:uaEOR1aRDH A.1924@TK2MSFTN GP12.phx.gbl...[color=blue]
          > "Bill Cousert" <wrcousert@yaho o.com> wrote in message
          > news:u5stKvORDH A.2148@TK2MSFTN GP10.phx.gbl...[color=green]
          > > Hi Peter,
          > >
          > > Would I do this by adding a reference? Assume my function is named test.[/color]
          > How[color=green]
          > > would I call it from JScript?[/color]
          >
          > Actually, I'm not sure how easy it will be to use the external object in[/color]
          C#[color=blue]
          > with WinForms. Looking at:
          >
          > http://msdn.microsoft.com/workshop/b...w/overview.asp
          >
          > it seems you have to do work in an DocUIHost interface which (presumably)
          > WinForms implements for you. Maybe you can figure out a way around that.
          >
          > Anyway, the next best option is to call into IE to get a handle on the
          > script block, then use Reflection to invoke a member on the script that[/color]
          will[color=blue]
          > accept a callback object (your C# object) for later use. Kind of messy,[/color]
          but[color=blue]
          > it should work.
          >
          > Peter
          >[/color]
          Thank you! I see I have my work cut out for me. I will post the results when
          I figure this out.



          Comment

          Working...