/// <summary> /// 创建填充背景使用的画刷对象 /// </summary> /// <param name="left">要绘制背景区域的左端坐标</param> /// <param name="top">要绘制背景区域的顶端坐标</param> /// <param name="width">要绘制背景区域的宽度</param> /// <param name="height">要绘制背景区域的高度</param> /// <param name="unit">绘制图形使用的单位</param> /// <returns>创建的画刷对象</returns> /// <remarks> /// 若设置了背景图片则创建图片样式的画刷对象,若设置了图案则创建带图案的画刷对象, /// 若设置了渐变设置则创建带渐变的画刷对象,否则创建纯色画刷对象。 /// </remarks> public Brush CreateBrush( float left, float top, float width, float height, System.Drawing.GraphicsUnit unit) { if (intStyle == XBrushStyleConst.Disabled) { return(null); } if (myImage != null && myImage.Value != null) { System.Drawing.TextureBrush brush = new TextureBrush(myImage.Value); if (bolRepeat) { brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile; } else { brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp; } float rate = (float)GraphicsUnitConvert.GetRate( unit, System.Drawing.GraphicsUnit.Pixel); //brush.Transform.Translate(fOffsetX, fOffsetY); brush.TranslateTransform(fOffsetX, fOffsetY); brush.ScaleTransform(rate, rate); return(brush); } if (intStyle == XBrushStyleConst.Solid) { return(new SolidBrush(intColor)); } else { if (( int )intStyle < 1000) { System.Drawing.Drawing2D.HatchStyle style = (System.Drawing.Drawing2D.HatchStyle)intStyle; return(new System.Drawing.Drawing2D.HatchBrush( (System.Drawing.Drawing2D.HatchStyle)intStyle, intColor, intColor2)); } else { return(new System.Drawing.Drawing2D.LinearGradientBrush( new RectangleF(left, top, width, height), intColor, intColor2, (System.Drawing.Drawing2D.LinearGradientMode)(intStyle - 1000))); } } //return new SolidBrush(intColor); }
/// <summary> /// 使用指定图形绘制对象从指定位置开始绘制页面框架 /// </summary> /// <param name="g">图形绘制对象</param> /// <param name="ClipRectangle">剪切矩形</param> public void DrawPageFrame( System.Drawing.Graphics g, System.Drawing.Rectangle ClipRectangle) { using (RectangleDrawer drawer = new RectangleDrawer()) { drawer.Bounds = this.myBounds; drawer.RoundRadio = 9; if (this.intBorderColor.A != 0 && this.intBorderWidth > 0) { drawer.BorderPen = new System.Drawing.Pen( this.intBorderColor, this.intBorderWidth); } if (this.intBackColor.A != 0) { drawer.FillBrush = new System.Drawing.SolidBrush(this.intBackColor); } if (drawer.Draw(g, ClipRectangle)) { if (myBackgroundImage != null) { // 绘制页面背景图片 Rectangle ir = new Rectangle( myBounds.Left, myBounds.Top, myBounds.Width, myBounds.Height); if (ClipRectangle.IsEmpty == false) { ir = System.Drawing.Rectangle.Intersect(ir, ClipRectangle); } if (ir.IsEmpty == false) { using (TextureBrush brush = new TextureBrush(myBackgroundImage)) { brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile; float rate = (float)GraphicsUnitConvert.GetRate( g.PageUnit, System.Drawing.GraphicsUnit.Pixel); brush.TranslateTransform( myBounds.Left, myBounds.Top); brush.ScaleTransform(rate, rate); g.FillRectangle(brush, ir); } //using drawer.DrawBorder(g, ClipRectangle); } //if //Rectangle ir = new Rectangle( // myBounds.Left + this.LeftMargin, // myBounds.Top + this.TopMargin, // myBounds.Width - this.LeftMargin - this.RightMargin, // myBounds.Height - this.TopMargin - this.BottomMargin); //if (ClipRectangle.IsEmpty == false) //{ // ir = System.Drawing.Rectangle.Intersect(ir, ClipRectangle); //} //if (ir.IsEmpty == false) //{ // using (TextureBrush brush = new TextureBrush(myBackgroundImage)) // { // brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile; // float rate = (float)GraphicsUnitConvert.GetRate( // g.PageUnit, // System.Drawing.GraphicsUnit.Pixel); // brush.TranslateTransform( // myBounds.Left + this.LeftMargin, // myBounds.Top + this.TopMargin); // brush.ScaleTransform(rate, rate); // g.FillRectangle(brush, ir); // }//using //}//if } if (this.bolDrawMargin && this.intMarginLineColor.A != 0 && this.intMarginLineLength > 0) { System.Drawing.Rectangle rect = new System.Drawing.Rectangle( myBounds.Left + this.intLeftMargin - 1, myBounds.Top + this.intTopMargin, myBounds.Width - this.intLeftMargin - this.intRightMargin + 2, myBounds.Height - this.intTopMargin - this.intBottomMargin); System.Drawing.Point[] ps = new System.Drawing.Point[16]; ps[0] = rect.Location; ps[1].X = rect.Left - intMarginLineLength; ps[1].Y = rect.Top; ps[2] = ps[0]; ps[3].X = rect.Left; ps[3].Y = rect.Top - intMarginLineLength; ps[4].X = rect.Right; ps[4].Y = rect.Top; ps[5].X = rect.Right + intMarginLineLength; ps[5].Y = rect.Top; ps[6] = ps[4]; ps[7].X = rect.Right; ps[7].Y = rect.Top - intMarginLineLength; ps[8].X = rect.Right; ps[8].Y = rect.Bottom; ps[9].X = rect.Right + intMarginLineLength; ps[9].Y = rect.Bottom; ps[10] = ps[8]; ps[11].X = rect.Right; ps[11].Y = rect.Bottom + intMarginLineLength; ps[12].X = rect.Left; ps[12].Y = rect.Bottom; ps[13].X = rect.Left; ps[13].Y = rect.Bottom + intMarginLineLength; ps[14] = ps[12]; ps[15].X = rect.Left - intMarginLineLength; ps[15].Y = rect.Bottom; MathCommon.RectangleClipLines(myBounds, ps); using (System.Drawing.Pen p = new System.Drawing.Pen( this.intMarginLineColor, 1)) { for (int iCount = 0; iCount < ps.Length; iCount += 2) { g.DrawLine(p, ps[iCount], ps[iCount + 1]); } } //using( System.Drawing.Pen p = new System.Drawing.Pen( this.intMarginLineColor , 1 )) } //if( this.bolDrawMargin && this.intMarginLineColor.A != 0 ) } //if( drawer.Draw( g , ClipRectangle )) } //using( RectangleDrawer drawer = new RectangleDrawer() ) } //public void DrawPageFrame()