我有一个字符串变量,或字符串属性,哪个都成。这个变量或属性在一个事件里接收值。现在我想一但这个变量或属性接收到值,我就触发一个事件通知我接收到值了。我知道用委托,但不会写。这个能不能办到?
解决方案 »
- MarShal.Copy
- C#新手。哪位有好教程介绍个!
- 如何用代码让水晶报表刷新?
- 请教c#中两个winform之间如何传值,比如左边一个treeview,右边一个listview.
- C#的reportviewer调用子报表rdlc的问题
- 用C#写的winform代码,在窗体使用combobox后,打开速度慢的问题
- C#委派(型別)給C++DLL問題
- 谁做过vpn断网后,让回到本地ip,也就是禁用本地网络
- 高分请教 在C#程序中来实现SQL2000数据库和ACCESS2000数据库间的数据导入和导出
- help me!
- c#中的命名空间问题
- 对一张图片的某点(例如点(10,10))的色值,为了精确,我将图片放大16倍后再取值,此时该点是不是对应点(160,160)
{
/// <summary>
/// 事件类
/// </summary>
/// public delegate void ClassInEventDelegate(object sender,string strEvent);
public class ClassInEvent
{ public event ClassInEventDelegate ClassInEvent_On; public ClassInEvent()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void ImpEvent(string name)
{
if(ClassInEvent_On != null)
{
this.ClassInEvent_On(this,name);
}
else
{
System.Windows.Forms.MessageBox.Show("没有绑定事件方法!"); }
}
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;namespace WindowsApplication1
{
/// <summary>
/// myevent 的摘要说明。
/// </summary>
public class myevent : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private string myname;
private myClassLibary.ClassInEvent cie;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public string Getname
{
set
{
myname=value;
cie.ImpEvent("lypink");
}
} private void cie_ClassInEvent_On(object sender, string strEvent)
{
MessageBox.Show(this,strEvent + " string 有值了");
} public myevent()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); cie = new myClassLibary.ClassInEvent();
cie.ClassInEvent_On +=new myClassLibary.ClassInEventDelegate(cie_ClassInEvent_On); //
// TODO: 在 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.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(72, 48);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(128, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(104, 96);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(72, 24);
this.button1.TabIndex = 1;
this.button1.Text = "Give str";
this.button1.Click += new System.EventHandle.(this.button1_Click);
//
// myevent
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Name = "myevent";
this.Text = "myevent";
this.Load += new System.EventHandler(this.myevent_Load);
this.ResumeLayout(false); }
#endregion private void myevent_Load(object sender, System.EventArgs e)
{
} private void button1_Click(object sender, System.EventArgs e)
{
if(textBox1.Text!="")
{
this.Getname = textBox1.Text;
}
}
}
}