Vs. Net C # Call the active component

Source: Internet
Author: User
In coding, it is undeniable that calling active will bring great convenience to programming, although Microsoft does not only require. Net to call active components.
This example is an example of calling the active component on a simple web page. Data is transmitted and displayed in the control of the active component.
The instance code is as follows:
1. Create an active component (. net c # is used here)
(In this program: Create a class library, add component classes, and place the following labels, buttons, and groupbox)
Note that. before using the DLL, you must install the SDK in assemblyinfo of the class library. add using system to CS. security; and the attribute [Assembly: allowpartiallytrustedcallers ()] to give the control sufficient permissions for display on the page.

Using system;
Using system. componentmodel;
Using system. collections;
Using system. diagnostics;
Using system. Windows. forms;

Namespace activexdotnet
{
/** // <Summary>
/// Abstract description of 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)
{
/**////
/// Required by the windows. Forms Class Writer designer
///
This. label1.text = "test ";
Container. Add (this );
Initializecomponent ();

//
// Todo: add Any constructor code after initializecomponent calls
//
}

Public abeencontrol ()
{
/**////
/// Required by the windows. Forms Class Writer designer
///
Initializecomponent ();


//
// Todo: add Any constructor code after initializecomponent calls
//
}

/** // <Summary>
/// Clear all resources in use.
/// </Summary>
Protected override void dispose (bool disposing)
{
If (disposing)
{
If (components! = NULL)
{
Components. Dispose ();
}
}
Base. Dispose (disposing );
}


Code generated by the component designer # code generated by the region component designer
/** // <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content 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. button#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 button#click (Object sender, system. eventargs E)
{
This. label1.text = "click Finish! ";
}

Private void abeencontrol_load (Object sender, system. eventargs E)
{

}
}
}
2. Call the active component on the web page
Note that when calling a Web page, you need to put active. dll under the WEB 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 # activexdotnet. abeencontrol"
Width = "288" Height = "72" viewastext>
</Object>
</Font>
<Form ID = "frm" name = "frm">
<Input type = "text" name = "TXT" value = "Enter data:" id = "text1">
<Input type = "button" value = "OK" onclick = "doscript ();" 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.