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.
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.
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 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> function ChangeText() { simpleControl1.Text = text1.value; } </script> |
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.
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> |
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.
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
本文地址:http://com.8s8s.com/it/it44269.htm