U_HLine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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. [ToolboxItem(false)]
  12. [Browsable(false)]
  13. [EditorBrowsable(EditorBrowsableState.Never)]
  14. [DesignerGenerated]
  15. public class U_HLine : UserControl, ICustomTypeDescriptor, IControl
  16. {
  17. private class XpropDescriptor : PropertyDescriptor
  18. {
  19. private string theProp;
  20. private U_HLine 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 "ewidth":
  36. return mycc.EWidth.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_HLine 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 "ewidth":
  68. return mycc.EWidth;
  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 "ewidth":
  95. mycc.EWidth = 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. private string[,] DefineProperty;
  123. [Category("行为")]
  124. [Description("以套打模式打印或预览时,是否打印该控件的内容")]
  125. public bool IsPrint
  126. {
  127. get
  128. {
  129. return theisprint;
  130. }
  131. set
  132. {
  133. theisprint = value;
  134. }
  135. }
  136. [Category("布局")]
  137. [Description("控件所处的X位置,以毫米为计量单位")]
  138. public float X
  139. {
  140. get
  141. {
  142. return ConvertToMM(base.Left, isX: true);
  143. }
  144. set
  145. {
  146. base.Left = checked((int)Math.Round(ConvertFromMM(value, isx: true)));
  147. }
  148. }
  149. [Description("控件所处的Y位置,以毫米为计量单位")]
  150. [Category("布局")]
  151. public float Y
  152. {
  153. get
  154. {
  155. return ConvertToMM(base.Top, isX: false);
  156. }
  157. set
  158. {
  159. base.Top = checked((int)Math.Round(ConvertFromMM(value, isx: false)));
  160. }
  161. }
  162. [Category("布局")]
  163. [Description("控件的宽度,以毫米为计量单位")]
  164. public float EWidth
  165. {
  166. get
  167. {
  168. return ConvertToMM(base.Width, isX: true);
  169. }
  170. set
  171. {
  172. base.Width = checked((int)Math.Round(ConvertFromMM(value, isx: true)));
  173. }
  174. }
  175. [Category("外观")]
  176. [Description("直线的线宽,不是直线的长度,以毫米为计量单位,最小必须为0.15毫米")]
  177. public float LineWidth
  178. {
  179. get
  180. {
  181. return thelinewidth;
  182. }
  183. set
  184. {
  185. if ((double)value < 0.15)
  186. {
  187. value = 0.15f;
  188. }
  189. thelinewidth = value;
  190. base.Height = checked((int)Math.Round(ConvertFromMM(value, isx: true)));
  191. Invalidate();
  192. }
  193. }
  194. [Category("外观")]
  195. [Description("线条颜色")]
  196. public Color LineColor
  197. {
  198. get
  199. {
  200. return thelinecolor;
  201. }
  202. set
  203. {
  204. thelinecolor = value;
  205. Invalidate();
  206. }
  207. }
  208. [DebuggerNonUserCode]
  209. protected override void Dispose(bool disposing)
  210. {
  211. try
  212. {
  213. if (disposing && components != null)
  214. {
  215. components.Dispose();
  216. }
  217. }
  218. finally
  219. {
  220. base.Dispose(disposing);
  221. }
  222. }
  223. [System.Diagnostics.DebuggerStepThrough]
  224. private void InitializeComponent()
  225. {
  226. base.SuspendLayout();
  227. System.Drawing.SizeF sizeF = new System.Drawing.SizeF(6f, 12f);
  228. base.AutoScaleDimensions = sizeF;
  229. base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  230. this.BackColor = System.Drawing.Color.White;
  231. base.Name = "Hline";
  232. System.Drawing.Size size = new System.Drawing.Size(169, 37);
  233. base.Size = size;
  234. base.ResumeLayout(false);
  235. }
  236. public float ConvertToMM(float tt, bool isX)
  237. {
  238. if (isX)
  239. {
  240. return (float)Math.Round((double)(tt / MYX) * 2.54 * 10.0, 2);
  241. }
  242. return (float)Math.Round((double)(tt / MYY) * 2.54 * 10.0, 2);
  243. }
  244. public float ConvertFromMM(float tt, bool isx)
  245. {
  246. if (isx)
  247. {
  248. return (float)((double)(tt * MYX) / 2.54 / 10.0);
  249. }
  250. return (float)((double)(tt * MYY) / 2.54 / 10.0);
  251. }
  252. public string GetPropertyEnglishName(string cname)
  253. {
  254. bool flag = false;
  255. int num = 0;
  256. checked
  257. {
  258. int num2 = DefineProperty.GetLength(0) - 1;
  259. int i;
  260. for (i = num; i <= num2; i++)
  261. {
  262. if (Operators.CompareString(DefineProperty[i, 1].ToUpper(), cname.ToUpper(), TextCompare: false) == 0)
  263. {
  264. flag = true;
  265. break;
  266. }
  267. }
  268. if (flag)
  269. {
  270. return DefineProperty[i, 0];
  271. }
  272. return cname;
  273. }
  274. }
  275. public string GetPropertyChineseName(string ename)
  276. {
  277. bool flag = false;
  278. int num = 0;
  279. checked
  280. {
  281. int num2 = DefineProperty.GetLength(0) - 1;
  282. int i;
  283. for (i = num; i <= num2; i++)
  284. {
  285. if (Operators.CompareString(DefineProperty[i, 0].ToUpper(), ename.ToUpper(), TextCompare: false) == 0)
  286. {
  287. flag = true;
  288. break;
  289. }
  290. }
  291. if (flag)
  292. {
  293. return DefineProperty[i, 1];
  294. }
  295. return ename;
  296. }
  297. }
  298. protected override void OnPaint(PaintEventArgs e)
  299. {
  300. base.OnPaint(e);
  301. float num = ConvertFromMM(LineWidth, isx: true);
  302. Pen pen = new Pen(LineColor, num);
  303. e.Graphics.DrawLine(pen, 0f, num / 2f, base.Width, num / 2f);
  304. }
  305. protected override void OnResize(EventArgs e)
  306. {
  307. base.OnResize(e);
  308. Invalidate();
  309. }
  310. public U_HLine()
  311. {
  312. base.Disposed += Hline_Disposed;
  313. theisprint = true;
  314. thelinewidth = 0.26f;
  315. thelinecolor = Color.Black;
  316. DefineProperty = new string[3, 2];
  317. InitializeComponent();
  318. MYX = CreateGraphics().DpiX;
  319. MYY = CreateGraphics().DpiY;
  320. DefineProperty = new string[6, 2];
  321. DefineProperty[0, 0] = "IsPrint";
  322. DefineProperty[0, 1] = "是否套打";
  323. DefineProperty[1, 0] = "X";
  324. DefineProperty[1, 1] = "X位置";
  325. DefineProperty[2, 0] = "Y";
  326. DefineProperty[2, 1] = "Y位置";
  327. DefineProperty[3, 0] = "EWidth";
  328. DefineProperty[3, 1] = "宽度";
  329. DefineProperty[4, 0] = "LineWidth";
  330. DefineProperty[4, 1] = "线宽";
  331. DefineProperty[5, 0] = "LineColor";
  332. DefineProperty[5, 1] = "线条颜色";
  333. }
  334. public AttributeCollection GetAttributes()
  335. {
  336. return TypeDescriptor.GetAttributes(this, noCustomTypeDesc: true);
  337. }
  338. public string GetClassName()
  339. {
  340. return TypeDescriptor.GetClassName(this, noCustomTypeDesc: true);
  341. }
  342. public string GetComponentName()
  343. {
  344. return TypeDescriptor.GetClassName(this, noCustomTypeDesc: true);
  345. }
  346. public TypeConverter GetConverter()
  347. {
  348. return TypeDescriptor.GetConverter(this, noCustomTypeDesc: true);
  349. }
  350. public EventDescriptor GetDefaultEvent()
  351. {
  352. return TypeDescriptor.GetDefaultEvent(this, noCustomTypeDesc: true);
  353. }
  354. public PropertyDescriptor GetDefaultProperty()
  355. {
  356. return TypeDescriptor.GetDefaultProperty(this, noCustomTypeDesc: true);
  357. }
  358. public object GetEditor(Type editorBaseType)
  359. {
  360. return TypeDescriptor.GetEditor(this, editorBaseType, noCustomTypeDesc: true);
  361. }
  362. public EventDescriptorCollection GetEvents()
  363. {
  364. return TypeDescriptor.GetEvents(this, noCustomTypeDesc: true);
  365. }
  366. public EventDescriptorCollection GetEvents(Attribute[] attributes)
  367. {
  368. return TypeDescriptor.GetEvents(this, attributes, noCustomTypeDesc: true);
  369. }
  370. public PropertyDescriptorCollection GetProperties()
  371. {
  372. return TypeDescriptor.GetProperties(this, noCustomTypeDesc: true);
  373. }
  374. public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
  375. {
  376. checked
  377. {
  378. PropertyDescriptor[] array = new PropertyDescriptor[DefineProperty.GetLength(0) - 1 + 1];
  379. int num = 0;
  380. int num2 = array.Length - 1;
  381. for (int i = num; i <= num2; i++)
  382. {
  383. Type type = GetType();
  384. PropertyInfo[] properties = type.GetProperties();
  385. PropertyInfo[] array2 = properties;
  386. foreach (PropertyInfo propertyInfo in array2)
  387. {
  388. if (Operators.CompareString(propertyInfo.Name.ToUpper(), DefineProperty[i, 0].ToUpper(), TextCompare: false) == 0)
  389. {
  390. attributes = Attribute.GetCustomAttributes(propertyInfo);
  391. break;
  392. }
  393. }
  394. array[i] = new XpropDescriptor(this, DefineProperty[i, 1], attributes);
  395. }
  396. return new PropertyDescriptorCollection(array);
  397. }
  398. }
  399. public object GetPropertyOwner(PropertyDescriptor pd)
  400. {
  401. return this;
  402. }
  403. private void Hline_Disposed(object sender, EventArgs e)
  404. {
  405. try
  406. {
  407. DefineProperty = null;
  408. }
  409. catch (Exception projectError)
  410. {
  411. ProjectData.SetProjectError(projectError);
  412. ProjectData.ClearProjectError();
  413. }
  414. }
  415. public void RestoreFromString(string ss)
  416. {
  417. string[] array = Strings.Split(ss, mbsjmodule.G_MB_Spetator_Proper);
  418. if (Operators.CompareString(array[0], "1", TextCompare: false) == 0)
  419. {
  420. IsPrint = true;
  421. }
  422. else
  423. {
  424. IsPrint = false;
  425. }
  426. X = Conversions.ToSingle(array[1]);
  427. Y = Conversions.ToSingle(array[2]);
  428. EWidth = Conversions.ToSingle(array[3]);
  429. LineWidth = Conversions.ToSingle(array[4]);
  430. LineColor = Module1.ConvertStringToColor(array[5]);
  431. base.Tag = "横线";
  432. }
  433. public string SaveAsString()
  434. {
  435. string text = ((!IsPrint) ? "0" : "1");
  436. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(X);
  437. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Y);
  438. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(EWidth);
  439. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(LineWidth);
  440. return text + mbsjmodule.G_MB_Spetator_Proper + Module1.ConvertColorToString(LineColor);
  441. }
  442. }
  443. }