![](/img/trans.png)
[英]ActiveX - hosting windows form control on web page using Windows 8
[英]Using windows control in web form
我們已經制作了一個簡單的Windows控件,希望以Web形式使用它,但是我們無法做到這一點。 我們剛剛在互聯網上找到了這個解決方案,但是這個解決方案沒有提供任何輸出
Windows控制程式碼
<pre lang="cs">namespace WinformUsrCntl
{
[ComVisible(true)]
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public void setText(string text)
{
label1.Text = text;
}
}
}</pre>
以網絡形式實施:-
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Defualt</title>
<script type="text/javascript">
function SendMessageToWinControl() {
var winCtrl = document.getElementById("myName");
winCtrl.innerHTMl("Message sent from the HTML page!!");
}
</script>
<style type="text/css">
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>
Windows Form Control:</h1>
<input type="button" onclick="SendMessageToWinControl()" value="Send Message" />
<br/>
<object id="myName" width="100px" classid="http:WinformUsrCntl.dll#WinformUsrCntl.UserControl1"
VIEWASTEXT />
</div>
</form>
</body>
</html>
創建自定義Web服務器控件並在其中包裝Windows控件會更有意義嗎? 然后,您可以公開所有想要的屬性和行為,並在ASP.NET上正常使用它。
有關自定義控件的更多信息,請參見:
http://msdn.microsoft.com/zh-CN/library/zt27tfhy(v=vs.100).aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.