U_VLine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. using System;
  2. using System.ComponentModel;
  3. using System.Diagnostics;
  4. using System.Drawing;
  5. using System.Reflection;
  6. using System.Windows.Forms;
  7. using Microsoft.VisualBasic;
  8. using Microsoft.VisualBasic.CompilerServices;
  9. namespace Dongke.IBOSS.PRD.Framework.Controls
  10. {
  11. [Browsable(false)]
  12. [ToolboxItem(false)]
  13. [DesignerGenerated]
  14. [EditorBrowsable(EditorBrowsableState.Never)]
  15. public class U_VLine : UserControl, ICustomTypeDescriptor, IControl
  16. {
  17. private class XpropDescriptor : PropertyDescriptor
  18. {
  19. private string theProp;
  20. private U_VLine mycc;
  21. public override Type ComponentType => GetType();
  22. public override bool IsReadOnly => false;
  23. public override Type PropertyType
  24. {
  25. get
  26. {
  27. switch (theProp.ToLower())
  28. {
  29. case "isprint":
  30. return mycc.IsPrint.GetType();
  31. case "x":
  32. return mycc.X.GetType();
  33. case "y":
  34. return mycc.Y.GetType();
  35. case "eheight":
  36. return mycc.EHeight.GetType();
  37. case "linewidth":
  38. return mycc.LineWidth.GetType();
  39. case "linecolor":
  40. return mycc.LineColor.GetType();
  41. default:
  42. Interaction.MsgBox("Property过程编程错误,属性名称[" + theProp + "]未找到");
  43. return null;
  44. }
  45. }
  46. }
  47. public XpropDescriptor(U_VLine cc, string prop, Attribute[] attrs)
  48. : base(prop, attrs)
  49. {
  50. theProp = cc.GetPropertyEnglishName(prop);
  51. mycc = cc;
  52. }
  53. public override bool CanResetValue(object component)
  54. {
  55. return false;
  56. }
  57. public override object GetValue(object component)
  58. {
  59. switch (theProp.ToLower())
  60. {
  61. case "isprint":
  62. return mycc.IsPrint;
  63. case "x":
  64. return mycc.X;
  65. case "y":
  66. return mycc.Y;
  67. case "eheight":
  68. return mycc.EHeight;
  69. case "linewidth":
  70. return mycc.LineWidth;
  71. case "linecolor":
  72. return mycc.LineColor;
  73. default:
  74. Interaction.MsgBox("GetValue过程编程错误,属性名称[" + theProp + "]未找到");
  75. return null;
  76. }
  77. }
  78. public override void ResetValue(object component)
  79. {
  80. }
  81. public override void SetValue(object component, object value)
  82. {
  83. switch (theProp.ToLower())
  84. {
  85. case "isprint":
  86. mycc.IsPrint = Conversions.ToBoolean(value);
  87. break;
  88. case "x":
  89. mycc.X = Conversions.ToSingle(value);
  90. break;
  91. case "y":
  92. mycc.Y = Conversions.ToSingle(value);
  93. break;
  94. case "eheight":
  95. mycc.EHeight = Conversions.ToSingle(value);
  96. break;
  97. case "linewidth":
  98. mycc.LineWidth = Conversions.ToSingle(value);
  99. break;
  100. case "linecolor":
  101. {
  102. Color black = Color.Black;
  103. mycc.LineColor = ((value != null) ? ((Color)value) : black);
  104. break;
  105. }
  106. default:
  107. Interaction.MsgBox("SetValue过程编程错误,属性名称[" + theProp + "]未找到");
  108. break;
  109. }
  110. }
  111. public override bool ShouldSerializeValue(object component)
  112. {
  113. return false;
  114. }
  115. }
  116. private IContainer components;
  117. private float MYX;
  118. private float MYY;
  119. private bool theisprint;
  120. private float thelinewidth;
  121. private Color thelinecolor;
  122. public string[,] DefineProperty;
  123. private float GetX => MYX;
  124. private float GetY => MYY;
  125. [Description("以套打模式打印或预览时,是否打印该控件的内容")]
  126. [Category("行为")]
  127. public bool IsPrint
  128. {
  129. get
  130. {
  131. return theisprint;
  132. }
  133. set
  134. {
  135. theisprint = value;
  136. }
  137. }
  138. [Description("控件所处的X位置,以十分之一毫米为计量单位")]
  139. [Category("布局")]
  140. public float X
  141. {
  142. get
  143. {
  144. return ConvertToMM(base.Left, isX: true);
  145. }
  146. set
  147. {
  148. base.Left = checked((int)Math.Round(ConvertFromMM(value, isx: true)));
  149. }
  150. }
  151. [Description("控件所处的Y位置,以十分之一毫米为计量单位")]
  152. [Category("布局")]
  153. public float Y
  154. {
  155. get
  156. {
  157. return ConvertToMM(base.Top, isX: false);
  158. }
  159. set
  160. {
  161. base.Top = checked((int)Math.Round(ConvertFromMM(value, isx: false)));
  162. }
  163. }
  164. [Description("控件的高度,以毫米为计量单位")]
  165. [Category("布局")]
  166. public float EHeight
  167. {
  168. get
  169. {
  170. return ConvertToMM(base.Height, isX: false);
  171. }
  172. set
  173. {
  174. base.Height = checked((int)Math.Round(ConvertFromMM(value, isx: false)));
  175. }
  176. }
  177. [Description("直线的线宽,不是直线的长度,以毫米为计量单位,最小必须为0.15")]
  178. [Category("外观")]
  179. public float LineWidth
  180. {
  181. get
  182. {
  183. return thelinewidth;
  184. }
  185. set
  186. {
  187. if ((double)value < 0.15)
  188. {
  189. value = 0.15f;
  190. }
  191. thelinewidth = value;
  192. base.Width = checked((int)Math.Round(ConvertFromMM(value, isx: true)));
  193. Invalidate();
  194. }
  195. }
  196. [Category("外观")]
  197. [Description("线条颜色")]
  198. public Color LineColor
  199. {
  200. get
  201. {
  202. return thelinecolor;
  203. }
  204. set
  205. {
  206. thelinecolor = value;
  207. Invalidate();
  208. }
  209. }
  210. [DebuggerNonUserCode]
  211. protected override void Dispose(bool disposing)
  212. {
  213. try
  214. {
  215. if (disposing && components != null)
  216. {
  217. components.Dispose();
  218. }
  219. }
  220. finally
  221. {
  222. base.Dispose(disposing);
  223. }
  224. }
  225. [System.Diagnostics.DebuggerStepThrough]
  226. private void InitializeComponent()
  227. {
  228. base.SuspendLayout();
  229. System.Drawing.SizeF sizeF = new System.Drawing.SizeF(6f, 12f);
  230. base.AutoScaleDimensions = sizeF;
  231. base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  232. this.BackColor = System.Drawing.Color.White;
  233. base.Name = "VLine";
  234. System.Drawing.Size size = new System.Drawing.Size(169, 37);
  235. base.Size = size;
  236. base.ResumeLayout(false);
  237. }
  238. public float ConvertToMM(float tt, bool isX)
  239. {
  240. if (isX)
  241. {
  242. return (float)Math.Round((double)(tt / MYX) * 2.54 * 10.0, 2);
  243. }
  244. return (float)Math.Round((double)(tt / MYY) * 2.54 * 10.0, 2);
  245. }
  246. public float ConvertFromMM(float tt, bool isx)
  247. {
  248. if (isx)
  249. {
  250. return (float)((double)(tt * MYX) / 2.54 / 10.0);
  251. }
  252. return (float)((double)(tt * MYY) / 2.54 / 10.0);
  253. }
  254. public string GetPropertyEnglishName(string cname)
  255. {
  256. bool flag = false;
  257. int num = 0;
  258. checked
  259. {
  260. int num2 = DefineProperty.GetLength(0) - 1;
  261. int i;
  262. for (i = num; i <= num2; i++)
  263. {
  264. if (Operators.CompareString(DefineProperty[i, 1].ToUpper(), cname.ToUpper(), TextCompare: false) == 0)
  265. {
  266. flag = true;
  267. break;
  268. }
  269. }
  270. if (flag)
  271. {
  272. return DefineProperty[i, 0];
  273. }
  274. return cname;
  275. }
  276. }
  277. public string GetPropertyChineseName(string ename)
  278. {
  279. bool flag = false;
  280. int num = 0;
  281. checked
  282. {
  283. int num2 = DefineProperty.GetLength(0) - 1;
  284. int i;
  285. for (i = num; i <= num2; i++)
  286. {
  287. if (Operators.CompareString(DefineProperty[i, 0].ToUpper(), ename.ToUpper(), TextCompare: false) == 0)
  288. {
  289. flag = true;
  290. break;
  291. }
  292. }
  293. if (flag)
  294. {
  295. return DefineProperty[i, 1];
  296. }
  297. return ename;
  298. }
  299. }
  300. protected override void OnPaint(PaintEventArgs e)
  301. {
  302. base.OnPaint(e);
  303. float num = ConvertFromMM(LineWidth, isx: true);
  304. Pen pen = new Pen(LineColor, num);
  305. e.Graphics.DrawLine(pen, num / 2f, 0f, num / 2f, base.Height);
  306. }
  307. protected override void OnResize(EventArgs e)
  308. {
  309. base.OnResize(e);
  310. Invalidate();
  311. }
  312. public U_VLine()
  313. {
  314. base.Disposed += VLine_Disposed;
  315. theisprint = true;
  316. thelinewidth = 0.25f;
  317. thelinecolor = Color.Black;
  318. DefineProperty = new string[3, 2];
  319. InitializeComponent();
  320. MYX = CreateGraphics().DpiX;
  321. MYY = CreateGraphics().DpiY;
  322. DefineProperty = new string[6, 2];
  323. DefineProperty[0, 0] = "IsPrint";
  324. DefineProperty[0, 1] = "是否套打";
  325. DefineProperty[1, 0] = "X";
  326. DefineProperty[1, 1] = "X位置";
  327. DefineProperty[2, 0] = "Y";
  328. DefineProperty[2, 1] = "Y位置";
  329. DefineProperty[3, 0] = "EHeight";
  330. DefineProperty[3, 1] = "高度";
  331. DefineProperty[4, 0] = "LineWidth";
  332. DefineProperty[4, 1] = "线宽";
  333. DefineProperty[5, 0] = "LineColor";
  334. DefineProperty[5, 1] = "线条颜色";
  335. }
  336. public AttributeCollection GetAttributes()
  337. {
  338. return TypeDescriptor.GetAttributes(this, noCustomTypeDesc: true);
  339. }
  340. public string GetClassName()
  341. {
  342. return TypeDescriptor.GetClassName(this, noCustomTypeDesc: true);
  343. }
  344. public string GetComponentName()
  345. {
  346. return TypeDescriptor.GetClassName(this, noCustomTypeDesc: true);
  347. }
  348. public TypeConverter GetConverter()
  349. {
  350. return TypeDescriptor.GetConverter(this, noCustomTypeDesc: true);
  351. }
  352. public EventDescriptor GetDefaultEvent()
  353. {
  354. return TypeDescriptor.GetDefaultEvent(this, noCustomTypeDesc: true);
  355. }
  356. public PropertyDescriptor GetDefaultProperty()
  357. {
  358. return TypeDescriptor.GetDefaultProperty(this, noCustomTypeDesc: true);
  359. }
  360. public object GetEditor(Type editorBaseType)
  361. {
  362. return TypeDescriptor.GetEditor(this, editorBaseType, noCustomTypeDesc: true);
  363. }
  364. public EventDescriptorCollection GetEvents()
  365. {
  366. return TypeDescriptor.GetEvents(this, noCustomTypeDesc: true);
  367. }
  368. public EventDescriptorCollection GetEvents(Attribute[] attributes)
  369. {
  370. return TypeDescriptor.GetEvents(this, attributes, noCustomTypeDesc: true);
  371. }
  372. public PropertyDescriptorCollection GetProperties()
  373. {
  374. return TypeDescriptor.GetProperties(this, noCustomTypeDesc: true);
  375. }
  376. public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
  377. {
  378. checked
  379. {
  380. PropertyDescriptor[] array = new PropertyDescriptor[DefineProperty.GetLength(0) - 1 + 1];
  381. int num = 0;
  382. int num2 = array.Length - 1;
  383. for (int i = num; i <= num2; i++)
  384. {
  385. Type type = GetType();
  386. PropertyInfo[] properties = type.GetProperties();
  387. PropertyInfo[] array2 = properties;
  388. foreach (PropertyInfo propertyInfo in array2)
  389. {
  390. if (Operators.CompareString(propertyInfo.Name.ToUpper(), DefineProperty[i, 0].ToUpper(), TextCompare: false) == 0)
  391. {
  392. attributes = Attribute.GetCustomAttributes(propertyInfo);
  393. break;
  394. }
  395. }
  396. array[i] = new XpropDescriptor(this, DefineProperty[i, 1], attributes);
  397. }
  398. return new PropertyDescriptorCollection(array);
  399. }
  400. }
  401. public object GetPropertyOwner(PropertyDescriptor pd)
  402. {
  403. return this;
  404. }
  405. private void VLine_Disposed(object sender, EventArgs e)
  406. {
  407. try
  408. {
  409. DefineProperty = null;
  410. }
  411. catch (Exception projectError)
  412. {
  413. ProjectData.SetProjectError(projectError);
  414. ProjectData.ClearProjectError();
  415. }
  416. }
  417. public void RestoreFromString(string ss)
  418. {
  419. string[] array = Strings.Split(ss, mbsjmodule.G_MB_Spetator_Proper);
  420. if (Operators.CompareString(array[0], "1", TextCompare: false) == 0)
  421. {
  422. IsPrint = true;
  423. }
  424. else
  425. {
  426. IsPrint = false;
  427. }
  428. X = Conversions.ToSingle(array[1]);
  429. Y = Conversions.ToSingle(array[2]);
  430. EHeight = Conversions.ToSingle(array[3]);
  431. LineWidth = Conversions.ToSingle(array[4]);
  432. LineColor = Module1.ConvertStringToColor(array[5]);
  433. base.Tag = "竖线";
  434. }
  435. public string SaveAsString()
  436. {
  437. string text = ((!IsPrint) ? "0" : "1");
  438. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(X);
  439. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Y);
  440. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(EHeight);
  441. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(LineWidth);
  442. return text + mbsjmodule.G_MB_Spetator_Proper + Module1.ConvertColorToString(LineColor);
  443. }
  444. }
  445. }