Converter.DesignExt.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Windows.Forms;
  4. namespace FastReport.Utils
  5. {
  6. public partial class Converter
  7. {
  8. internal static Dictionary<Keys, string> ValidShortcutKeys = new Dictionary<Keys, string>()
  9. {
  10. { Keys.ShiftKey, "Shift" },
  11. { Keys.ControlKey, "Ctrl" },
  12. { Keys.Menu, "Alt" },
  13. { Keys.LShiftKey, "LShift" },
  14. { Keys.RShiftKey, "RShift" },
  15. { Keys.LControlKey, "LCtrl" },
  16. { Keys.RControlKey, "RCtrl" },
  17. { Keys.LMenu, "LAlt" },
  18. { Keys.RMenu, "RAlt" },
  19. { Keys.A, "A" },
  20. { Keys.B, "B" },
  21. { Keys.C, "C" },
  22. { Keys.D, "D" },
  23. { Keys.D0, "0" },
  24. { Keys.D1, "1" },
  25. { Keys.D2, "2" },
  26. { Keys.D3, "3" },
  27. { Keys.D4, "4" },
  28. { Keys.D5, "5" },
  29. { Keys.D6, "6" },
  30. { Keys.D7, "7" },
  31. { Keys.D8, "8" },
  32. { Keys.D9, "9" },
  33. { Keys.Delete, "Delete" },
  34. { Keys.Down, "Down" },
  35. { Keys.E, "E" },
  36. { Keys.End, "End" },
  37. { Keys.F, "F" },
  38. { Keys.F1, "F1" },
  39. { Keys.F10, "F10" },
  40. { Keys.F11, "F11" },
  41. { Keys.F12, "F12" },
  42. { Keys.F13, "F13" },
  43. { Keys.F14, "F14" },
  44. { Keys.F15, "F15" },
  45. { Keys.F16, "F16" },
  46. { Keys.F17, "F17" },
  47. { Keys.F18, "F18" },
  48. { Keys.F19, "F19" },
  49. { Keys.F2, "F2" },
  50. { Keys.F20, "F20" },
  51. { Keys.F21, "F21" },
  52. { Keys.F22, "F22" },
  53. { Keys.F23, "F23" },
  54. { Keys.F24, "F24" },
  55. { Keys.F3, "F3" },
  56. { Keys.F4, "F4" },
  57. { Keys.F5, "F5" },
  58. { Keys.F6, "F6" },
  59. { Keys.F7, "F7" },
  60. { Keys.F8, "F8" },
  61. { Keys.F9, "F9" },
  62. { Keys.G, "G" },
  63. { Keys.H, "H" },
  64. { Keys.I, "I" },
  65. { Keys.Insert, "Insert" },
  66. { Keys.J, "J" },
  67. { Keys.K, "K" },
  68. { Keys.L, "L" },
  69. { Keys.Left, "Left" },
  70. { Keys.M, "M" },
  71. { Keys.N, "N" },
  72. { Keys.NumLock, "NumLock" },
  73. { Keys.NumPad0, "NumPad0" },
  74. { Keys.NumPad1, "NumPad1" },
  75. { Keys.NumPad2, "NumPad2" },
  76. { Keys.NumPad3, "NumPad3" },
  77. { Keys.NumPad4, "NumPad4" },
  78. { Keys.NumPad5, "NumPad5" },
  79. { Keys.NumPad6, "NumPad6" },
  80. { Keys.NumPad7, "NumPad7" },
  81. { Keys.NumPad8, "NumPad8" },
  82. { Keys.NumPad9, "NumPad9" },
  83. { Keys.O, "O" },
  84. { Keys.OemBackslash, "\\" },
  85. { Keys.OemClear, "Clear" },
  86. { Keys.OemCloseBrackets, "]" },
  87. { Keys.Oemcomma, "," },
  88. { Keys.OemMinus, "-" },
  89. { Keys.OemOpenBrackets, "[" },
  90. { Keys.OemPeriod, "." },
  91. { Keys.OemPipe, "|" },
  92. { Keys.Oemplus, "+" },
  93. { Keys.OemQuestion, "?" },
  94. { Keys.OemQuotes, "\"" },
  95. { Keys.OemSemicolon, ";" },
  96. { Keys.Oemtilde, "~" },
  97. { Keys.P, "P" },
  98. { Keys.Pause, "Pause" },
  99. { Keys.Q, "Q" },
  100. { Keys.R, "R" },
  101. { Keys.Right, "Right" },
  102. { Keys.S, "S" },
  103. { Keys.Space, "Space" },
  104. { Keys.T, "T" },
  105. { Keys.Tab, "Tab" },
  106. { Keys.U, "U" },
  107. { Keys.Up, "Up" },
  108. { Keys.V, "V" },
  109. { Keys.W, "W" },
  110. { Keys.X, "X" },
  111. { Keys.Y, "Y" },
  112. { Keys.Z, "Z" },
  113. { Keys.Alt, "Alt" },
  114. { Keys.Shift, "Shift" },
  115. { Keys.Control, "Ctrl" },
  116. };
  117. internal static string ShortcutKeysToStr(Keys key)
  118. {
  119. List<string> result = new List<string>();
  120. var keys = ValidShortcutKeys.Keys.ToList();
  121. keys.Sort();
  122. keys.Reverse();
  123. foreach (var k in keys)
  124. {
  125. if (key.HasFlag(k))
  126. {
  127. result.Add(ValidShortcutKeys[k]);
  128. key &= ~k;
  129. }
  130. }
  131. if (key != Keys.None)
  132. result.Add(key.ToString());
  133. else if (result.Count == 0)
  134. result.Add("None");
  135. if (result.Contains("LShift") || result.Contains("RShift") || result.FindAll((string s) => s == "Shift").Count > 1)
  136. result.Remove("Shift");
  137. if (result.Contains("LCtrl") || result.Contains("RCtrl") || result.FindAll((string s) => s == "Ctrl").Count > 1)
  138. result.Remove("Ctrl");
  139. if (result.Contains("LAlt") || result.Contains("RAlt") || result.FindAll((string s) => s == "Alt").Count > 1)
  140. result.Remove("Alt");
  141. return string.Join(" + ", result.ToArray());
  142. }
  143. }
  144. }