111,105
社区成员




public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.setUserAvatar1.SetDragEvents();
}
}
using System.Drawing;
using System.Windows.Forms;
namespace MyNameSpace
{
public static class Extensions
{
public static void SetDragEvents(this UserControl ctrl)
{
bool DragFlag = false;
Point PreviousPoint = Point.Empty;
ctrl.MouseDown += (s, e) =>
{
DragFlag = true;
PreviousPoint = new Point(e.X, e.Y);
ctrl.SuspendLayout();
};
ctrl.MouseUp += (s, e) =>
DragFlag = false;
{
DragFlag = false;
ctrl.ResumeLayout();
};
ctrl.MouseMove += (s, e) =>
{
if (DragFlag)
{
var t = ctrl.Top + e.Y - PreviousPoint.Y;
if (t <= 0 && t + ctrl.Height >= ctrl.Parent.Height)
ctrl.Top = t;
}
};
}
}
}
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
老鼠 m = new 老鼠();
人 p = new 人();
猫 c = new 猫();
c.叫了 += p.醒了;
m.跑了 += c.叫;
Console.WriteLine("测试开始............");
m.开跑();
Console.WriteLine("..................测试结束!");
Console.ReadKey();
}
}
public class 老鼠
{
public event Action 跑了;
public void 开跑()
{
Console.WriteLine("老鼠跑");
if (跑了 != null)
跑了();
}
}
public class 猫
{
public event Action 叫了;
public void 叫()
{
Console.WriteLine("猫叫");
if (this.叫了 != null)
this.叫了();
}
}
public class 人
{
public void 醒了()
{
Console.WriteLine("人醒了");
}
}
}
public Man(IRatSubject[] ratSub, ICatSubject catSub)
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
老鼠 m = new 老鼠();
人 p = new 人();
猫 c = new 猫();
m.跑了 += c.叫;
m.跑了 += p.醒了;
Console.WriteLine("测试开始............");
m.开跑();
Console.WriteLine("..................测试结束!");
Console.ReadKey();
}
}
public class 老鼠
{
public event Action 跑了;
public void 开跑()
{
Console.WriteLine("老鼠跑");
if (跑了 != null)
跑了();
}
}
public class 猫
{
public void 叫()
{
Console.WriteLine("猫叫");
}
}
public class 人
{
public void 醒了()
{
Console.WriteLine("人醒了");
}
}
}
using System;
using System.Collections;
namespace test
{
public interface ICatCatcher
{
void DoSth();
}
public interface ICatSubject
{
void RegesiterCatCatcher(ICatCatcher catCatcher);
void Miao();
}
public interface IRatSubject
{
void RegesiterRatCatcher(IRatCatcher ratCatcher);
void Run();
}
public interface IRatCatcher
{
void Wake();
}
public class Cat : ICatSubject
{
public Cat()
{
}
private ArrayList catcherList = new ArrayList();
public void RegesiterCatCatcher(ICatCatcher catcher)
{
catcherList.Add(catcher);
}
public void Miao()
{
Console.WriteLine("Miao");
for (int i = 0; i < catcherList.Count; i++)
{
ICatCatcher catCatcher = (ICatCatcher)catcherList[i];
catCatcher.DoSth();
}
}
[STAThread]
public static void Main()
{
Cat cat = new Cat();
Rat[] rat = new Rat[10];
for (int i = 0; i < 10; i++)
{
rat[i] = new Rat(cat);
}
Man man = new Man(rat, cat);
cat.Miao();
}
}
public class Rat : ICatCatcher, IRatSubject
{
public Rat(ICatSubject catSub)
{
catSub.RegesiterCatCatcher(this);
}
public void DoSth()
{
Run();
}
private ArrayList ratcherList = new ArrayList();
public void RegesiterRatCatcher(IRatCatcher catcher)
{
ratcherList.Add(catcher);
}
public void Run()
{
Console.WriteLine("Rat Run");
for (int i = 0; i < ratcherList.Count; i++)
{
IRatCatcher ratCatcher = (IRatCatcher)ratcherList[i];
ratCatcher.Wake();
}
}
}
public class Man : ICatCatcher, IRatCatcher
{
public Man(IRatSubject[] ratSub, ICatSubject catSub)
{
for (int i = 0; i < ratSub.Length; i++)
{
ratSub[i].RegesiterRatCatcher(this);
}
catSub.RegesiterCatCatcher(this);
}
public void DoSth()
{
Console.WriteLine("Cat bring on Wake");
}
public void Wake()
{
Console.WriteLine("Rats bring on Wake");
}
}
}