using System; using System.Windows; using DevExpress.XtraGrid; using DevExpress.XtraGrid.Views.Grid; using System.Drawing; using System.ComponentModel; using System.Windows.Forms; using DevExpress.XtraVerticalGrid; using System.Drawing.Imaging; using System.Drawing.Drawing2D; namespace WMS.Compoment { public class VGridControlCustom : VGridControl { #region 定义变量 private Bitmap _Image = null; #endregion #region 构造函数 /// /// 构造函数 /// public VGridControlCustom() { InitializeComponent(); } /// /// 构造控件 /// private void InitializeComponent() { ((System.ComponentModel.ISupportInitialize)(this)).BeginInit(); this.SuspendLayout(); this.Paint += new System.Windows.Forms.PaintEventHandler(this.VGridControlCustom_Paint); ((System.ComponentModel.ISupportInitialize)(this)).EndInit(); this.ResumeLayout(false); } #endregion #region 设置审核标识图片 /// /// 设置审核标识图片 /// /// 审核标识 public void SetVerifyFlagImage(string flag) { try { if (flag == "0") { _Image = WMS.Ctrl.Properties.Resources.未审核; } else if (flag == "1") { _Image = WMS.Ctrl.Properties.Resources.已审核; } else if (flag == "2") { _Image = WMS.Ctrl.Properties.Resources.审核未执行; } else if (flag == "3") { _Image = WMS.Ctrl.Properties.Resources.审批中; } else if (flag == "4") { _Image = WMS.Ctrl.Properties.Resources.未通过; } else if (flag == "5") { _Image = WMS.Ctrl.Properties.Resources.已通过; } else if (flag == "6") { _Image = WMS.Ctrl.Properties.Resources.作废; } else if (flag == "7") { _Image = WMS.Ctrl.Properties.Resources.驳回; } this.Invalidate(); } catch (Exception ex) { throw ex; } } /// /// 设置审核标识图片 /// /// 图片 public void SetVerifyFlagImage(Bitmap image) { try { _Image = image; this.Invalidate(); } catch (Exception ex) { throw ex; } } #endregion #region 清空审核标识图片 /// /// 清空审核标识图片 /// /// 审核标识 public void ClearVerifyFlagImage() { try { _Image = null; this.Invalidate(); } catch (Exception ex) { throw ex; } } #endregion #region 绘图事件 /// /// 界面绘制事件 /// /// /// private void VGridControlCustom_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { try { if (_Image == null) { return; } Graphics g = e.Graphics; int x = Convert.ToInt32(this.Width - (_Image.Width / Math.Sqrt(2) + _Image.Width / 2 * Math.Sqrt(2)) / 2 - _Image.Width / 2) + 20; int y = Convert.ToInt32(this.Height - (_Image.Width / Math.Sqrt(2) + _Image.Width / 2 * Math.Sqrt(2)) / 2 - _Image.Height / 2) + 20; int width = _Image.Width; int height = _Image.Height; ImageAttributes imageAttr = new ImageAttributes(); ColorMatrix matrix = new ColorMatrix(); matrix.Matrix33 = 0.4f; //透明度 imageAttr.SetColorMatrix(matrix); Rectangle rect = new Rectangle(0, 0, width, height); Point[] points = { new Point(0 - width / 2, 0 - height / 2), new Point(width - width / 2, 0 - height / 2), new Point(0 - width / 2, height - height / 2) }; Matrix matrixRotate = new Matrix(1, 0, 0, 1, x + width / 2, y + height / 2);// 定义一个UNIT矩阵,坐标原点在(x,y) matrixRotate.Rotate(-45); // 逆时针旋转45度 //matrix.Scale((float)2, (float)2); // X 和 Y 方向分别乘以0.63和0.6比例因子 matrixRotate.TransformPoints(points);// 用该矩阵转换points g.DrawImage(_Image, points, rect, GraphicsUnit.Pixel, imageAttr); } catch { } //try //{ // if (_Image == null) // { // return; // } // Graphics g = e.Graphics; // int x = this.Width / 3 * 2 - _Image.Width / 2; // int y = this.Height / 3 * 2 - _Image.Height / 2; // int width = _Image.Width; // int height = _Image.Height; // g.DrawImage(_Image, x, y, width, height); //} //catch (Exception ex) //{ // throw ex; //} } #endregion } }