AnchorTool.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using CommonUI.Display;
  5. namespace CommonUI.Tool
  6. {
  7. public class AnchorTool
  8. {
  9. public static Anchor FromString(string text)
  10. {
  11. string[] ay = text.Split('_');
  12. string h = ay[0];
  13. string v = ay[ay.Length - 1];
  14. Anchor ih = Anchor.ANCHOR_HCENTER;
  15. if (h == "L")
  16. {
  17. ih = Anchor.ANCHOR_LEFT;
  18. }
  19. else if (h == "R")
  20. {
  21. ih = Anchor.ANCHOR_RIGHT;
  22. }
  23. Anchor iv = Anchor.ANCHOR_VCENTER;
  24. if (v == "T")
  25. {
  26. iv = Anchor.ANCHOR_TOP;
  27. }
  28. else if (v == "B")
  29. {
  30. iv = Anchor.ANCHOR_BOTTOM;
  31. }
  32. return ih | iv;
  33. }
  34. public static Anchor FromTextAnchor(Data.TextAnchor ta)
  35. {
  36. Anchor ih = Anchor.ANCHOR_HCENTER;
  37. Anchor iv = Anchor.ANCHOR_VCENTER;
  38. switch (ta)
  39. {
  40. case Data.TextAnchor.L_T:
  41. ih = Anchor.ANCHOR_LEFT;
  42. iv = Anchor.ANCHOR_TOP;
  43. break;
  44. case Data.TextAnchor.C_T:
  45. iv = Anchor.ANCHOR_TOP;
  46. break;
  47. case Data.TextAnchor.R_T:
  48. ih = Anchor.ANCHOR_TOP;
  49. iv = Anchor.ANCHOR_TOP;
  50. break;
  51. case Data.TextAnchor.L_C:
  52. ih = Anchor.ANCHOR_LEFT;
  53. break;
  54. case Data.TextAnchor.C_C:
  55. break;
  56. case Data.TextAnchor.R_C:
  57. ih = Anchor.ANCHOR_RIGHT;
  58. break;
  59. case Data.TextAnchor.L_B:
  60. ih = Anchor.ANCHOR_LEFT;
  61. iv = Anchor.ANCHOR_BOTTOM;
  62. break;
  63. case Data.TextAnchor.C_B:
  64. iv = Anchor.ANCHOR_BOTTOM;
  65. break;
  66. case Data.TextAnchor.R_B:
  67. ih = Anchor.ANCHOR_RIGHT;
  68. iv = Anchor.ANCHOR_BOTTOM;
  69. break;
  70. default: break;
  71. }
  72. return ih | iv;
  73. }
  74. }
  75. }