BaoKai_202508_Wms_Jingwang_.../WMS.Ctrl/DevExpressCustom/VGridControlCustom.cs
2025-08-24 21:52:42 +08:00

186 lines
5.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
/// <summary>
/// 构造函数
/// </summary>
public VGridControlCustom()
{
InitializeComponent();
}
/// <summary>
/// 构造控件
/// </summary>
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
/// <summary>
/// 设置审核标识图片
/// </summary>
/// <param name="flag">审核标识</param>
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;
}
}
/// <summary>
/// 设置审核标识图片
/// </summary>
/// <param name="flag">图片</param>
public void SetVerifyFlagImage(Bitmap image)
{
try
{
_Image = image;
this.Invalidate();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region
/// <summary>
/// 清空审核标识图片
/// </summary>
/// <param name="flag">审核标识</param>
public void ClearVerifyFlagImage()
{
try
{
_Image = null;
this.Invalidate();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region
/// <summary>
/// 界面绘制事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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
}
}