Call winform function from html page?

主宰稳场 提交于 2019-12-11 18:07:40

问题


I have a winform application that contains a c# webbrowser control.Webbrower control load a html page. On that html page I have a button. What I want is when click that button, it will call a winform function(function in Form1.cs for example). Is it possible? Please help me


回答1:


Use window.external object in your scripting code to access public properties and methods of the specified object. (See the sample in the link)

C#

public void Test(String message)
{
    MessageBox.Show(message, "client code");
}

HTML

<button onclick="window.external.Test('called from script code')">
    call client code from script code
</button>


来源:https://stackoverflow.com/questions/11331146/call-winform-function-from-html-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!