VS.Net C# 调用 Active 组件

http://tech.ddvip.com   2008年09月08日    社区交流

本文详细介绍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()],这是为了给控件赋予足够的权限使它能在页面上显示。

 using System;
 using System.ComponentModel;
 using System.Collections;
 using System.Diagnostics;
 using System.Windows.Forms ;
 
 namespace ActiveXDotNet
 {
  /**//// <summary>
  /// 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>
  /// 必需的设计器变量。
  /// </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 类撰写设计器支持所必需的
  ///
  this.label1.Text="test";
  container.Add(this);
  InitializeComponent();
 
  //
  // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  //
  }
 
  public AbeenControl()
  {
  /**////
  /// Windows.Forms 类撰写设计器支持所必需的
  ///
  InitializeComponent();
 
 
  //
  // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  //
  }
 
  /**//// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
  if( disposing )
  {
  if(components != null)
  {
  components.Dispose();
  }
  }
  base.Dispose( disposing );
  }

责编:豆豆技术应用

正在加载评论...