国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

VS.Net C# 調用 Active 組件

2024-07-10 13:09:01
字體:
來源:轉載
供稿:網友

  在編碼中不可否認調用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="確定" id="button1" name="button1">
            <script type="text/javascript">
            function doscript()
            {
                 mycontrol1.labeltext=frm.txt.value;
            }
           
            </script>
        </form>
    </body>
</html>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平安县| 晴隆县| 句容市| 旺苍县| 水城县| 滨州市| 达州市| 鄂温| 平原县| 湟源县| 新河县| 玛纳斯县| 朝阳市| 宣恩县| 荆门市| 平邑县| 清徐县| 德州市| 霍州市| 维西| 麻栗坡县| 永安市| 福泉市| 衢州市| 买车| 增城市| 左贡县| 永德县| 平罗县| 洪江市| 县级市| 中西区| 长乐市| 新巴尔虎右旗| 宁武县| 临澧县| 横山县| 喀什市| 鹤岗市| 兖州市| 红原县|