单据状态图
介绍单据状态图片显示,能够很美观的看到单据的状态,源码不是我写的 是网上下载的 只是时间久了 忘记哪位博主大神写的了 只是略作修改,系统能够正常使用。
这里粘贴系统用的代码,希望能帮助各位。
1 namespace RwxFramework.Library 2 { 3 /// <summary> 4 /// 提供透明和旋转功能的基础控件 5 /// </summary> 6 public partial class CYBaseControl : Control 7 { 8 private float _iBorderThickness = 1f; 9 private float _iOpacity = 1f; 10 private Brush _brushBg = null; 11 private Pen _penFg = null; 12 13 public CYBaseControl() 14 { 15 this.SetStyle(ControlStyles.SupportsTransparentBackColor | 16 ControlStyles.Opaque, true); 17 this.BackColor = Color.Transparent; 18 BackgroundBrush = Brushes.Transparent; 19 ForegroundPen = Pens.Black; 20 this.TabStop = false; 21 } 22 23 #region Propertys 24 #region HideParent 25 [Browsable(false)] 26 [EditorBrowsable(EditorBrowsableState.Never)] 27 public override string Text 28 { 29 get { return base.Text; } 30 set { base.Text = value; } 31 } 32 33 [Browsable(false)] 34 [EditorBrowsable(EditorBrowsableState.Never)] 35 public override Image BackgroundImage 36 { 37 get { return base.BackgroundImage; } 38 set { base.BackgroundImage = value; } 39 } 40 41 [Browsable(false)] 42 [EditorBrowsable(EditorBrowsableState.Never)] 43 public override ImageLayout BackgroundImageLayout 44 { 45 get 46 { 47 return base.BackgroundImageLayout; 48 } 49 set 50 { 51 base.BackgroundImageLayout = value; 52 } 53 } 54 #endregion 55 56 public override Color BackColor 57 { 58 get 59 { 60 return base.BackColor; 61 } 62 set 63 { 64 base.BackColor = value; 65 ResetBgBrush(); 66 } 67 } 68 69 //[EditorAttribute(typeof(BrushTypeEditor), typeof(System.Drawing.Design.UITypeEditor))] 70 //public double Background 71 //{ 72 // get; 73 // set; 74 //} 75 76 public override Color ForeColor 77 { 78 get 79 { 80 return base.ForeColor; 81 } 82 set 83 { 84 base.ForeColor = value; 85 ResetFgPen(); 86 } 87 } 88 89 public float BorderThickness 90 { 91 get { return _iBorderThickness; } 92 set 93 { 94 if (value < 0) 95 { 96 throw new Exception("Out off range"); 97 } 98 _iBorderThickness = value; 99 ResetFgPen(); 100 ResetDrawRect(); 101 } 102 } 103 104 public virtual float RotateAngle 105 { 106 get; 107 set; 108 } 109 110 111 public float Opacity 112 { 113 get { return _iOpacity; } 114 set 115 { 116 if (value > 1 || value < 0) 117 { 118 throw new Exception("Out of range,the Value be in [0,1]"); 119 } 120 else 121 { 122 _iOpacity = value; 123 ResetBrushes(); 124 } 125 } 126 } 127 128 protected override CreateParams CreateParams 129 { 130 get 131 { 132 CreateParams cp = base.CreateParams; 133 cp.ExStyle = 0x20; 134 return cp; 135 } 136 } 137 138 protected virtual Brush BackgroundBrush 139 { 140 get { return _brushBg; } 141 set { _brushBg = value; } 142 } 143 144 protected virtual Pen ForegroundPen 145 { 146 get { return _penFg; } 147 set { _penFg = value; } 148 } 149 150 protected virtual RectangleF DrawRect 151 { 152 get; 153 set; 154 } 155 #endregion 156 157 #region Methods 158 protected override void OnPaint(PaintEventArgs e) 159 { 160 base.OnPaint(e); 161 e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; 162 } 163 164 protected override void OnSizeChanged(EventArgs e) 165 { 166 base.OnSizeChanged(e); 167 ResetDrawRect(); 168 } 169 protected override void OnPaddingChanged(EventArgs e) 170 { 171 base.OnPaddingChanged(e); 172 ResetDrawRect(); 173 } 174 175 protected void ResetBrushes() 176 { 177 ResetBgBrush(); 178 ResetFgPen(); 179 } 180 181 protected void ResetBgBrush() 182 { 183 BackgroundBrush = new SolidBrush(GetOpacityColor(BackColor, Opacity)); 184 } 185 186 protected void ResetFgPen() 187 { 188 ForegroundPen = new Pen(GetOpacityColor(ForeColor, Opacity), BorderThickness); 189 } 190 191 protected Color GetOpacityColor(Color baseColor, float op) 192 { 193 return Color.FromArgb(Convert.ToInt32(op * baseColor.A), baseColor); 194 } 195 196 private void ResetDrawRect() 197 { 198 float dbwidth = 2 * BorderThickness; 199 float halfwidth = BorderThickness / 2; 200 int paddingWhith = Padding.Left + Padding.Right; 201 int paddingHeight = Padding.Top + Padding.Bottom; 202 if (dbwidth > Width - paddingWhith || dbwidth > Height - paddingHeight) 203 { 204 DrawRect = this.Bounds; 205 } 206 else 207 { 208 DrawRect = new RectangleF(Padding.Left + halfwidth, 209 Padding.Top + halfwidth, 210 Width - BorderThickness - paddingWhith, 211 Height - BorderThickness - paddingHeight); 212 } 213 } 214 #endregion 215 } 216 }
1 namespace RwxFramework.Library 2 { 3 [ToolboxBitmap(typeof(OpacityImage), "Resources.PictureObject.png")] 4 public partial class OpacityImage : CYBaseControl 5 { 6 private Image _image = RwxFramework.Library.Properties.Resources.no; 7 private ImageFillMode _fillMode = ImageFillMode.Zoom; 8 9 public Image Image 10 { 11 get { return _image; } 12 set 13 { 14 if (value == null) 15 { 16 _image = RwxFramework.Library.Properties.Resources.no; 17 } 18 else 19 { 20 _image = value; 21 } 22 ResetPaintImage(); 23 } 24 } 25 public bool _isaudit = false; 26 public bool IsAudit 27 { 28 get { return _isaudit; } 29 set 30 { 31 _isaudit = value; 32 ShowImage(value); 33 } 34 } 35 36 37 public ImageFillMode FillMode 38 { 39 get { return _fillMode; } 40 set 41 { 42 _fillMode = value; 43 ResetPaintImage(); 44 } 45 } 46 47 protected override RectangleF DrawRect 48 { 49 get 50 { 51 return base.DrawRect; 52 } 53 set 54 { 55 base.DrawRect = value; 56 ResetPaintImage(); 57 } 58 } 59 60 protected Image PaintImage 61 { 62 get; 63 private set; 64 } 65 protected override void OnPaint(PaintEventArgs e) 66 { 67 base.OnPaint(e); 68 if (PaintImage != null) 69 { 70 e.Graphics.DrawImage(PaintImage, Point.Empty); 71 } 72 } 73 private void ResetPaintImage() 74 { 75 if (PaintImage != null) 76 { 77 PaintImage.Dispose(); 78 PaintImage = null; 79 } 80 if (_image != null && _image.Width > 0 && _image.Height > 0 && DrawRect.Width > 0 && DrawRect.Height > 0) 81 { 82 PaintImage = new Bitmap((int)DrawRect.Width, (int)DrawRect.Height); 83 using (Graphics g = Graphics.FromImage(PaintImage)) 84 { 85 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; 86 g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; 87 88 System.Drawing.Imaging.ImageAttributes ima = new System.Drawing.Imaging.ImageAttributes(); 89 ColorMatrix cm = new ColorMatrix(); 90 cm.Matrix33 = Opacity; 91 ima.SetColorMatrix(cm); 92 Point pt = Point.Empty; 93 switch (FillMode) 94 { 95 case ImageFillMode.Center: 96 pt = new Point((int)(DrawRect.Width - _image.Width) / 2, (int)(DrawRect.Height - _image.Height) / 2); 97 g.DrawImage(_image, new Rectangle(pt, _image.Size), 0, 0, _image.Width, _image.Height, GraphicsUnit.Pixel, ima); 98 break; 99 case ImageFillMode.Strength: 100 g.DrawImage(_image, Rectangle.Round(DrawRect), 0, 0, _image.Width, _image.Height, GraphicsUnit.Pixel, ima); 101 break; 102 case ImageFillMode.Title: 103 ima.SetWrapMode(System.Drawing.Drawing2D.WrapMode.Tile); 104 TextureBrush brush = new TextureBrush(_image, new Rectangle(0, 0, _image.Width, _image.Height), ima); 105 g.FillRectangle(brush, DrawRect); 106 break; 107 case ImageFillMode.Zoom: 108 float IntWidth; //新的图片宽 109 float IntHeight; //新的图片高 110 111 float TargetWidth = DrawRect.Width; 112 float TargetHeight = DrawRect.Height; 113 114 if (_image.Width > TargetWidth && _image.Height <= TargetHeight)//宽度比目的图片宽度大,长度比目的图片长度小 115 { 116 IntWidth = TargetWidth; 117 IntHeight = (IntWidth * _image.Height) / _image.Width; 118 } 119 else if (_image.Width <= TargetWidth && _image.Height > TargetHeight)//宽度比目的图片宽度小,长度比目的图片长度大 120 { 121 IntHeight = TargetHeight; 122 IntWidth = (IntHeight * _image.Width) / _image.Height; 123 } 124 else if (_image.Width <= TargetWidth && _image.Height <= TargetHeight) //长宽比目的图片长宽都小 125 { 126 IntHeight = _image.Width; 127 IntWidth = _image.Height; 128 } 129 else//长宽比目的图片的长宽都大 130 { 131 IntWidth = TargetWidth; 132 IntHeight = (IntWidth * _image.Height) / _image.Width; 133 if (IntHeight > TargetHeight)//重新计算 134 { 135 IntHeight = TargetHeight; 136 IntWidth = (IntHeight * _image.Width) / _image.Height; 137 } 138 } 139 g.DrawImage(_image, 140 (TargetWidth - IntWidth) / 2, 141 (TargetHeight - IntHeight) / 2, 142 IntWidth, 143 IntHeight); 144 break; 145 } 146 g.Dispose(); 147 } 148 } 149 else 150 { 151 PaintImage = null; 152 } 153 } 154 public void RefreshImage() 155 { 156 int width = base.Width; 157 base.Width = width + 1; 158 width = base.Width; 159 base.Width = width - 1; 160 } 161 162 public void ShowImage(bool audit) 163 { 164 if (audit) 165 { 166 this.Image = RwxFramework.Library.Properties.Resources.Audit; 167 } 168 else 169 { 170 this.Image = RwxFramework.Library.Properties.Resources.no; 171 } 172 this.RefreshImage(); 173 } 174 175 } 176 177 public enum ImageFillMode 178 { 179 Zoom, 180 Title, 181 Strength, 182 Center 183 } 184 }