U_Field.cs 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  1. using System;
  2. using System.ComponentModel;
  3. using System.Diagnostics;
  4. using System.Drawing;
  5. using System.Drawing.Printing;
  6. using System.Reflection;
  7. using System.Windows.Forms;
  8. using Microsoft.VisualBasic;
  9. using Microsoft.VisualBasic.CompilerServices;
  10. namespace Dongke.IBOSS.PRD.Framework.Controls
  11. {
  12. [Browsable(false)]
  13. [DesignerGenerated]
  14. [EditorBrowsable(EditorBrowsableState.Never)]
  15. [ToolboxItem(false)]
  16. public class U_Field : UserControl, ICustomTypeDescriptor, IControl
  17. {
  18. private class XpropDescriptor : PropertyDescriptor
  19. {
  20. private string theProp;
  21. private U_Field mycc;
  22. public override Type ComponentType => GetType();
  23. public override bool IsReadOnly => false;
  24. public override Type PropertyType
  25. {
  26. get
  27. {
  28. switch (theProp.ToLower())
  29. {
  30. case "isprint":
  31. return mycc.IsPrint.GetType();
  32. case "x":
  33. return mycc.X.GetType();
  34. case "y":
  35. return mycc.Y.GetType();
  36. case "ewidth":
  37. return mycc.EWidth.GetType();
  38. case "eheight":
  39. return mycc.EHeight.GetType();
  40. case "linewidth":
  41. return mycc.LineWidth.GetType();
  42. case "linecolor":
  43. return mycc.LineColor.GetType();
  44. case "filledcolor":
  45. return mycc.FilledColor.GetType();
  46. case "textalign":
  47. return mycc.TextAlign.GetType();
  48. case "textvalue":
  49. return mycc.TextValue.GetType();
  50. case "textfont":
  51. return mycc.TextFont.GetType();
  52. case "textcolor":
  53. return mycc.TextColor.GetType();
  54. case "cols":
  55. return mycc.Cols.GetType();
  56. case "mulline":
  57. return mycc.Mulline.GetType();
  58. case "leftborder":
  59. return mycc.LeftBorder.GetType();
  60. case "rightborder":
  61. return mycc.RightBorder.GetType();
  62. case "topborder":
  63. return mycc.TopBorder.GetType();
  64. case "bottomborder":
  65. return mycc.BottomBorder.GetType();
  66. case "margins":
  67. return mycc.Margins.GetType();
  68. case "direction":
  69. return mycc.Direction.GetType();
  70. case "beforetext":
  71. return mycc.BeforeText.GetType();
  72. case "format":
  73. return mycc.Format.GetType();
  74. case "istdborder":
  75. return mycc.IsTdBorder.GetType();
  76. case "istdbackcolor":
  77. return mycc.IsTdBackColor.GetType();
  78. case "columntype":
  79. return mycc.ColumnType.GetType();
  80. default:
  81. Interaction.MsgBox("Property过程编程错误,属性名称[" + theProp + "]未找到");
  82. return null;
  83. }
  84. }
  85. }
  86. public XpropDescriptor(U_Field cc, string prop, Attribute[] attrs)
  87. : base(prop, attrs)
  88. {
  89. theProp = cc.GetPropertyEnglishName(prop);
  90. mycc = cc;
  91. }
  92. public override bool CanResetValue(object component)
  93. {
  94. return false;
  95. }
  96. public override object GetValue(object component)
  97. {
  98. switch (theProp.ToLower())
  99. {
  100. case "isprint":
  101. return mycc.IsPrint;
  102. case "x":
  103. return mycc.X;
  104. case "y":
  105. return mycc.Y;
  106. case "ewidth":
  107. return mycc.EWidth;
  108. case "eheight":
  109. return mycc.EHeight;
  110. case "linewidth":
  111. return mycc.LineWidth;
  112. case "linecolor":
  113. return mycc.LineColor;
  114. case "filledcolor":
  115. return mycc.FilledColor;
  116. case "textalign":
  117. return mycc.TextAlign;
  118. case "textvalue":
  119. return mycc.TextValue;
  120. case "textfont":
  121. return mycc.TextFont;
  122. case "textcolor":
  123. return mycc.TextColor;
  124. case "cols":
  125. return mycc.Cols;
  126. case "mulline":
  127. return mycc.Mulline;
  128. case "leftborder":
  129. return mycc.LeftBorder;
  130. case "rightborder":
  131. return mycc.RightBorder;
  132. case "topborder":
  133. return mycc.TopBorder;
  134. case "bottomborder":
  135. return mycc.BottomBorder;
  136. case "margins":
  137. return mycc.Margins;
  138. case "direction":
  139. return mycc.Direction;
  140. case "beforetext":
  141. return mycc.BeforeText;
  142. case "format":
  143. return mycc.Format;
  144. case "istdborder":
  145. return mycc.IsTdBorder;
  146. case "istdbackcolor":
  147. return mycc.IsTdBackColor;
  148. case "columntype":
  149. return mycc.ColumnType;
  150. default:
  151. Interaction.MsgBox("GetValue过程编程错误,属性名称[" + theProp + "]未找到");
  152. return null;
  153. }
  154. }
  155. public override void ResetValue(object component)
  156. {
  157. }
  158. public override void SetValue(object component, object value)
  159. {
  160. switch (theProp.ToLower())
  161. {
  162. case "isprint":
  163. mycc.IsPrint = Conversions.ToBoolean(value);
  164. break;
  165. case "x":
  166. mycc.X = Conversions.ToSingle(value);
  167. break;
  168. case "y":
  169. mycc.Y = Conversions.ToSingle(value);
  170. break;
  171. case "ewidth":
  172. mycc.EWidth = Conversions.ToSingle(value);
  173. break;
  174. case "eheight":
  175. mycc.EHeight = Conversions.ToSingle(value);
  176. break;
  177. case "linewidth":
  178. mycc.LineWidth = Conversions.ToSingle(value);
  179. break;
  180. case "linecolor":
  181. {
  182. Color black3 = Color.Black;
  183. mycc.LineColor = ((value != null) ? ((Color)value) : black3);
  184. break;
  185. }
  186. case "filledcolor":
  187. {
  188. Color black2 = Color.Black;
  189. mycc.FilledColor = ((value != null) ? ((Color)value) : black2);
  190. break;
  191. }
  192. case "textalign":
  193. mycc.TextAlign = (ContentAlignment)Conversions.ToInteger(value);
  194. break;
  195. case "textvalue":
  196. mycc.TextValue = Conversions.ToString(value);
  197. break;
  198. case "textfont":
  199. mycc.TextFont = (Font)value;
  200. break;
  201. case "textcolor":
  202. {
  203. Color black = Color.Black;
  204. mycc.TextColor = ((value != null) ? ((Color)value) : black);
  205. break;
  206. }
  207. case "cols":
  208. mycc.Cols = Conversions.ToInteger(value);
  209. break;
  210. case "mulline":
  211. mycc.Mulline = Conversions.ToBoolean(value);
  212. break;
  213. case "leftborder":
  214. mycc.LeftBorder = Conversions.ToBoolean(value);
  215. break;
  216. case "rightborder":
  217. mycc.RightBorder = Conversions.ToBoolean(value);
  218. break;
  219. case "topborder":
  220. mycc.TopBorder = Conversions.ToBoolean(value);
  221. break;
  222. case "bottomborder":
  223. mycc.BottomBorder = Conversions.ToBoolean(value);
  224. break;
  225. case "margins":
  226. mycc.Margins = (Margins)value;
  227. break;
  228. case "direction":
  229. mycc.Direction = Conversions.ToBoolean(value);
  230. break;
  231. case "beforetext":
  232. mycc.BeforeText = Conversions.ToString(value);
  233. break;
  234. case "format":
  235. mycc.Format = Conversions.ToString(value);
  236. break;
  237. case "istdborder":
  238. mycc.IsTdBorder = Conversions.ToBoolean(value);
  239. break;
  240. case "istdbackcolor":
  241. mycc.IsTdBackColor = Conversions.ToBoolean(value);
  242. break;
  243. case "columntype":
  244. mycc.ColumnType = Conversions.ToString(value);
  245. break;
  246. default:
  247. Interaction.MsgBox("SetValue过程编程错误,属性名称[" + theProp + "]未找到");
  248. break;
  249. }
  250. }
  251. public override bool ShouldSerializeValue(object component)
  252. {
  253. return false;
  254. }
  255. }
  256. private IContainer components;
  257. private float MYX;
  258. private float MYY;
  259. private bool theisprint;
  260. private float thelinewidth;
  261. private Color thelinecolor;
  262. private Color thefilledcolor;
  263. private ContentAlignment thetextalign;
  264. private string thetext;
  265. private Font thetextfont;
  266. private Color thetextcolor;
  267. private int thecols;
  268. private bool themulline;
  269. private bool theleftborder;
  270. private bool thetopborder;
  271. private bool therightborder;
  272. private bool thebottomborder;
  273. private Margins themargins;
  274. private bool thedirection;
  275. private string thebeforetext;
  276. private string theformat;
  277. private bool theistdborder;
  278. private bool theistdbackcolor;
  279. private string thecolumntype;
  280. private string[,] DefineProperty;
  281. private float GetX => MYX;
  282. private float GetY => MYY;
  283. [Category("行为")]
  284. [Description("以套打模式打印或预览时,是否打印该控件的背景颜色(填充颜色)")]
  285. public bool IsTdBackColor
  286. {
  287. get
  288. {
  289. return theistdbackcolor;
  290. }
  291. set
  292. {
  293. theistdbackcolor = value;
  294. }
  295. }
  296. [Category("行为")]
  297. [Description("以套打模式打印或预览时,是否打印该控件的边框(如果设置为显示边框的话)")]
  298. public bool IsTdBorder
  299. {
  300. get
  301. {
  302. return theistdborder;
  303. }
  304. set
  305. {
  306. theistdborder = value;
  307. }
  308. }
  309. [Description("以套打模式打印或预览时,是否打印该控件的内容")]
  310. [Category("行为")]
  311. public bool IsPrint
  312. {
  313. get
  314. {
  315. return theisprint;
  316. }
  317. set
  318. {
  319. theisprint = value;
  320. }
  321. }
  322. [Category("布局")]
  323. [Description("控件所处的X位置,以毫米为计量单位")]
  324. public float X
  325. {
  326. get
  327. {
  328. return ConvertToMM(base.Left, isX: true);
  329. }
  330. set
  331. {
  332. base.Left = checked((int)Math.Round(ConvertFromMM(value, isx: true)));
  333. }
  334. }
  335. [Description("控件所处的Y位置,以毫米为计量单位")]
  336. [Category("布局")]
  337. public float Y
  338. {
  339. get
  340. {
  341. return ConvertToMM(base.Top, isX: false);
  342. }
  343. set
  344. {
  345. base.Top = checked((int)Math.Round(ConvertFromMM(value, isx: false)));
  346. }
  347. }
  348. [Description("控件的宽度,以毫米为计量单位")]
  349. [Category("布局")]
  350. public float EWidth
  351. {
  352. get
  353. {
  354. return ConvertToMM(base.Width, isX: true);
  355. }
  356. set
  357. {
  358. base.Width = checked((int)Math.Round(ConvertFromMM(value, isx: true)));
  359. }
  360. }
  361. [Category("布局")]
  362. [Description("控件的高度,以毫米为计量单位")]
  363. public float EHeight
  364. {
  365. get
  366. {
  367. return ConvertToMM(base.Height, isX: false);
  368. }
  369. set
  370. {
  371. base.Height = checked((int)Math.Round(ConvertFromMM(value, isx: false)));
  372. }
  373. }
  374. [Category("外观")]
  375. [Description("边线宽度,不是直线的长度,以毫米为计量单位, 必须大于等于0")]
  376. public float LineWidth
  377. {
  378. get
  379. {
  380. return thelinewidth;
  381. }
  382. set
  383. {
  384. if (value < 0f)
  385. {
  386. value = 0f;
  387. }
  388. thelinewidth = value;
  389. Invalidate();
  390. }
  391. }
  392. [Category("外观")]
  393. [Description("线条颜色")]
  394. public Color LineColor
  395. {
  396. get
  397. {
  398. return thelinecolor;
  399. }
  400. set
  401. {
  402. thelinecolor = value;
  403. Invalidate();
  404. }
  405. }
  406. [Description("文本背景颜色")]
  407. [Category("外观")]
  408. public Color FilledColor
  409. {
  410. get
  411. {
  412. return thefilledcolor;
  413. }
  414. set
  415. {
  416. thefilledcolor = value;
  417. Invalidate();
  418. }
  419. }
  420. [Description("数据对齐方式")]
  421. [Category("外观")]
  422. public ContentAlignment TextAlign
  423. {
  424. get
  425. {
  426. return thetextalign;
  427. }
  428. set
  429. {
  430. thetextalign = value;
  431. Invalidate();
  432. }
  433. }
  434. [Description("列的数据源")]
  435. [Category("数据")]
  436. [TypeConverter(typeof(mbsjmodule.StrChoice))]
  437. public string TextValue
  438. {
  439. get
  440. {
  441. return thetext;
  442. }
  443. set
  444. {
  445. thetext = value;
  446. Invalidate();
  447. }
  448. }
  449. [Category("外观")]
  450. [Description("文本字体")]
  451. public Font TextFont
  452. {
  453. get
  454. {
  455. return thetextfont;
  456. }
  457. set
  458. {
  459. if (value != null)
  460. {
  461. thetextfont = (Font)value.Clone();
  462. Invalidate();
  463. }
  464. }
  465. }
  466. [Description("文本前景颜色")]
  467. [Category("外观")]
  468. public Color TextColor
  469. {
  470. get
  471. {
  472. return thetextcolor;
  473. }
  474. set
  475. {
  476. thetextcolor = value;
  477. Invalidate();
  478. }
  479. }
  480. [Category("外观")]
  481. [Description("分散打印的列数(为1表示普通打印)")]
  482. public int Cols
  483. {
  484. get
  485. {
  486. return thecols;
  487. }
  488. set
  489. {
  490. if (value <= 0)
  491. {
  492. value = 1;
  493. }
  494. thecols = value;
  495. Invalidate();
  496. }
  497. }
  498. [Description("文本是否允许自动换行打印。若该列为图像列,则为True表示对图像进行拉伸,为False表示对图像进行缩放)")]
  499. [Category("外观")]
  500. public bool Mulline
  501. {
  502. get
  503. {
  504. return themulline;
  505. }
  506. set
  507. {
  508. themulline = value;
  509. Invalidate();
  510. }
  511. }
  512. [Description("是否显示左边框")]
  513. [Category("边框")]
  514. public bool LeftBorder
  515. {
  516. get
  517. {
  518. return theleftborder;
  519. }
  520. set
  521. {
  522. theleftborder = value;
  523. Invalidate();
  524. }
  525. }
  526. [Category("边框")]
  527. [Description("是否显示右边框")]
  528. public bool RightBorder
  529. {
  530. get
  531. {
  532. return therightborder;
  533. }
  534. set
  535. {
  536. therightborder = value;
  537. Invalidate();
  538. }
  539. }
  540. [Category("边框")]
  541. [Description("是否显示上边框")]
  542. public bool TopBorder
  543. {
  544. get
  545. {
  546. return thetopborder;
  547. }
  548. set
  549. {
  550. thetopborder = value;
  551. Invalidate();
  552. }
  553. }
  554. [Category("边框")]
  555. [Description("是否显示下边框")]
  556. public bool BottomBorder
  557. {
  558. get
  559. {
  560. return thebottomborder;
  561. }
  562. set
  563. {
  564. thebottomborder = value;
  565. Invalidate();
  566. }
  567. }
  568. [Category("外观")]
  569. [Description("单元格文本与边框的间距,计量单位为毫米,且必须是整数")]
  570. public Margins Margins
  571. {
  572. get
  573. {
  574. return themargins;
  575. }
  576. set
  577. {
  578. themargins = value;
  579. Invalidate();
  580. }
  581. }
  582. [Category("外观")]
  583. [Description("列内容前缀字符,打印在该列内容的前面")]
  584. public string BeforeText
  585. {
  586. get
  587. {
  588. return thebeforetext;
  589. }
  590. set
  591. {
  592. thebeforetext = value;
  593. Invalidate();
  594. }
  595. }
  596. [Description("列的显示格式,设计时不应用,打印或预览时才应用格式,仅对日期和数字两种数据格式有效")]
  597. [Category("格式")]
  598. public string Format
  599. {
  600. get
  601. {
  602. return theformat;
  603. }
  604. set
  605. {
  606. theformat = value;
  607. }
  608. }
  609. [Description("列的数据类型,该属性用于 显示格式 属性。")]
  610. [TypeConverter(typeof(mbsjmodule.StrChoice3))]
  611. [Category("格式")]
  612. public string ColumnType
  613. {
  614. get
  615. {
  616. return thecolumntype;
  617. }
  618. set
  619. {
  620. thecolumntype = value;
  621. }
  622. }
  623. [Category("外观")]
  624. [Description("文本的打印方向,为False表示是从左至右的方向,为True表示从上至下的打印方向")]
  625. public bool Direction
  626. {
  627. get
  628. {
  629. return thedirection;
  630. }
  631. set
  632. {
  633. thedirection = value;
  634. Invalidate();
  635. }
  636. }
  637. [DebuggerNonUserCode]
  638. protected override void Dispose(bool disposing)
  639. {
  640. try
  641. {
  642. if (disposing && components != null)
  643. {
  644. components.Dispose();
  645. }
  646. if (thetextfont != null)
  647. {
  648. thetextfont.Dispose();
  649. }
  650. }
  651. finally
  652. {
  653. base.Dispose(disposing);
  654. }
  655. }
  656. [System.Diagnostics.DebuggerStepThrough]
  657. private void InitializeComponent()
  658. {
  659. base.SuspendLayout();
  660. System.Drawing.SizeF sizeF = new System.Drawing.SizeF(6f, 12f);
  661. base.AutoScaleDimensions = sizeF;
  662. base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  663. this.BackColor = System.Drawing.Color.Transparent;
  664. System.Windows.Forms.Padding margin = new System.Windows.Forms.Padding(0);
  665. base.Margin = margin;
  666. base.Name = "U_Field";
  667. System.Drawing.Size size = new System.Drawing.Size(169, 37);
  668. base.Size = size;
  669. base.ResumeLayout(false);
  670. }
  671. public float ConvertToMM(float tt, bool isX)
  672. {
  673. if (isX)
  674. {
  675. return (float)Math.Round((double)(tt / MYX) * 2.54 * 10.0, 2);
  676. }
  677. return (float)Math.Round((double)(tt / MYY) * 2.54 * 10.0, 2);
  678. }
  679. public float ConvertFromMM(float tt, bool isx)
  680. {
  681. if (isx)
  682. {
  683. return (float)((double)(tt * MYX) / 2.54 / 10.0);
  684. }
  685. return (float)((double)(tt * MYY) / 2.54 / 10.0);
  686. }
  687. public string GetPropertyEnglishName(string cname)
  688. {
  689. bool flag = false;
  690. int num = 0;
  691. checked
  692. {
  693. int num2 = DefineProperty.GetLength(0) - 1;
  694. int i;
  695. for (i = num; i <= num2; i++)
  696. {
  697. if (Operators.CompareString(DefineProperty[i, 1].ToUpper(), cname.ToUpper(), TextCompare: false) == 0)
  698. {
  699. flag = true;
  700. break;
  701. }
  702. }
  703. if (flag)
  704. {
  705. return DefineProperty[i, 0];
  706. }
  707. return cname;
  708. }
  709. }
  710. public string GetPropertyChineseName(string ename)
  711. {
  712. bool flag = false;
  713. int num = 0;
  714. checked
  715. {
  716. int num2 = DefineProperty.GetLength(0) - 1;
  717. int i;
  718. for (i = num; i <= num2; i++)
  719. {
  720. if (Operators.CompareString(DefineProperty[i, 0].ToUpper(), ename.ToUpper(), TextCompare: false) == 0)
  721. {
  722. flag = true;
  723. break;
  724. }
  725. }
  726. if (flag)
  727. {
  728. return DefineProperty[i, 1];
  729. }
  730. return ename;
  731. }
  732. }
  733. protected override void OnPaint(PaintEventArgs e)
  734. {
  735. base.OnPaint(e);
  736. float num = ConvertFromMM(LineWidth, isx: true);
  737. Pen pen = new Pen(LineColor, num);
  738. e.Graphics.FillRectangle(new SolidBrush(FilledColor), 0, 0, base.Width, base.Height);
  739. if (LeftBorder)
  740. {
  741. e.Graphics.DrawLine(pen, num / 2f, num / 2f, num / 2f, (float)base.Height - num);
  742. }
  743. if (RightBorder)
  744. {
  745. e.Graphics.DrawLine(pen, (float)base.Width - num, num / 2f, (float)base.Width - num, (float)base.Height - num / 2f);
  746. }
  747. if (TopBorder)
  748. {
  749. e.Graphics.DrawLine(pen, num / 2f, num / 2f, (float)base.Width - num, num / 2f);
  750. }
  751. if (BottomBorder)
  752. {
  753. e.Graphics.DrawLine(pen, num / 2f, (float)base.Height - num, (float)base.Width - num, (float)base.Height - num);
  754. }
  755. StringFormat stringFormat = new StringFormat(StringFormat.GenericTypographic);
  756. StringFormatFlags formatFlags = stringFormat.FormatFlags;
  757. formatFlags = (Mulline ? (formatFlags & ~StringFormatFlags.NoWrap) : (formatFlags | StringFormatFlags.NoWrap));
  758. formatFlags = ((!Direction) ? (formatFlags & ~StringFormatFlags.DirectionVertical) : (formatFlags | StringFormatFlags.DirectionVertical));
  759. formatFlags |= StringFormatFlags.NoClip;
  760. stringFormat.FormatFlags = formatFlags;
  761. stringFormat.Alignment = mbsjmodule.GetHalign(TextAlign);
  762. stringFormat.LineAlignment = mbsjmodule.GetValign(TextAlign);
  763. Graphics graphics = e.Graphics;
  764. string s = BeforeText + TextValue;
  765. Font textFont = TextFont;
  766. Brush brush = new SolidBrush(TextColor);
  767. checked
  768. {
  769. RectangleF layoutRectangle = new RectangleF(ConvertFromMM(Margins.Left, isx: true), ConvertFromMM(Margins.Top, isx: false), (float)base.Width - ConvertFromMM(Margins.Left + Margins.Right, isx: true), (float)base.Height - ConvertFromMM(Margins.Top + Margins.Bottom, isx: false));
  770. graphics.DrawString(s, textFont, brush, layoutRectangle, stringFormat);
  771. float num2 = (float)((double)base.Width / (double)Cols);
  772. float num3 = (float)((double)base.Height / (double)Cols);
  773. if (Direction)
  774. {
  775. int num4 = 1;
  776. int num5 = Cols - 1;
  777. for (int i = num4; i <= num5; i++)
  778. {
  779. float num6 = num3 * (float)i;
  780. e.Graphics.DrawLine(pen, num / 2f, num6 + num / 2f, base.Width, num6 + num / 2f);
  781. }
  782. }
  783. else
  784. {
  785. int num7 = 1;
  786. int num8 = Cols - 1;
  787. for (int j = num7; j <= num8; j++)
  788. {
  789. float num9 = num2 * (float)j;
  790. e.Graphics.DrawLine(pen, num9 + num / 2f, 0f, num9 + num / 2f, base.Height);
  791. }
  792. }
  793. }
  794. }
  795. protected override void OnResize(EventArgs e)
  796. {
  797. base.OnResize(e);
  798. Invalidate();
  799. }
  800. public U_Field()
  801. {
  802. base.Disposed += U_Field_Disposed;
  803. theisprint = true;
  804. thelinewidth = 0.2f;
  805. thelinecolor = Color.Black;
  806. thefilledcolor = Color.Transparent;
  807. thetextalign = ContentAlignment.MiddleLeft;
  808. thetext = "未设置数据源";
  809. thetextfont = new Font("宋体", 9f);
  810. thetextcolor = Color.Black;
  811. thecols = 1;
  812. themulline = true;
  813. theleftborder = false;
  814. thetopborder = false;
  815. therightborder = false;
  816. thebottomborder = false;
  817. themargins = new Margins(1, 1, 0, 0);
  818. thedirection = false;
  819. thebeforetext = "";
  820. theformat = "";
  821. theistdborder = false;
  822. theistdbackcolor = false;
  823. thecolumntype = "";
  824. DefineProperty = new string[3, 2];
  825. InitializeComponent();
  826. MYX = CreateGraphics().DpiX;
  827. MYY = CreateGraphics().DpiY;
  828. DefineProperty = new string[25, 2];
  829. DefineProperty[0, 0] = "IsPrint";
  830. DefineProperty[0, 1] = "是否套打";
  831. DefineProperty[1, 0] = "X";
  832. DefineProperty[1, 1] = "X位置";
  833. DefineProperty[2, 0] = "Y";
  834. DefineProperty[2, 1] = "Y位置";
  835. DefineProperty[3, 0] = "EWidth";
  836. DefineProperty[3, 1] = "宽度";
  837. DefineProperty[4, 0] = "LineWidth";
  838. DefineProperty[4, 1] = "线宽";
  839. DefineProperty[5, 0] = "LineColor";
  840. DefineProperty[5, 1] = "线条颜色";
  841. DefineProperty[6, 0] = "EHeight";
  842. DefineProperty[6, 1] = "高度";
  843. DefineProperty[7, 0] = "FilledColor";
  844. DefineProperty[7, 1] = "填充颜色";
  845. DefineProperty[8, 0] = "TextAlign";
  846. DefineProperty[8, 1] = "文本对齐方式";
  847. DefineProperty[9, 0] = "TextValue";
  848. DefineProperty[9, 1] = "数据字段";
  849. DefineProperty[10, 0] = "TextFont";
  850. DefineProperty[10, 1] = "字体";
  851. DefineProperty[11, 0] = "TextColor";
  852. DefineProperty[11, 1] = "文本颜色";
  853. DefineProperty[12, 0] = "Cols";
  854. DefineProperty[12, 1] = "分列打印";
  855. DefineProperty[13, 0] = "Mulline";
  856. DefineProperty[13, 1] = "自动换行";
  857. DefineProperty[14, 0] = "LeftBorder";
  858. DefineProperty[14, 1] = "左边框";
  859. DefineProperty[15, 0] = "RightBorder";
  860. DefineProperty[15, 1] = "右边框";
  861. DefineProperty[16, 0] = "TopBorder";
  862. DefineProperty[16, 1] = "上边框";
  863. DefineProperty[17, 0] = "BottomBorder";
  864. DefineProperty[17, 1] = "下边框";
  865. DefineProperty[18, 0] = "Margins";
  866. DefineProperty[18, 1] = "边距";
  867. DefineProperty[19, 0] = "Direction";
  868. DefineProperty[19, 1] = "文本方向";
  869. DefineProperty[20, 0] = "BeforeText";
  870. DefineProperty[20, 1] = "打印前缀";
  871. DefineProperty[21, 0] = "Format";
  872. DefineProperty[21, 1] = "显示格式";
  873. DefineProperty[22, 0] = "IsTdBorder";
  874. DefineProperty[22, 1] = "套打边框";
  875. DefineProperty[23, 0] = "IsTdBackColor";
  876. DefineProperty[23, 1] = "套打背景颜色";
  877. DefineProperty[24, 0] = "ColumnType";
  878. DefineProperty[24, 1] = "列数据类型";
  879. }
  880. public AttributeCollection GetAttributes()
  881. {
  882. return TypeDescriptor.GetAttributes(this, noCustomTypeDesc: true);
  883. }
  884. public string GetClassName()
  885. {
  886. return TypeDescriptor.GetClassName(this, noCustomTypeDesc: true);
  887. }
  888. public string GetComponentName()
  889. {
  890. return TypeDescriptor.GetClassName(this, noCustomTypeDesc: true);
  891. }
  892. public TypeConverter GetConverter()
  893. {
  894. return TypeDescriptor.GetConverter(this, noCustomTypeDesc: true);
  895. }
  896. public EventDescriptor GetDefaultEvent()
  897. {
  898. return TypeDescriptor.GetDefaultEvent(this, noCustomTypeDesc: true);
  899. }
  900. public PropertyDescriptor GetDefaultProperty()
  901. {
  902. return TypeDescriptor.GetDefaultProperty(this, noCustomTypeDesc: true);
  903. }
  904. public object GetEditor(Type editorBaseType)
  905. {
  906. return TypeDescriptor.GetEditor(this, editorBaseType, noCustomTypeDesc: true);
  907. }
  908. public EventDescriptorCollection GetEvents()
  909. {
  910. return TypeDescriptor.GetEvents(this, noCustomTypeDesc: true);
  911. }
  912. public EventDescriptorCollection GetEvents(Attribute[] attributes)
  913. {
  914. return TypeDescriptor.GetEvents(this, attributes, noCustomTypeDesc: true);
  915. }
  916. public PropertyDescriptorCollection GetProperties()
  917. {
  918. return TypeDescriptor.GetProperties(this, noCustomTypeDesc: true);
  919. }
  920. public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
  921. {
  922. checked
  923. {
  924. PropertyDescriptor[] array = new PropertyDescriptor[DefineProperty.GetLength(0) - 1 + 1];
  925. int num = 0;
  926. int num2 = array.Length - 1;
  927. for (int i = num; i <= num2; i++)
  928. {
  929. Type type = GetType();
  930. PropertyInfo[] properties = type.GetProperties();
  931. PropertyInfo[] array2 = properties;
  932. foreach (PropertyInfo propertyInfo in array2)
  933. {
  934. if (Operators.CompareString(propertyInfo.Name.ToUpper(), DefineProperty[i, 0].ToUpper(), TextCompare: false) == 0)
  935. {
  936. attributes = Attribute.GetCustomAttributes(propertyInfo);
  937. break;
  938. }
  939. }
  940. array[i] = new XpropDescriptor(this, DefineProperty[i, 1], attributes);
  941. }
  942. return new PropertyDescriptorCollection(array);
  943. }
  944. }
  945. public object GetPropertyOwner(PropertyDescriptor pd)
  946. {
  947. return this;
  948. }
  949. private void U_Field_Disposed(object sender, EventArgs e)
  950. {
  951. try
  952. {
  953. DefineProperty = null;
  954. thetextfont = null;
  955. }
  956. catch (Exception projectError)
  957. {
  958. ProjectData.SetProjectError(projectError);
  959. ProjectData.ClearProjectError();
  960. }
  961. }
  962. public void RestoreFromString(string ss)
  963. {
  964. string[] array = Strings.Split(ss, mbsjmodule.G_MB_Spetator_Proper);
  965. if (Operators.CompareString(array[0], "1", TextCompare: false) == 0)
  966. {
  967. IsPrint = true;
  968. }
  969. else
  970. {
  971. IsPrint = false;
  972. }
  973. X = Conversions.ToSingle(array[1]);
  974. Y = Conversions.ToSingle(array[2]);
  975. EWidth = Conversions.ToSingle(array[3]);
  976. LineWidth = Conversions.ToSingle(array[4]);
  977. LineColor = Module1.ConvertStringToColor(array[5]);
  978. EHeight = Conversions.ToSingle(array[6]);
  979. LeftBorder = Conversions.ToBoolean(array[7]);
  980. RightBorder = Conversions.ToBoolean(array[8]);
  981. TopBorder = Conversions.ToBoolean(array[9]);
  982. BottomBorder = Operators.CompareString(array[10], "1", TextCompare: false) == 0;
  983. FilledColor = Module1.ConvertStringToColor(array[11]);
  984. TextAlign = (ContentAlignment)Conversions.ToInteger(array[12]);
  985. TextFont = Module1.ConvertStringToFont(array[13]);
  986. TextColor = Module1.ConvertStringToColor(array[14]);
  987. Cols = Conversions.ToInteger(array[15]);
  988. Mulline = Conversions.ToBoolean(array[16]);
  989. Margins = new Margins(Conversions.ToInteger(array[17]), Conversions.ToInteger(array[18]), Conversions.ToInteger(array[19]), Conversions.ToInteger(array[20]));
  990. TextValue = array[21];
  991. BeforeText = array[22];
  992. Format = array[23];
  993. Direction = Conversions.ToBoolean(array[24]);
  994. IsTdBorder = Conversions.ToBoolean(array[25]);
  995. IsTdBackColor = Conversions.ToBoolean(array[26]);
  996. try
  997. {
  998. if (array.Length == 28)
  999. {
  1000. ColumnType = array[27];
  1001. }
  1002. }
  1003. catch (Exception projectError)
  1004. {
  1005. ProjectData.SetProjectError(projectError);
  1006. ProjectData.ClearProjectError();
  1007. }
  1008. }
  1009. public string SaveAsString()
  1010. {
  1011. string text = ((!IsPrint) ? "0" : "1");
  1012. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(X);
  1013. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Y);
  1014. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(EWidth);
  1015. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(LineWidth);
  1016. text = text + mbsjmodule.G_MB_Spetator_Proper + Module1.ConvertColorToString(LineColor);
  1017. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(EHeight);
  1018. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Interaction.IIf(LeftBorder, "1", "0"));
  1019. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Interaction.IIf(RightBorder, "1", "0"));
  1020. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Interaction.IIf(TopBorder, "1", "0"));
  1021. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Interaction.IIf(BottomBorder, "1", "0"));
  1022. text = text + mbsjmodule.G_MB_Spetator_Proper + Module1.ConvertColorToString(FilledColor);
  1023. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString((int)TextAlign);
  1024. text = text + mbsjmodule.G_MB_Spetator_Proper + Module1.ConvertFontToString(TextFont);
  1025. text = text + mbsjmodule.G_MB_Spetator_Proper + Module1.ConvertColorToString(TextColor);
  1026. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Cols);
  1027. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Interaction.IIf(Mulline, "1", "0"));
  1028. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Margins.Left);
  1029. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Margins.Right);
  1030. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Margins.Top);
  1031. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Margins.Bottom);
  1032. text = text + mbsjmodule.G_MB_Spetator_Proper + TextValue;
  1033. text = text + mbsjmodule.G_MB_Spetator_Proper + BeforeText;
  1034. text = text + mbsjmodule.G_MB_Spetator_Proper + Format;
  1035. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Interaction.IIf(Direction, "1", "0"));
  1036. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Interaction.IIf(IsTdBorder, "1", "0"));
  1037. text = text + mbsjmodule.G_MB_Spetator_Proper + Conversions.ToString(Interaction.IIf(IsTdBackColor, "1", "0"));
  1038. return text + mbsjmodule.G_MB_Spetator_Proper + ColumnType;
  1039. }
  1040. }
  1041. }