internal void RefreshInRect(Graphics eg, Rectangle rect) { if (!gbRefresh) return; Random rnd = new Random(); if (rect.Width <= 0 || rect.Height <= 0) return; //using (Graphics eg = base.CreateGraphics()) { using (Bitmap Bmp = new Bitmap(rect.Width, rect.Height)) { using (Graphics g = Graphics.FromImage(Bmp)) { g.Clear(Color.White); //发送绘制消息 PaintMessage m = new PaintMessage(g, rect); gManager.SendMessage(m); } if (eg != null) { eg.DrawImageUnscaled(Bmp, rect.X, rect.Y); } else { try { using (Graphics g = this.CreateGraphics()) { g.DrawImageUnscaled(Bmp, rect.X, rect.Y); //System.Diagnostics.Debug.WriteLine("GPanel\\>RefreshInRect" + rect.ToString()); } } catch { } } } }
/// <summary> /// 范围重新绘制 /// </summary> /// <param name="rect"></param> internal void RefreshInRect(Graphics eg, Rectangle rect) { OnApply(rect);//调用继承处理 //根据容器的设定重新设定请求区域 int nTop = base.ShadowsSize + base.BorderSize + base.PaddingTop; int nLeft = base.ShadowsSize + base.BorderSize + base.PaddingLeft; int nWidth = base.Width - (base.ShadowsSize * 2 + base.BorderSize * 2 + base.PaddingRight + base.PaddingLeft) + 1; int nHeight = base.Height - (base.ShadowsSize * 2 + base.BorderSize * 2 + base.PaddingBottom + base.PaddingTop) + 1; int nRectWidth = rect.Width; int nRectHeight = rect.Height; if (rect.Right > nWidth) nRectWidth = nWidth - rect.Left; if (rect.Bottom > nHeight) nRectHeight = nHeight - rect.Top; Rectangle rectNew = new Rectangle(rect.Left, rect.Top, nRectWidth, nRectHeight); Rectangle rectAbs = new Rectangle(rect.Left, rect.Top, rect.Width, rect.Width); if (nRectWidth <= 0 || nRectHeight <= 0) return; //base.Debug(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName, "RefreshInRect", "Rectangle", rect.ToString()); //base.Debug(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName, "RefreshInRect", "RefreshAllow", base.RefreshAllow.ToString()); //创建一个临时画布,更新当前容器绘制缓存 using (Bitmap Bmp = new Bitmap(nRectWidth, nRectHeight)) { using (Graphics g = Graphics.FromImage(Bmp)) { g.Clear(Color.White); //发送绘制消息 PaintMessage m = new PaintMessage(g, rectNew); PaintMessage mAbs = new PaintMessage(g, rectAbs); //base.Debug(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName, "RefreshInRect", "rectNew", rectNew.ToString()); for (int i = 0; i < gChildren.Count; i++) { if (gChildren[i].Visible) { if (gChildren[i].Absolute) { gChildren[i].SendMessage(mAbs); } else { gChildren[i].SendMessage(m); } if (m.Suppress) return; } } } //更新到容器缓存 if (eg != null) { eg.DrawImageUnscaled(Bmp, nLeft + rect.Left, nTop + rect.Top); } else { if (base.Cache != null) { using (Graphics g = Graphics.FromImage(base.Cache)) { g.DrawImageUnscaled(Bmp, nLeft + rect.Left, nTop + rect.Top); } } } } //当允许绘制时路由提交刷新请求 if (base.RefreshAllow) { Rectangle rectSubmit = new Rectangle(rect.Left + this.Left + nLeft, rect.Top + this.Top + nTop, nRectWidth, nRectHeight); //具有父对象,先向父对象提交刷新,如无父对象,则提交给管理器 if (base.Parent != null) { base.Parent.RefreshInRect(rectSubmit); } else { if (base.Manager != null) base.Manager.RefreshInRect(rectSubmit); } } }
/// <summary> /// 范围重新绘制 /// </summary> /// <param name="rect"></param> internal void RefreshInRect(Rectangle rect) { //base.Debug(rect.ToString()); Messages.PaintMessage msg = new PaintMessage(null, rect); this.Apply(this, msg); }