你可以把这个功能抽象成类,然后编译成dll文件,然后直接引用dll文件,然后在你
以后要用到这功能的时候实例化后就可以用了
               
                                                wish u good luck
                                                     Greatsft

解决方案 »

  1.   

    我的想法好像跟楼主倒过来了。
    用户控件代码:
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Windows.Forms;namespace ZZTestForm
    {
    public delegate void TextBoxChangedHandle(string message);
    /// <summary>
    /// UserControl1 的摘要说明。
    /// </summary>
    public class UserControl1 : System.Windows.Forms.UserControl
    {
    public event TextBoxChangedHandle TextBoxChanged;
    private System.Windows.Forms.TextBox textBox1;
    /// <summary> 
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public UserControl1()
    {
    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.textBox1 = new System.Windows.Forms.TextBox();
    this.SuspendLayout();
    // 
    // textBox1
    // 
    this.textBox1.Location = new System.Drawing.Point(20, 32);
    this.textBox1.Name = "textBox1";
    this.textBox1.TabIndex = 0;
    this.textBox1.Text = "textBox1";
    this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
    // 
    // UserControl1
    // 
    this.Controls.Add(this.textBox1);
    this.Name = "UserControl1";
    this.Size = new System.Drawing.Size(150, 96);
    this.ResumeLayout(false); }
    #endregion private void textBox1_TextChanged(object sender, System.EventArgs e)
    {
    TextBoxChanged(this.textBox1.Text);
    }
    }
    }
    主窗体代码:
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace ZZTestForm
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private ZZTestForm.UserControl1 userControl11;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    InitializeComponent();
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.userControl11 = new ZZTestForm.UserControl1();
    this.SuspendLayout();
    // 
    // userControl11
    // 
    this.userControl11.Location = new System.Drawing.Point(96, 48);
    this.userControl11.Name = "userControl11";
    this.userControl11.Size = new System.Drawing.Size(150, 96);
    this.userControl11.TabIndex = 0;
    this.userControl11.TextBoxChanged += new ZZTestForm.TextBoxChangedHandle(this.userControl11_TextBoxChanged);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(332, 217);
    this.Controls.Add(this.userControl11);
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void userControl11_TextBoxChanged(string message)
    {
    MessageBox.Show("你改变了用户控件中TextBox的值:"+message);
    } }
    }
      

  2.   


    step1:
    在项目下声明一个代理:
    //要传的数据类
    public class heheEventArgs:EventArgs
    {
    //要传的string或者放个对象也可以!     
    public string xx;
    }
    //传输代理;
    public delegate void heheHandler(object sender, heheEventArgs e);step2:在RequestPurchaseBillListUI控件中添加一个
    public event heheHandler heheevent;
    在RequestPurchaseBillListUI控件Load事件中加入:
    {
    heheEventArgs arg = new heheEventArgs();
    arg.xx = "okle";
    this.heheevent(this,arg);
    }step3:
    在父窗口实例化RequestPurchaseBillListUI控件时,加入下面代码:
    RequestPurchaseBillListUI requestPurchaseBillListUI = new RequestPurchaseBillListUI();
    requestPurchaseBillListUI.heheevent += new heheHandler(this.hehe); 
    (如果你的控件是托过去的,在父窗体的#region Windows 窗体设计器生成的代码里的实例化后加requestPurchaseBillListUI.heheevent += new heheHandler(this.Button_click);)
    同时在父控件里添加方法:
    private void hehe(object sender, heheEventArgs e)
    {
      MessageBox.Show(e.xx);
      this.Button_click(this,new System.EventArgs());
    }这个原理和VC的消息类似,是子控件发一个Message给父控件,父控件收到Message后调用
    对应的方法,这个方法再调用button_click方法。这是C#代码的运行机制,一定要会的,就和VC的消息机制一样重要!