是否可以托管和运行高级 JavaScript,例如 this ,直接在 WinForms 应用程序上?说得非常清楚,当我直接说时,我的意思是我不能使用网络服务器来托管内容,然后通过 URL 进行引用。我需要能够直接在表单上实现所有必需的功能。
最佳答案
您可以使用嵌入的 html 文件并将其加载到浏览器控件中吗?
示例 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。其特点是:
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;
}
这将产生一个警告框和“测试”一词!在 Windows 窗体上。
关于c# - Winforms 托管 Javascript 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8299330/