public override void Paint(PaintEventArgs pe, int nBaseX, int nBaseY, PaintMember paintMember) { Rectangle rectPaintThis = new Rectangle(0, 0, 0, 0); rectPaintThis = new Rectangle(nBaseX + this.Rect.X, nBaseY + this.Rect.Y, this.Rect.Width, this.Rect.Height); if (rectPaintThis.IntersectsWith(pe.ClipRectangle) == false) { return; } Item item = this.GetItem(); if (item == null) { return; } //? Object colorDefault = null; XmlEditor editor = item.m_document; if (editor != null && editor.VisualCfg != null) { colorDefault = editor.VisualCfg.transparenceColor; } if (colorDefault != null) { if (((Color)colorDefault).Equals(BackColor) == true) { goto SKIPDRAWBACK; } } using (Brush brush = new SolidBrush(this.BackColor)) { pe.Graphics.FillRectangle(brush, rectPaintThis); } SKIPDRAWBACK: if (editor != null && editor.VisualCfg == null) { } else { //调DrawLines画边框 this.DrawLines(rectPaintThis, this.TopBorderHeight, this.BottomBorderHeight, this.LeftBorderWidth, this.RightBorderWidth, this.BorderColor); } if (childrenVisual == null) { return; } for (int i = 0; i < this.childrenVisual.Count; i++) { Visual visual = (Visual)(this.childrenVisual[i]); Rectangle rectPaintChild = new Rectangle( nBaseX + this.Rect.X + visual.Rect.X, nBaseY + this.Rect.Y + visual.Rect.Y, visual.Rect.Width, visual.Rect.Height); if (rectPaintChild.IntersectsWith(pe.ClipRectangle) == true) { visual.Paint(pe, nBaseX + this.Rect.X, nBaseY + this.Rect.Y, paintMember); } if (editor != null && editor.VisualCfg == null) { if (i == this.childrenVisual.Count - 1) { int nDelta = this.RectAbs.Y + this.Rect.Height - visual.RectAbs.Y - visual.Rect.Height - Visual.BOTTOMBORDERHEIGHT; if (nDelta > 0) { // 画下方线条 this.DrawLines(new Rectangle(rectPaintChild.X, rectPaintChild.Y, rectPaintChild.Width, rectPaintChild.Height + Visual.BOTTOMBORDERHEIGHT), 0, Visual.BOTTOMBORDERHEIGHT, 0, 0, visual.BorderColor); } } if (i <= 0) { continue; } if (this.LayoutStyle == LayoutStyle.Vertical) { // 只画上方线条 this.DrawLines(rectPaintChild, visual.TopBorderHeight, 0, 0, 0, visual.BorderColor); } else if (this.LayoutStyle == LayoutStyle.Horizontal) { this.DrawLines(rectPaintChild, 0, 0, visual.LeftBorderWidth, 0, visual.BorderColor); } } } }
// 为什么要重写这个函数 // 因为只画单线条时,只有根才画四线,其它父亲不画线条 public override void Paint(PaintEventArgs pe, int nBaseX, int nBaseY, PaintMember paintMember) { // 1.计算出区域 Rectangle rectPaintThis = new Rectangle(0, 0, 0, 0); rectPaintThis = new Rectangle(nBaseX + this.Rect.X, nBaseY + this.Rect.Y, this.Rect.Width, this.Rect.Height); if (rectPaintThis.IntersectsWith(pe.ClipRectangle) == false) { return; } // 2.画背景色 // 如有缺省透明色,当前颜色与透明色相同则不画了 //? Object colorDefault = null; XmlEditor editor = this.m_document; if (editor != null && editor.VisualCfg != null) { colorDefault = editor.VisualCfg.transparenceColor; } if (colorDefault != null) //缺省颜色 { if (((Color)colorDefault).Equals(BackColor) == true) { goto SKIPDRAWBACK; } } using (Brush brush = new SolidBrush(BackColor)) { pe.Graphics.FillRectangle(brush, rectPaintThis); } SKIPDRAWBACK: // 4.画儿子 if (childrenVisual == null) { goto END1; } for (int i = 0; i < this.childrenVisual.Count; i++) { Visual visual = (Visual)(this.childrenVisual[i]); Rectangle rectPaintChild = new Rectangle( nBaseX + this.Rect.X + visual.Rect.X, nBaseY + this.Rect.Y + visual.Rect.Y, visual.Rect.Width, visual.Rect.Height); if (rectPaintChild.IntersectsWith(pe.ClipRectangle) == true) { visual.Paint(pe, nBaseX + this.Rect.X, nBaseY + this.Rect.Y, paintMember); } if (i <= 0) { continue; } if (editor != null && editor.VisualCfg == null) { if (this.layoutStyle == LayoutStyle.Horizontal) { this.DrawLines(rectPaintChild, 0, 0, visual.LeftBorderWidth, 0, visual.BorderColor); } else { this.DrawLines(rectPaintChild, visual.TopBorderHeight, 0, 0, 0, visual.BorderColor); } } } END1: // 3.画根元素的外边框线条 this.DrawLines(rectPaintThis, this.TopBorderHeight, this.BottomBorderHeight, this.LeftBorderWidth, this.RightBorderWidth, this.BorderColor); }
// 为什么要重写虚属性,item是从visual派生,而visual派生类并没有具体实现这个函数 public override void Paint(PaintEventArgs pe, int nBaseX, int nBaseY, PaintMember paintMember) { // 1.计算出本对象的实际区域 Rectangle rectPaintThis = new Rectangle(0, 0, 0, 0); rectPaintThis = new Rectangle(nBaseX + this.Rect.X, nBaseY + this.Rect.Y, this.Rect.Width, this.Rect.Height); if (rectPaintThis.IntersectsWith(pe.ClipRectangle) == false) { return; } // 2.画背景色 // 如有缺省透明色,当前颜色与透明色相同则不画了 Object colorDefault = null; XmlEditor editor = this.m_document; if (editor != null && editor.VisualCfg != null) { colorDefault = editor.VisualCfg.transparenceColor; } if (colorDefault != null) //缺省颜色 { if (((Color)colorDefault).Equals(BackColor) == true) { goto SkipDrawBack; } } using (Brush brush = new SolidBrush(this.BackColor)) { pe.Graphics.FillRectangle(brush, rectPaintThis); } // 跳过画背景色 SkipDrawBack: // 3.画线条 // 当单线条时,自己不画,靠儿子来画 if (editor != null && editor.VisualCfg == null) { } else { // 配置文件定了的时候 this.DrawLines(rectPaintThis, this.TopBorderHeight, this.BottomBorderHeight, this.LeftBorderWidth, this.RightBorderWidth, this.BorderColor); } // 4.画儿子 if (childrenVisual == null) { return; } for (int i = 0; i < this.childrenVisual.Count; i++) { Visual visual = (Visual)(this.childrenVisual[i]); Rectangle rectPaintChild = new Rectangle( nBaseX + this.Rect.X + visual.Rect.X, nBaseY + this.Rect.Y + visual.Rect.Y, visual.Rect.Width, visual.Rect.Height); if (rectPaintChild.IntersectsWith(pe.ClipRectangle) == true) { visual.Paint(pe, nBaseX + this.Rect.X, nBaseY + this.Rect.Y, paintMember); } if (i <= 0) { continue; } if (editor != null && editor.VisualCfg == null) { this.DrawLines(rectPaintChild, 0, 0, visual.LeftBorderWidth, 0, visual.BorderColor); } } }