网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > C#应用
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.C#中Windows通用的回车转Tab方法.
.C#中的非安全编程.
.利用c#制作简单的留言板(4) .
.用Visual C#来增加数据记录(1).
.在C#中使用热键隐含窗口.
.同步http处理程序(IHttpHandler) .
.浅析.NET开发中代理模式的使用.
.用C#开发网络防火墙技术分析.
.C# 操作文件.
.c#关闭系统进程以及如何调用cmd并.
.Visual C#的SQL Server编程.
.在C#中把两个DataTable连接起来,.
.如何把html中的相对路径变成绝对.
.c#数据库操作的3种典型用法.
.c# MD5加密算法的一个实例.
.在C#.net中将查询数据导入EXCEL表.
.用C#开发.NET CF 蓝牙通信模块.
.在C#中利用DirectX实现声音播放.
.Web Service的几个很重要的概念 .
.一个产生中文累计数的代码片断.

VS.Net C# 调用 Active 组件

发表日期:2006-12-14


  在编码中不可否认调用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 );
        }


        组件设计器生成的代码#region 组件设计器生成的代码
        /**//// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </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="点击完成!";
        }

        private void AbeenControl_Load(object sender, System.EventArgs e)
        {
       
        }
    }
}
2、web 页面调用Active组件
  注意web页面调用时需要把Active的.dll放到web的虚拟要目录下。
<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="请输入数据:" ID="Text1">
            <input type="button" value="确定" onclick="doScript();" ID="Button1" NAME="Button1">
            <script type="text/javascript">
            function doScript()
            {
                 MyControl1.LabelText=frm.txt.value;
            }
           
            </script>
        </form>
    </body>
</HTML>
http://www.cnblogs.com/abeen/archive/2006/12/13/590764.html

上一篇:C#操作Word文档(Office 2007) 人气:6185
下一篇:通过win32api让c#控制Windows任务栏 人气:5038
浏览全部C#的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐