U_Bias.cs 12 KB

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