namespace HydroUI { public partial class DMap : XtraPanel { public TContainer TC = new TContainer(); /// /// 地图选项 /// public MapDimensions mapOption { get { return TC.mapOption; } set { TC.mapOption = value; } } /// /// 临时管网层 /// [Browsable(false)] public Template _newTemplate { get { return TC.newTemplate; } set { TC.newTemplate = value; } } [Browsable(false)] public Template _Template { get { return TC.template; } } private bool _needPaintAll; private Bitmap buffer; public DrawDelegate DrawNet = null; public DrawDelegate DrawNetNew = null; public DrawDelegate DrawBackGroundPic = null; //绘制辅助线 public DrawDelegate DrawAuxiliary = null; public MouseDelegate onMouseDown = null; public MouseDelegate onMouseMove = null; public MouseDelegate onMouseUp = null; public MouseDelegate onMouseWheel = null; public DrawingMode drawingMode = DrawingMode.All; private bool Inited = false; public DrawingStatus Status = DrawingStatus.Ready; public DMap() { InitializeComponent(); DoubleBuffered = true; } //补充参数 public void Init(TContainer TC, DrawDelegate[] Draws, MouseDelegate[] MouseEvents) { this.TC = TC; this.DrawNet = Draws[0]; this.DrawNetNew = Draws[1]; this.DrawBackGroundPic = Draws[2]; this.DrawAuxiliary = Draws[3]; this.onMouseDown = MouseEvents[0]; this.onMouseMove = MouseEvents[1]; this.onMouseUp = MouseEvents[2]; this.onMouseWheel = MouseEvents[3]; this.Inited = true; this.Status=DrawingStatus.Ready; } protected override void OnPaint(PaintEventArgs e) { this.Status = DrawingStatus.drawingBase; base.OnPaint(e); if (!Inited) { this.Status = DrawingStatus.Ready; return; } if (float.IsInfinity(mapOption.zoom)) { this.Status = DrawingStatus.Ready; return; } _needPaintAll = false; if (buffer == null || buffer.Width != Width || buffer.Height != Height) { buffer?.Dispose(); buffer = new Bitmap(Width, Height); } // 使用缓存绘制,避免在每次重绘时重新计算所有要绘制的元素 var bufferG = Graphics.FromImage(buffer); // 先将控件的背景填充为白色 bufferG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; bufferG.Clear(Color.Transparent); bufferG.TranslateTransform(Width / 2, Height / 2); bufferG.ScaleTransform(mapOption.zoom, -mapOption.zoom); bufferG.TranslateTransform(-mapOption.Center.X, -mapOption.Center.Y); this.Status = DrawingStatus.drawingPic; DrawBackGroundPic(bufferG, _Template); this.Status = DrawingStatus.drawingNet; //BookMark :绘制地图事件 DrawNet(bufferG, _Template); this.Status = DrawingStatus.drawingNetNew; if (_newTemplate?.network != null) DrawNetNew(bufferG, _newTemplate); this.Status = DrawingStatus.drawingOthers; DrawAuxiliary(bufferG, null); // 将生成的画布绘制到控件上 e.Graphics.DrawImage(buffer, 0, 0); bufferG.Dispose(); this.Status = DrawingStatus.Ready; } protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (Inited) onMouseDown(e); } protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (Inited) onMouseMove(e); } protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (Inited) onMouseUp(e); } protected override void OnMouseWheelCore(MouseEventArgs ev) { base.OnMouseWheelCore(ev); if (Inited) onMouseWheel(ev); } } }