PaintCoordinator.cs
资源名称:Visual.rar [点击查看]
上传用户:yiyuerguo
上传日期:2014-09-27
资源大小:3781k
文件大小:2k
源码类别:
C#编程
开发平台:
Others
- 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);
- //}