Using Windows Forms controls in IE browser (i)

Source: Internet
Author: User
Tags contains html page unique id client
window| Control | Browser uses Windows Forms control in IE browser (i)

Author:: Thiru Thangarathinam

Translation: Autumn Maple

Introduction

In the past, web programmers often used ActiveX controls in their Web programs to implement features that some fat clients have. But now developers can easily through the Microsoft.NET framework to create the simple and secure objects, and easy to use in IE browser. By creating Windows Forms controls in IE browsers, developers can implement rich Web clients. In this article, we'll know how to create a Windows Forms control and use it in IE. In the process of using form controls in a browser, we demonstrate how to provide a rich Web client display through a form control, which is used to invoke a remote Web service to fetch data. At the same time, we will know how to use it. NET security model to provide a secure running environment for our form controls.

If you have the experience of using Java to develop Web programs, you will be familiar with Java applets. It is a small program that runs in a browser. The Java applets runs when the browser opens an HTML document that contains an applet tag. Windows Forms work in a Web page in a way that is similar to the Java applets. In this implementation, you create a form control and add a rich Windows Form control style to it, which is then cut into a Web page. When the browser loads the Web page, the code that the Windows control contains is also executed. This will be useful in a LAN or Extended network program. For example, you want to develop a base and Web program with a rich client feature used by an enterprise.

. NET is an important feature is the close integration with IE. For example, we can use Windows Forms controls in IE without notifying users that they need to add something else. This does not need to register what the. NET CLR provides the ability to access code securely.

When you create a Windows Forms control, you will have the features provided by the form class hierarchy. For example, you can use Windows Forms control validation techniques to verify the accuracy of the input data. In the same way, you can even invoke Web Service in your form control. Using these techniques, you can create a base with. NET platform's rich, robust, dynamic applications.



Remark: Rewrite the code according to the original text, replace the picture with the Chinese, the operating environment: OS windows2003,.net Framework 1.1. Here are a few points: open the browser to enter the full address during debugging. If you open it as a file, the form control will not appear, and for process debugging, it can be a single source file. However, I am running the components generated under the debug version, not release, interested readers can try.



Perform

In this section, we will understand how to create Windows Forms controls and use them in IE. The following five steps are listed to complete this process.

1. To create a Windows Forms control

2. Creates an HTML document with an object label that identifies the Windows control

3. Configure the control's virtual path

4. Set Code access permissions

5. Running controls

Let's take a look at each of the steps above.

1. Create a Windows Forms control

In this step, we create a simple Windows Forms control. The function of the control implementation is to display "Hello World" to the user. Let's start by building a Windows Control Library project named Helloworldcontrol, modifying the default user control to Helloworldctl. Then add a label to the control, named Lbldisplaymessage, and add a button btnclick. When the user clicks the button, the following code is executed to display the message to the user.

private void Btnclick_click (object sender, System.EventArgs e)

{

This.lblDisplayMessage.Text = "Hello World";

}

The next thing is to compile him to generate a assembly.


2. Create an HTML page

In this step, we will create an HTML document and insert an OBJECT tag inside it. The entire document looks as follows:

<body>
<p>hello World Control
<object id= "HelloWorldControl1" height= "width=" "classid=" http:helloworldcontrol.dll# Helloworldcontrol.helloworldctl "
Viewastext>
</OBJECT>
<br>
</p>
</body>

In the ClassID attribute of this tag, we specify the path to the component that was created in the first step and the fully qualified name of the component. The entire full name includes the namespace and the entire class name. We can clearly see in the code above the component name and qualified name with the # split. These two-part parameters are grouped together to identify the uniqueness of the control. Of course, you can write client script by naming a unique ID for HelloWorldControl1.

3. Configuring virtual Paths

With the HTML page, now to build a helloworldcontrolhost virtual directory, the actual directory in D:\My Programs\hellpworldhost, This directory contains the HelloWorldControl.dll and hellpworld.htm files. When setting up a virtual directory, it is necessary to be aware that the set execution permission is "pure script." If set to "script and Execute Script" permissions. The control may not work properly (I am set to "script and Executable script" under IIS6, not normal). You can open the properties of the virtual directory to confirm the settings, set the window as follows:


4. Set Code access permissions

If the web is accessed on a local area network, he will work properly. If the web is accessed over the Internet, you need to set up Internet Explorer and modify the security properties to allow it to run. You can add the homepage to a trusted site. If you need to set the ―>internet option-> secure-> trusted site via IE's Tools menu, click on the Site button above to add your site. Next, when you open the browser to view, you will see the correct execution.

5. Running controls

To run this control, we view the HTML page that contains the control in the browser. If you click on the button on the page, the control will display "HELLP World" information, the execution page is as follows:



In this example, we implemented how to create a Windows Forms control and then display it in IE browser. In the next section, we implement access to Web Service through a form control on the client browser.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.