namespace Application
{
/// <summary>
/// Class1 的摘要说明。
/// 这是一个向自己的
/// </summary>
public delegate void ProcessBookDelegate();
public class TComponetClass :CollectionBase
{
private TComponetClass m_Class;
private ProcessBookDelegate m_Events;
public TComponetClass()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private TComponetClass this[int index]
{
get
{
return (TComponetClass)List[index];
}
}
public ProcessBookDelegate EventsChanged
{
get
{
return m_Events;
}
set
{
m_Events = value;
}
}
public TComponetClass Parent
{
get
{
return m_Class;
}
set
{
if(value == null )
{
if( m_Class != null)
{
m_Class.List.Remove(this);
m_Class =value;
}
}
else
//value !=null m_Class != null
{
if(m_Class != value)
{
if(m_Class != null)
this.Parent = null;
value.Componets.Add(this);
m_Class = value;
}//m_Calss =value then
什模都不做
}
}
}
private void Add(TComponetClass ChildClass)
{
//建一数组
List.Add(ChildClass);
}
protected TComponetClass Componets
{
get
{
return this;
}
}
public int ComponetCount
{
get
{
return List.Count;
}
}
private void MyEvents(ProcessBookDelegate Event,string s)
{
//MessageBox.Show(s);
if(Event !=null)
Event();
}
protected void Move()
{
for(int i = 0 ;i< List.Count ;i++)
{
TComponetClass Class1 =(TComponetClass)List;
Class1.Move();
//MessageBox.Show(List.ToString());
Class1.MyEvents(Class1.m_Events,List.ToString());
}
}
//public
}
}
模仿delphi TComponent写的,请大家指教,我主要是用它派生控制类,实现广播方式
下面是我做的例子!
private void Example1()
{
MessageBox.Show("t_distress");
}
private void Example2()
{
MessageBox.Show("t_Sample");
}
private void Example3()
{
MessageBox.Show("t_FuncClass");
}
private void Example4()
{
MessageBox.Show("t_PaveType");
}
private void Example5()
{
MessageBox.Show("t_Street");
}
private void button1_Click(object sender, System.EventArgs e)
{
Sectoin t_Section = new Sectoin();//Section 类是
Street t_Street = new Street();
PaveType t_PaveType = new PaveType();
FuncClass t_FuncClass = new FuncClass();
Sample t_Sample = new Sample();
distress t_distress = new distress();
t_Street.Parent = t_Section;
t_PaveType.Parent =t_Section;
t_FuncClass.Parent = t_Section;
t_Sample.Parent = null;
//
t_Sample.Parent = t_Section;
//
//t_Sample.Parent = t_Section;
//
//t_Sample.Parent = t_Street;
//
//t_Sample.Parent = null;
t_distress.Parent = t_Street;
t_Street.EventsChanged = new ProcessBookDelegate(Example5);
t_PaveType.EventsChanged = new ProcessBookDelegate(Example4);
t_FuncClass.EventsChanged = new ProcessBookDelegate(Example3);
t_Sample.EventsChanged = new ProcessBookDelegate(Example2);
t_distress.EventsChanged = new ProcessBookDelegate(Example1);
t_Section.Move();
}