Winforms 托管 Javascript 内容 [英] Winforms Host Javascript Content
问题描述
是否可以托管和运行高级 javascript,例如 this,直接在 WinForms 应用程序上?明确地说,当我直接说时,我的意思是我不能使用网络服务器来托管内容,然后通过 URL 引用.我需要能够直接在表单上完成所有必需的功能.
Is it possible to host and run advanced javascript, such as this, directly on a WinForms application? To be ultra-clear, when I say, directly, I mean that I cannot use a web sever to host the content and then reference by URL. I need to be able to fulfil all the required functionality directly on the form.
推荐答案
您能否使用嵌入的 html 文件并将其加载到浏览器控件中?
Can you use an embeded html file and load that into a browser control?
示例 HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>
</title>
<script type="text/javascript">
alert("hello");
</script>
</head>
<body>
TESTING!
</body>
</html>
我将此文件命名为 alertTest.html.它的属性是:
I named this file alertTest.html. It's properties are:
Build Action: Content
Copy to Output Directory: Copy always
FileName: alertTest.html
然后是C#形式:
public Form1()
{
InitializeComponent();
StreamReader reader = new StreamReader("alertTest.html");
string html = reader.ReadToEnd();
this.webBrowser1.DocumentText = html;
}
这将产生一个警告框和单词 TESTING!在窗体上.
this will produce an alert box and the word TESTING! on the windows form.
这篇关于Winforms 托管 Javascript 内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!