using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Design; using System.Reflection; using System.Windows.Forms; using Microsoft.VisualBasic; using Microsoft.VisualBasic.CompilerServices; namespace Dongke.IBOSS.PRD.Framework.Controls { [DesignerGenerated] [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [ToolboxItem(false)] public class U_Image : UserControl, ICustomTypeDescriptor, IControl { private class XpropDescriptor : PropertyDescriptor { private string theProp; private U_Image mycc; public override Type ComponentType => GetType(); public override bool IsReadOnly => false; public override Type PropertyType { get { switch (theProp.ToLower()) { case "isprint": return mycc.IsPrint.GetType(); case "x": return mycc.X.GetType(); case "y": return mycc.Y.GetType(); case "ewidth": return mycc.EWidth.GetType(); case "eheight": return mycc.EHeight.GetType(); case "linewidth": return mycc.LineWidth.GetType(); case "linecolor": return mycc.LineColor.GetType(); case "leftborder": return mycc.LeftBorder.GetType(); case "rightborder": return mycc.RightBorder.GetType(); case "topborder": return mycc.TopBorder.GetType(); case "bottomborder": return mycc.BottomBorder.GetType(); case "img": return typeof(Image); case "picturevar": return mycc.PictureVar.GetType(); case "layerout": return mycc.LayerOut.GetType(); case "valign": return mycc.Valign.GetType(); case "halign": return mycc.Halign.GetType(); default: Interaction.MsgBox("Property过程编程错误,属性名称[" + theProp + "]未找到"); return null; } } } public XpropDescriptor(U_Image cc, string prop, Attribute[] attrs) : base(prop, attrs) { theProp = cc.GetPropertyEnglishName(prop); mycc = cc; } public override bool CanResetValue(object component) { return false; } public override object GetValue(object component) { switch (theProp.ToLower()) { case "isprint": return mycc.IsPrint; case "x": return mycc.X; case "y": return mycc.Y; case "ewidth": return mycc.EWidth; case "eheight": return mycc.EHeight; case "linewidth": return mycc.LineWidth; case "linecolor": return mycc.LineColor; case "leftborder": return mycc.LeftBorder; case "rightborder": return mycc.RightBorder; case "topborder": return mycc.TopBorder; case "bottomborder": return mycc.BottomBorder; case "img": return mycc.Img; case "picturevar": return mycc.PictureVar; case "layerout": return mycc.LayerOut; case "valign": return mycc.Valign; case "halign": return mycc.Halign; default: Interaction.MsgBox("GetValue过程编程错误,属性名称[" + theProp + "]未找到"); return null; } } public override void ResetValue(object component) { } public override void SetValue(object component, object value) { switch (theProp.ToLower()) { case "isprint": mycc.IsPrint = Conversions.ToBoolean(value); break; case "x": mycc.X = Conversions.ToSingle(value); break; case "y": mycc.Y = Conversions.ToSingle(value); break; case "ewidth": mycc.EWidth = Conversions.ToSingle(value); break; case "eheight": mycc.EHeight = Conversions.ToSingle(value); break; case "linewidth": mycc.LineWidth = Conversions.ToSingle(value); break; case "linecolor": { Color black = Color.Black; mycc.LineColor = ((value != null) ? ((Color)value) : black); break; } case "leftborder": mycc.LeftBorder = Conversions.ToBoolean(value); break; case "rightborder": mycc.RightBorder = Conversions.ToBoolean(value); break; case "topborder": mycc.TopBorder = Conversions.ToBoolean(value); break; case "bottomborder": mycc.BottomBorder = Conversions.ToBoolean(value); break; case "img": mycc.Img = (Image)value; break; case "picturevar": mycc.PictureVar = Conversions.ToString(value); break; case "layerout": mycc.LayerOut = (DataGridViewImageCellLayout)Conversions.ToInteger(value); break; case "valign": mycc.Valign = (StringAlignment)Conversions.ToInteger(value); break; case "halign": mycc.Halign = (StringAlignment)Conversions.ToInteger(value); break; default: Interaction.MsgBox("SetValue过程编程错误,属性名称[" + theProp + "]未找到"); break; } } public override bool ShouldSerializeValue(object component) { return false; } } private IContainer components; private float MYX; private float MYY; private bool theisprint; private float thelinewidth; private Color thelinecolor; private bool theleftborder; private bool thetopborder; private bool therightborder; private bool thebottomborder; private string thepicturevar; private StringAlignment thevalign; private StringAlignment thehalign; private DataGridViewImageCellLayout thelayout; private string[,] DefineProperty; private float GetX => MYX; private float GetY => MYY; [Category("布局")] [Description("图片垂直对齐方式,打印时有效")] public StringAlignment Valign { get { return thevalign; } set { thevalign = value; } } [Category("布局")] [Description("图片水平对齐方式,打印时有效")] public StringAlignment Halign { get { return thehalign; } set { thehalign = value; } } [Description("图片缩放设置")] [Category("布局")] public DataGridViewImageCellLayout LayerOut { get { return thelayout; } set { thelayout = value; switch (value) { case DataGridViewImageCellLayout.Stretch: BackgroundImageLayout = ImageLayout.Stretch; return; case DataGridViewImageCellLayout.Zoom: BackgroundImageLayout = ImageLayout.Zoom; return; } if ((Valign == StringAlignment.Center) & (Halign == StringAlignment.Center)) { BackgroundImageLayout = ImageLayout.Center; } else { BackgroundImageLayout = ImageLayout.None; } } } [Description("以套打模式打印或预览时,是否打印该控件的内容")] [Category("行为")] public bool IsPrint { get { return theisprint; } set { theisprint = value; } } [Category("布局")] [Description("控件所处的X位置,以毫米为计量单位")] public float X { get { return ConvertToMM(base.Left, isX: true); } set { base.Left = checked((int)Math.Round(ConvertFromMM(value, isx: true))); } } [Category("布局")] [Description("控件所处的Y位置,以毫米为计量单位")] public float Y { get { return ConvertToMM(base.Top, isX: false); } set { base.Top = checked((int)Math.Round(ConvertFromMM(value, isx: false))); } } [Category("布局")] [Description("控件的宽度,以毫米为计量单位")] public float EWidth { get { return ConvertToMM(base.Width, isX: true); } set { base.Width = checked((int)Math.Round(ConvertFromMM(value, isx: true))); } } [Description("控件的高度,以毫米为计量单位")] [Category("布局")] public float EHeight { get { return ConvertToMM(base.Height, isX: false); } set { base.Height = checked((int)Math.Round(ConvertFromMM(value, isx: false))); } } [Category("外观")] [Description("边线宽度,不是直线的长度,以毫米为计量单位, 必须大于等于0")] public float LineWidth { get { return thelinewidth; } set { if (value < 0f) { value = 0f; } thelinewidth = value; Invalidate(); } } [Category("外观")] [Description("线条颜色")] public Color LineColor { get { return thelinecolor; } set { thelinecolor = value; Invalidate(); } } [Description("是否显示左边框")] [Category("边框")] public bool LeftBorder { get { return theleftborder; } set { theleftborder = value; Invalidate(); } } [Description("是否显示右边框")] [Category("边框")] public bool RightBorder { get { return therightborder; } set { therightborder = value; Invalidate(); } } [Description("是否显示上边框")] [Category("边框")] public bool TopBorder { get { return thetopborder; } set { thetopborder = value; Invalidate(); } } [Description("是否显示下边框")] [Category("边框")] public bool BottomBorder { get { return thebottomborder; } set { thebottomborder = value; Invalidate(); } } [Category("外观")] [Description("要显示的图片(注意,如果设置了PictureVar属性且是合法的图片,则会忽略此属性而使用PictureVar属性指定的图片)")] public Image Img { get { return BackgroundImage; } set { BackgroundImage = value; Invalidate(); } } [Category("外观")] [Description("要显示的图片自定义变量(可以是图片路径字符串变量,也可以是以字符串形式表示的图片的自定义变量)")] [Editor(typeof(U_Editor), typeof(UITypeEditor))] public string PictureVar { get { return thepicturevar; } set { thepicturevar = value; } } [DebuggerNonUserCode] protected override void Dispose(bool disposing) { try { if (disposing && components != null) { components.Dispose(); } } finally { base.Dispose(disposing); } } [System.Diagnostics.DebuggerStepThrough] private void InitializeComponent() { base.SuspendLayout(); System.Drawing.SizeF sizeF = new System.Drawing.SizeF(6f, 12f); base.AutoScaleDimensions = sizeF; base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.White; this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.DoubleBuffered = true; System.Windows.Forms.Padding margin = new System.Windows.Forms.Padding(0); base.Margin = margin; base.Name = "U_Image"; System.Drawing.Size size = new System.Drawing.Size(169, 37); base.Size = size; base.ResumeLayout(false); } public float ConvertToMM(float tt, bool isX) { if (isX) { return (float)Math.Round((double)(tt / MYX) * 2.54 * 10.0, 2); } return (float)Math.Round((double)(tt / MYY) * 2.54 * 10.0, 2); } public float ConvertFromMM(float tt, bool isx) { if (isx) { return (float)((double)(tt * MYX) / 2.54 / 10.0); } return (float)((double)(tt * MYY) / 2.54 / 10.0); } public string GetPropertyEnglishName(string cname) { bool flag = false; int num = 0; checked { int num2 = DefineProperty.GetLength(0) - 1; int i; for (i = num; i <= num2; i++) { if (Operators.CompareString(DefineProperty[i, 1].ToUpper(), cname.ToUpper(), TextCompare: false) == 0) { flag = true; break; } } if (flag) { return DefineProperty[i, 0]; } return cname; } } public string GetPropertyChineseName(string ename) { bool flag = false; int num = 0; checked { int num2 = DefineProperty.GetLength(0) - 1; int i; for (i = num; i <= num2; i++) { if (Operators.CompareString(DefineProperty[i, 0].ToUpper(), ename.ToUpper(), TextCompare: false) == 0) { flag = true; break; } } if (flag) { return DefineProperty[i, 1]; } return ename; } } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); float num = ConvertFromMM(LineWidth, isx: true); Pen pen = new Pen(LineColor, num); if (LeftBorder) { e.Graphics.DrawLine(pen, num / 2f, num / 2f, num / 2f, (float)base.Height - num - 1f); } if (RightBorder) { e.Graphics.DrawLine(pen, (float)base.Width - num - 1f, num / 2f, (float)base.Width - num - 1f, (float)base.Height - num - 1f); } if (TopBorder) { e.Graphics.DrawLine(pen, num / 2f, num / 2f, (float)base.Width - num - 1f, num / 2f); } if (BottomBorder) { e.Graphics.DrawLine(pen, num / 2f, (float)base.Height - num - 1f, (float)base.Width - num - 1f, (float)base.Height - num - 1f); } } protected override void OnResize(EventArgs e) { base.OnResize(e); Invalidate(); } public U_Image() { base.Disposed += U_Image_Disposed; theisprint = true; thelinewidth = 0f; thelinecolor = Color.Black; theleftborder = true; thetopborder = true; therightborder = true; thebottomborder = true; thepicturevar = ""; thevalign = StringAlignment.Center; thehalign = StringAlignment.Center; thelayout = DataGridViewImageCellLayout.Stretch; DefineProperty = new string[3, 2]; InitializeComponent(); MYX = CreateGraphics().DpiX; MYY = CreateGraphics().DpiY; DefineProperty = new string[16, 2]; DefineProperty[0, 0] = "IsPrint"; DefineProperty[0, 1] = "是否套打"; DefineProperty[1, 0] = "X"; DefineProperty[1, 1] = "X位置"; DefineProperty[2, 0] = "Y"; DefineProperty[2, 1] = "Y位置"; DefineProperty[3, 0] = "EWidth"; DefineProperty[3, 1] = "宽度"; DefineProperty[4, 0] = "LineWidth"; DefineProperty[4, 1] = "线宽"; DefineProperty[5, 0] = "LineColor"; DefineProperty[5, 1] = "线条颜色"; DefineProperty[6, 0] = "EHeight"; DefineProperty[6, 1] = "高度"; DefineProperty[7, 0] = "LeftBorder"; DefineProperty[7, 1] = "左边框"; DefineProperty[8, 0] = "RightBorder"; DefineProperty[8, 1] = "右边框"; DefineProperty[9, 0] = "TopBorder"; DefineProperty[9, 1] = "上边框"; DefineProperty[10, 0] = "BottomBorder"; DefineProperty[10, 1] = "下边框"; DefineProperty[11, 0] = "Img"; DefineProperty[11, 1] = "图片内容"; DefineProperty[12, 0] = "PictureVar"; DefineProperty[12, 1] = "图片变量"; DefineProperty[13, 0] = "LayerOut"; DefineProperty[13, 1] = "图片布局"; DefineProperty[14, 0] = "Valign"; DefineProperty[14, 1] = "垂直对齐"; DefineProperty[15, 0] = "Halign"; DefineProperty[15, 1] = "水平对齐"; } public AttributeCollection GetAttributes() { return TypeDescriptor.GetAttributes(this, noCustomTypeDesc: true); } public string GetClassName() { return TypeDescriptor.GetClassName(this, noCustomTypeDesc: true); } public string GetComponentName() { return TypeDescriptor.GetClassName(this, noCustomTypeDesc: true); } public TypeConverter GetConverter() { return TypeDescriptor.GetConverter(this, noCustomTypeDesc: true); } public EventDescriptor GetDefaultEvent() { return TypeDescriptor.GetDefaultEvent(this, noCustomTypeDesc: true); } public PropertyDescriptor GetDefaultProperty() { return TypeDescriptor.GetDefaultProperty(this, noCustomTypeDesc: true); } public object GetEditor(Type editorBaseType) { return TypeDescriptor.GetEditor(this, editorBaseType, noCustomTypeDesc: true); } public EventDescriptorCollection GetEvents() { return TypeDescriptor.GetEvents(this, noCustomTypeDesc: true); } public EventDescriptorCollection GetEvents(Attribute[] attributes) { return TypeDescriptor.GetEvents(this, attributes, noCustomTypeDesc: true); } public PropertyDescriptorCollection GetProperties() { return TypeDescriptor.GetProperties(this, noCustomTypeDesc: true); } public PropertyDescriptorCollection GetProperties(Attribute[] attributes) { checked { PropertyDescriptor[] array = new PropertyDescriptor[DefineProperty.GetLength(0) - 1 + 1]; int num = 0; int num2 = array.Length - 1; for (int i = num; i <= num2; i++) { Type type = GetType(); PropertyInfo[] properties = type.GetProperties(); PropertyInfo[] array2 = properties; foreach (PropertyInfo propertyInfo in array2) { if (Operators.CompareString(propertyInfo.Name.ToUpper(), DefineProperty[i, 0].ToUpper(), TextCompare: false) == 0) { attributes = Attribute.GetCustomAttributes(propertyInfo); break; } } array[i] = new XpropDescriptor(this, DefineProperty[i, 1], attributes); } return new PropertyDescriptorCollection(array); } } public object GetPropertyOwner(PropertyDescriptor pd) { return this; } private void U_Image_Disposed(object sender, EventArgs e) { try { DefineProperty = null; } catch (Exception projectError) { ProjectData.SetProjectError(projectError); ProjectData.ClearProjectError(); } } public void RestoreFromString(string ss) { string[] array = Strings.Split(ss, mbsjmodule.G_MB_Spetator_Proper); if (Operators.CompareString(array[0], "1", TextCompare: false) == 0) { IsPrint = true; } else { IsPrint = false; } X = Conversions.ToSingle(array[1]); Y = Conversions.ToSingle(array[2]); EWidth = Conversions.ToSingle(array[3]); LineWidth = Conversions.ToSingle(array[4]); LineColor = Module1.ConvertStringToColor(array[5]); EHeight = Conversions.ToSingle(array[6]); LeftBorder = Conversions.ToBoolean(Interaction.IIf(Operators.CompareString(array[7], "1", TextCompare: false) == 0, true, false)); RightBorder = Conversions.ToBoolean(Interaction.IIf(Operators.CompareString(array[8], "1", TextCompare: false) == 0, true, false)); TopBorder = Conversions.ToBoolean(Interaction.IIf(Operators.CompareString(array[9], "1", TextCompare: false) == 0, true, false)); BottomBorder = Conversions.ToBoolean(Interaction.IIf(Operators.CompareString(array[10], "1", TextCompare: false) == 0, true, false)); Img = Module1.ConvertStringToImage(array[11]); if (array.Length >= 13) { PictureVar = array[12]; } if (array.Length >= 16) { LayerOut = (DataGridViewImageCellLayout)Conversions.ToInteger(array[13]); Halign = (StringAlignment)Conversions.ToInteger(array[14]); Valign = (StringAlignment)Conversions.ToInteger(array[15]); } } public string SaveAsString() { string text = ((!IsPrint) ? "0" : "1"); text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(X); text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Y); text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(EWidth); text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(LineWidth); text = text + mbsjmodule.G_MB_Spetator_Proper + Module1.ConvertColorToString(LineColor); text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(EHeight); text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Interaction.IIf(LeftBorder, "1", "0")); text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Interaction.IIf(RightBorder, "1", "0")); text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Interaction.IIf(TopBorder, "1", "0")); text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Interaction.IIf(BottomBorder, "1", "0")); text = text + mbsjmodule.G_MB_Spetator_Proper + Module1.ConvertImageToString(Img); text = text + mbsjmodule.G_MB_Spetator_Proper + PictureVar; text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString((int)LayerOut); text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString((int)Halign); return text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString((int)Valign); } } }