Vs.net C # calls an Active component

Source: Internet
Author: User
Tags constructor visual studio
Active

The undeniable invocation of active in code can be very handy for programming, although Microsoft does not only call active components with. Net.
This example is an example of a simple Web page calling an active component that implements the data to be passed into and displayed in a control in an active component.
The instance code is as follows:
1. Establish an active component (created here with. NET C #)
(In this procedure: Set up Class Library add component class after put: Label, Button, GroupBox one)
It is important to note that you must add a reference using System.Security to the AssemblyInfo.cs of the class library before building the. dll, and properties [Assembly:allowpartiallytrustedcallers ()]. This is to give the control sufficient permissions to display it on the page.

Using System;
Using System.ComponentModel;
Using System.Collections;
Using System.Diagnostics;
Using System.Windows.Forms;

Namespace Activexdotnet
{
   /**////<summary>
   /// Summary description of the Abeencontrol.
   ///</summary>
    public class Abeencontrol: System.Windows.Forms.UserControl
    {
        private System.Windows.Forms.Label Label1;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.GroupBox groupBox1;
       /**////<summary>
        ///required designer variables.
       ///</summary>
         Private System.ComponentModel.Container components = null;

        public string LabelText
         {
            get
             {
                 return this.label1.Text.ToString ();
           }
            Set
             {
                 This.label1.text=value;
           }
       }

        public Abeencontrol (System.ComponentModel.IContainer container)
        {
            /**////
           ///windows.forms
           ///
    required for class authoring designer support          this.label1.text= "Test";
            container. ADD (this);
            InitializeComponent ();

//
TODO: Add any constructor code after the InitializeComponent call
//
}

Public Abeencontrol ()
{
/**////
Windows.Forms class is required to compose designer support
///
InitializeComponent ();

//
TODO: Add any constructor code after the InitializeComponent call
//
}

/**////<summary>
Clean up all resources that are in use.
</summary>
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (Components!= null)
{
Components. Dispose ();
}
}
Base. Dispose (disposing);
}


Component Designer generated Code #region Component Designer generated code
/**////<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
This.label1 = new System.Windows.Forms.Label ();
This.button1 = new System.Windows.Forms.Button ();
This.groupbox1 = new System.Windows.Forms.GroupBox ();
This.groupBox1.SuspendLayout ();
This. SuspendLayout ();
//
Label1
//
This.label1.Location = new System.Drawing.Point (16, 24);
This.label1.Name = "Label1";
This.label1.Size = new System.Drawing.Size (296, 23);
This.label1.TabIndex = 0;
This.label1.Text = "Label1";
//
Button1
//
This.button1.Location = new System.Drawing.Point (120, 56);
This.button1.Name = "Button1";
This.button1.TabIndex = 1;
This.button1.Text = "Button1";
This.button1.Click + = new System.EventHandler (This.button1_click);
//
GroupBox1
//
THIS.GROUPBOX1.CONTROLS.ADD (THIS.LABEL1);
THIS.GROUPBOX1.CONTROLS.ADD (This.button1);
This.groupBox1.Location = new System.Drawing.Point (0, 0);
This.groupBox1.Name = "GroupBox1";
This.groupBox1.Size = new System.Drawing.Size (320, 88);
This.groupBox1.TabIndex = 2;
This.groupBox1.TabStop = false;
This.groupBox1.Text = "GroupBox1";
//
Abeencontrol
//
This. Controls.Add (This.groupbox1);
This. Name = "Abeencontrol";
This. Size = new System.Drawing.Size (328, 96);
This. Load + = new System.EventHandler (this. Abeencontrol_load);
This.groupBox1.ResumeLayout (FALSE);
This. ResumeLayout (FALSE);

}
#endregion

private void Button1_Click (object sender, System.EventArgs e)
{
this.label1.text= "Click Finish!" ";
}

private void Abeencontrol_load (object sender, System.EventArgs e)
{

}
}
}
2, the Web page calls the active component
Note Web page calls need to place active. dll in the Web's virtual directory.
<HTML>
<HEAD>
<title>TestActive</title>
<meta name= "generator" content= "Microsoft Visual Studio. NET 7.1" >
<meta name= "Code_language" content= "C #" >
<meta name= "vs_defaultClientScript" content= "JavaScript" >
<meta name= "vs_targetschema" content= "http://schemas.microsoft.com/intellisense/ie5" >
</HEAD>
<body >
<font face= "Arial" size= "1" >
<object id= "MyControl1" name= "MyControl1" classid= "Http://localhost/WebApplication1/ActiveXDotNet.dll"
Width= "height=" viewastext>
</OBJECT>
</font>
<form id= "frm" name= "frm" >
<input type= "text" name= "TXT" value= "Please enter data:" id= "Text1" >
<input type= "button" value= "OK" id= "Button1" name= "Button1" >
<script type= "Text/javascript" >
function Doscript ()
{
Mycontrol1.labeltext=frm.txt.value;
}

</script>
</form>
</body>
</HTML>



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.