转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 站长学院 >> Web开发 >> 正文
Using Windows Forms Controls in Internet Explorer         ★★★★

Using Windows Forms Controls in Internet Explorer

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1028 更新时间:2009/4/23 10:51:28

Using Windows Forms Controls in Internet Explorer

This document describes how to successfully execute Windows Forms controls within Internet Explorer (IE). Windows Forms controls within IE are activated without user prompt, require no registration and utilize the Common Language Runtime (CLR) code access security.

There are four steps in getting the Windows Forms control activated within Internet Explorer, each listed here and detailed below.

  • Configure Code Access Permissions
  • Create the Windows Forms control
  • Create an HTML document with an object tag
  • Create the virtual directory, copy content and set permissions
  • Run the control

1. Windows Forms Control : SimpleControl.dll

Almost any Windows Forms control could be, but for this example the SimpleControl that is included in the .NET Framework SDK QuickStart Tutorial Creating Controls will be used.

2. HTML Document : SimpleControl.html

The next step is to create an HTML document with and object tag to insert and activate the Windows Forms control. Some simple script and input tags will also be added to demonstrate programmatic access to the control.

Object tag
<object id="simpleControl1"
    classid="http:SimpleControl.dll#Microsoft.Samples.WinForms.Cs.SimpleControl.SimpleControl"
    height="300"
    width="300">
    <param name="Text" value="Simple Control">
</object>

The classid has two interesting parts; the path to the control library and the fully qualified name of the control separated by the pound sign. If you are familiar with an ActiveX object tag, youll notice the lack of a GUID. In the case of Windows Forms, the combination of path and fully qualified classname serve as the unique identifier.

Param tags are used to set properties on controls. The name attribute is the name of the property and the value attribute is the value of the property.

Script
<script>

function ChangeText() {
      simpleControl1.Text = text1.value;
}

</script>


<input type="text" id="text1"> <input type="button" value="Change Text" onclick="ChangeText()">

To gain programmatic access to your control, you can write script against it. A button and text box on the page is used in conjunction with the simple function ChangeText to set the text property of the control.

Complete

The following is the complete HTML code for this example.

<html>

<script>

function ChangeText() {
	simpleControl1.Text = text1.value;
}

</script>

<body>

    <p>Simple Control</p>
    <br>
    <br>
    
    <object id="simpleControl1"
        classid="http:SimpleControl.dll#Microsoft.Samples.WinForms.Cs.SimpleControl.SimpleControl"
        height="300"
        width="300">
        <param name="Text" value="Simple Control">
    </object>
    
    <br>
    <br>
    
    <input type="text" id="text1">
    <input type="button" value="Change Text" onclick="ChangeText()">

</body>

</html>

3. Virtual Directory

Create a new virtual directory and populate it with both the control (SimpleControl.dll) and the HTML document (SimpleControl.html).

Important: Set execution permissions on the virtual directory to scripts. The control will not be properly activated if the execution permissions are set to scripts & executables.

4. Configure Code Access Permissions

This sample will execute correctly if you are running the control from an intranet site and you have not altered the .Net Framework security policy. If you have altered policy, or if you are running the control from an internet site then you may need to configure Internet Explorer or alter security policy to allow it to run. One way to enable a specific site for control download and execution is to identify your hosting page as belonging to the Trusted zone. This change is done in Internet Explorer with the following steps.

1. Choose Tools|Options
2. Select the "Security" tab
3. Select the "Trusted Sites" icon
4. Click the Sites... button
5. Add your site using the dialog presented
6. Click OK to commit your changes

Now, when you browse to that page, it should be in the Trusted Sites zone which has the Internet permission set by default.

You can also configure the .net framework security policy to enable code to run from a particular web site or from the Internet. The SDK documentation contains details of how to configure security policy.

5. Run the Control

To run the control, just point Internet Explorer to SimpleControl.html in your virtual directory. If the control is not activating correctly it may be necessary to restart Internet Explorer or clear the assembly download cache.

Note:You can view the contents of your assembly download cache using gacutil /ldl on the command line. You can clear the contents of the cache using gacutil /cdl


[系统软件]windows下Apache+php+mysql的安装与配置图解  [操作系统]在Windows中玩转Linux操作系统
[操作系统]死马还当活马医:6种方法挽救Windows系统  [聊天工具]四大更新 Windows Live Msn 8.1评测
[聊天工具]Windows Live Messenger最新0683版亮相_联络工具_…  [聊天工具]Windows Live Mail招人爱的N个理由_联络工具_Wind…
[聊天工具]Windows Live Mail Desktop多图欣赏_联络工具_Win…  [聊天工具]OE老了 微软开发新邮件客户端取而代之_联络工具
[聊天工具]Windows Live Messenger中文版试用报告(一)__天极…  [聊天工具]Windows Live Messenger 8 Beta1高清图赏__天极Ye…
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Web开发  · 网页制作
    · 平面设计  · 网站运营
    · 网站推广  · 搜索优化
    · 建站心得  · 站长故事
    · 互联动态
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台