VS.Net C# 调用 Active 组件

  在编码中不可否认调用Active会给编程带来很大便利,虽然微软不太只持.net调用Active 组件。
       本实例是一个简单Web 页面调用Active组件的例子,实现把数据传入并显示在active组件里的控件中。
  实例代码如下:
1、建立Active组件(这里用.net c#创建)
        (本程序中:建立类库添加组件类后托放:label 、 button  、groupBox各一个)
   需要注意的是在生成.dll之前一定要在类库的AssemblyInfo.cs中加入引用using System.Security;和属性[assembly : AllowPartiallyTrustedCallers()],这是为了给控件赋予足够的权限使它能在页面上显示。

None.gif using  System;
None.gif
using  System.ComponentModel;
None.gif
using  System.Collections;
None.gif
using  System.Diagnostics;
None.gif
using  System.Windows.Forms ;
None.gif
None.gif
namespace  ActiveXDotNet
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// AbeenControl 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class AbeenControl : System.Windows.Forms.UserControl
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private System.Windows.Forms.Label label1;
InBlock.gif        
private System.Windows.Forms.Button button1;
InBlock.gif        
private System.Windows.Forms.GroupBox groupBox1;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 必需的设计器变量。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private System.ComponentModel.Container components = null;
InBlock.gif
InBlock.gif        
public string LabelText
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return this.label1.Text.ToString();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.label1.Text=value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public AbeenControl(System.ComponentModel.IContainer container)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**////
InBlock.gif            
/// Windows.Forms 类撰写设计器支持所必需的
ExpandedSubBlockEnd.gif            
///

InBlock.gif            this.label1.Text="test";
InBlock.gif            container.Add(
this);
InBlock.gif            InitializeComponent();
InBlock.gif
InBlock.gif            
//
InBlock.gif            
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
InBlock.gif            
//
ExpandedSubBlockEnd.gif
        }

InBlock.gif
InBlock.gif        
public AbeenControl()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**////
InBlock.gif            
/// Windows.Forms 类撰写设计器支持所必需的
ExpandedSubBlockEnd.gif            
///

InBlock.gif            InitializeComponent();
InBlock.gif            
InBlock.gif
InBlock.gif            
//
InBlock.gif            
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
InBlock.gif            
//
ExpandedSubBlockEnd.gif
        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 
InBlock.gif        
/// 清理所有正在使用的资源。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        protected override void Dispose( bool disposing )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if( disposing )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(components != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    components.Dispose();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
base.Dispose( disposing );
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
组件设计器生成的代码#region 组件设计器生成的代码
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif        
/// 此方法的内容。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.label1 = new System.Windows.Forms.Label();
InBlock.gif            
this.button1 = new System.Windows.Forms.Button();
InBlock.gif            
this.groupBox1 = new System.Windows.Forms.GroupBox();
InBlock.gif            
this.groupBox1.SuspendLayout();
InBlock.gif            
this.SuspendLayout();
InBlock.gif            
// 
InBlock.gif            
// label1
InBlock.gif            
// 
InBlock.gif
            this.label1.Location = new System.Drawing.Point(1624);
InBlock.gif            
this.label1.Name = "label1";
InBlock.gif            
this.label1.Size = new System.Drawing.Size(29623);
InBlock.gif            
this.label1.TabIndex = 0;
InBlock.gif            
this.label1.Text = "label1";
InBlock.gif            
// 
InBlock.gif            
// button1
InBlock.gif            
// 
InBlock.gif
            this.button1.Location = new System.Drawing.Point(12056);
InBlock.gif            
this.button1.Name = "button1";
InBlock.gif            
this.button1.TabIndex = 1;
InBlock.gif            
this.button1.Text = "button1";
InBlock.gif            
this.button1.Click += new System.EventHandler(this.button1_Click);
InBlock.gif            
// 
InBlock.gif            
// groupBox1
InBlock.gif            
// 
InBlock.gif
            this.groupBox1.Controls.Add(this.label1);
InBlock.gif            
this.groupBox1.Controls.Add(this.button1);
InBlock.gif            
this.groupBox1.Location = new System.Drawing.Point(00);
InBlock.gif            
this.groupBox1.Name = "groupBox1";
InBlock.gif            
this.groupBox1.Size = new System.Drawing.Size(32088);
InBlock.gif            
this.groupBox1.TabIndex = 2;
InBlock.gif            
this.groupBox1.TabStop = false;
InBlock.gif            
this.groupBox1.Text = "groupBox1";
InBlock.gif            
// 
InBlock.gif            
// AbeenControl
InBlock.gif            
// 
InBlock.gif
            this.Controls.Add(this.groupBox1);
InBlock.gif            
this.Name = "AbeenControl";
InBlock.gif            
this.Size = new System.Drawing.Size(32896);
InBlock.gif            
this.Load += new System.EventHandler(this.AbeenControl_Load);
InBlock.gif            
this.groupBox1.ResumeLayout(false);
InBlock.gif            
this.ResumeLayout(false);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
private void button1_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.label1.Text="点击完成!";
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void AbeenControl_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif        
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
2、web 页面调用Active组件
   注意web页面调用时需要把Active的.dll放到web的虚拟要目录下。
None.gif < HTML >
None.gif    
< HEAD >
None.gif        
< title > TestActive </ title >
None.gif        
< meta  name ="GENERATOR"  Content ="Microsoft Visual Studio .NET 7.1" >
None.gif        
< meta  name ="CODE_LANGUAGE"  Content ="C#" >
None.gif        
< meta  name ="vs_defaultClientScript"  content ="JavaScript" >
None.gif        
< meta  name ="vs_targetSchema"  content ="http://schemas.microsoft.com/intellisense/ie5" >
None.gif    
</ HEAD >
None.gif    
< body  >
None.gif        
< font  face ="arial"  size ="1" >
None.gif            
< OBJECT  id ="MyControl1"  name ="MyControl1"  classid ="http://localhost/WebApplication1/ActiveXDotNet.dll#ActiveXDotNet.AbeenControl"
None.gif                width
="288"  height ="72"  VIEWASTEXT >
None.gif            
</ OBJECT >
None.gif        
</ font >
None.gif        
< form  id ="frm"  name ="frm" >
None.gif            
< input  type ="text"  name ="txt"  value ="请输入数据:"  ID ="Text1" >
None.gif            
< input  type ="button"  value ="确定"  onclick ="doScript();"  ID ="Button1"  NAME ="Button1" >
ExpandedBlockStart.gifContractedBlock.gif            
< script  type ="text/javascript" > dot.gif
InBlock.gif            
function doScript()
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                 MyControl1.LabelText
=frm.txt.value;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
ExpandedBlockEnd.gif            
</ script >
None.gif        
</ form >
None.gif    
</ body >
None.gif
</ HTML >
None.gif

转载于:https://www.cnblogs.com/abeen/archive/2006/12/13/590764.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值