当前位置:编程学习 > C#/ASP.NET >>

Activator.CreateInstance 传值

在调用的同时传递两个参数给dll窗体界面,用这两个参数做一些查询条件等等。
那个该如何来写呢? 

以下代码执行提示:未找到类型“YCCXMK.YCCX”上的构造函数


调用方法:
private void 测试ToolStripMenuItem_Click(object sender, EventArgs e)
        {            
            Type typeofControl = null;                  
            string dllPath = Application.StartupPath + "\\YCCXMK.dll";                 
            Assembly ass = Assembly.LoadFrom(dllPath);

            object[] args = new object[] {"a","b","c"};
            typeofControl = ass.GetType("YCCXMK.YCCX");
            object obj = Activator.CreateInstance(typeofControl, true, System.Reflection.BindingFlags.Default, null, args, null, null);              
            ((Form)obj).MdiParent = this;
            ((Form)obj).Show();

        }


dll内容:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace YCCXMK
{   
    public partial class YCCX : Form
    {
        private static SqlConnection sqlConnection1 = null;
        string aa, bb, cc;

        public YCCX(object a,object b,object c)
        {
            //aa = a;
            //bb = b;
            //cc = c;
        } 

        public YCCX()
        {
            InitializeComponent();

            this.dataGridView1.Columns.Add("第1列", "异常代码");
            this.dataGridView1.Columns.Add("第2列", "异常名称");
            this.dataGridView1.Columns.Add("第3列", "品名");
            this.dataGridView1.Columns.Add("第4列", "LOT NO.");
            this.dataGridView1.Columns.Add("第5列", "数量");
            this.dataGridView1.Columns.Add("第6列", "VFmin");
            this.dataGridView1.Columns.Add("第7列", "VFavg");
            this.dataGridView1.Columns.Add("第8列", "VFmax");
            this.dataGridView1.Columns.Add("第9列", "VFstd");
            this.dataGridView1.Columns.Add("第10列", "WLDmin");
            this.dataGridView1.Columns.Add("第11列", "WLDavg");
            this.dataGridView1.Columns.Add("第12列", "WLDmax");
            this.dataGridView1.Columns.Add("第13列", "WLDstd");
            this.dataGridView1.Columns.Add("第14列", "LOPmin");
            this.dataGridView1.Columns.Add("第15列", "LOPavg");
            this.dataGridView1.Columns.Add("第16列", "LOPmax");
            this.dataGridView1.Columns.Add("第17列", "LOPstd");
            this.dataGridView1.Columns.Add("第18列", "入库日期");
            this.dataGridView1.Columns.Add("第19列", "工号");
            this.dataGridView1.Columns.Add("第20列", "姓名");
            this.dataGridView1.Columns.Add("第21列", "操作时间");

            //绑定状态
            //comboBox_pinming.Items.Add("--所有--");
            comboBox_pihao.Items.Add("--所有--");
            //comboBox_pinming_();
            comboBox_pihao_();
            //comboBox_pinming.SelectedIndex = 0;
            comboBox_pihao.SelectedIndex = 0;
        }

        //获得数据库连接sql
        public static SqlConnection getsqlConnection()
        {
            if (sqlConnection1 == null)
            {
                sqlConnection1 = new SqlConnection(db.sqlconnection);
                sqlConnection1.Open();
            }
            return sqlConnection1;
        }


        //绑定批号控件数据
        private void comboBox_pihao_()
        {
            if (sqlConnection1 == null)
                sqlConnection1 = getsqlConnection();
            string sql;

            sql = "select distinct substring(YC_LOT_NO,3,8) from CHIP_LAB order by substring(YC_LOT_NO,3,8) ";
            SqlDataAdapter adp = new SqlDataAdapter(sql, sqlConnection1);
            DataSet ds = new DataSet();
            adp.Fill(ds, "Temp");
            sqlConnection1.Close();
            sqlConnection1 = null;

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                comboBox_pihao.Items.Add(ds.Tables["Temp"].Rows[i][0].ToString().Trim());
            }
        }   --------------------编程问答--------------------  object obj = Activator.CreateInstance(typeofControl,  args); 
为什么要用反射呢,只是为了测试?        
--------------------编程问答-------------------- 直接调用不好? --------------------编程问答-------------------- 我是想把每个功能模块打包成dll,然后通过主界面调用每个dll,方便更新。
主界面调用dll的时候,需要把用户信息传给dll。

按照您说的,调用弹出的不是我设计的界面,弹出的是系统默认的界面。


那该怎么来写呢? --------------------编程问答--------------------    public YCCX(object a,object b,object c):this()
不过你这样设计走弯路了,应该回头
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,