U_Rect.cs 13 KB

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