?? paintcoordinator.cs
字號:
using System;
using System.Runtime.Remoting.Messaging;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml;
using System.Xml.Serialization;
//namespace PaintCoordinator
//{
//Class Coordinator
public class Coordinator: MarshalByRefObject
{
public Coordinator() {
Console.WriteLine("Coordinator has been created...");
}
//聲明NewStroke事件,客戶端將會訂閱此事件
public event NewStrokeEventHandler NewStroke;
//忽略默認的對象租用行為,使對象始終保存在內存中
public override object InitializeLifetimeService() {
return null;
}
//Define GetCurrentTime(), return the system's time
public string GetCurrentTime() {
return DateTime.Now.ToLongTimeString();
}
//定義DrawStroke處理程序,當某一個客戶端遠程調用此函數時,將會觸發NewStroke事件,從而使得所有訂閱NewStroke事件的客戶端都會受到此事件
[OneWay]
public void DrawStroke(Stroke stroke) {
if(NewStroke!=null)
NewStroke(stroke);
}
}
//Class Stroke
[Serializable]
public class Stroke {
//Store the width of pen
int penWidth;
//Store the color of pen
Color penColor;
ArrayList Points=new ArrayList();
//Constructor
public Stroke(){
}
public Stroke(int x,int y) {
Points.Add(new Point(x,y));
}
//屬性
public int PenWidth {
get
{
return penWidth;
}
set
{
penWidth=value;
}
}
public Color PenColor {
get
{
return penColor;
}
set
{
penColor=value;
}
}
public int Count {
get
{
return Points.Count;
}
}
//
public void Add(int x,int y) {
Points.Add(new Point(x,y));
}
//DrawStroke函數用于將此線條繪出
public void DrawStroke(Graphics g) {
Pen pen=new Pen(penColor,penWidth);
for(int i=0;i<Points.Count-1;i++) {
g.DrawLine(pen,(Point)Points[i],(Point)Points[i+1]);
}
pen.Dispose();
}
}
//Class RemoteDelegateObject
public abstract class ReomteDelegateObject: MarshalByRefObject {
public void NewStrokeCallback(Stroke stroke) {
InternalNewStrokeCallback(stroke);
}
protected abstract void InternalNewStrokeCallback(Stroke stroke);
}
//聲明一個委托
public delegate void NewStrokeEventHandler(Stroke stroke);
//}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -