No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

TextHelper.cs

Description du code

TextHelper.cs est un fichier du projet BrolDev.
Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/broldev/src/.

Projet BrolDev : Librairie de composants réutilisables pour les applications BrolDev en CSharp.

Code source ou contenu du fichier

  1. using System;
  2. using System.Drawing;
  3. using System.Runtime.InteropServices;
  4.  
  5. namespace be.gaudry.model
  6. {
  7. public class TextHelper
  8. {
  9. public enum KEY
  10. {
  11. CANCEL = 0x03,
  12. BACK = 0x08,
  13. TAB = 0x09,
  14. CLEAR = 0x0C,
  15. RETURN = 0x0D,
  16. SHIFT = 0x10,
  17. CONTROL = 0x11,
  18. ALT = 0x12,
  19. PAUSE = 0x13
  20. };
  21. #region key values info
  22. /*
  23.   VK_LBUTTON = 0x01,
  24. VK_RBUTTON = 0x02,
  25. VK_CANCEL = 0x03,
  26. VK_MBUTTON = 0x04 , // NOT contiguous with L & RBUTTON
  27. VK_BACK = 0x08,
  28. VK_TAB = 0x09,
  29. VK_CLEAR = 0x0C,
  30. VK_RETURN = 0x0D,
  31. VK_SHIFT = 0x10,
  32. VK_CONTROL = 0x11,
  33. VK_MENU = 0x12,
  34. VK_PAUSE = 0x13,
  35. VK_CAPITAL = 0x14,
  36. VK_KANA = 0x15,
  37. VK_HANGEUL = 0x15, // old name - should be here for compatibility
  38. VK_HANGUL = 0x15,
  39. VK_JUNJA = 0x17,
  40. VK_FINAL = 0x18,
  41. VK_HANJA = 0x19,
  42. VK_KANJI = 0x19,
  43. VK_ESCAPE = 0x1B,
  44. VK_CONVERT = 0x1C,
  45. VK_NONCONVERT = 0x1D,
  46. VK_ACCEPT = 0x1E,
  47. VK_MODECHANGE = 0x1F,
  48. VK_SPACE = 0x20,
  49. VK_PRIOR = 0x21,
  50. VK_NEXT = 0x22,
  51. VK_END = 0x23,
  52. VK_HOME = 0x24,
  53. VK_LEFT = 0x25,
  54. VK_UP = 0x26,
  55. VK_RIGHT = 0x27,
  56. VK_DOWN = 0x28,
  57. VK_SELECT = 0x29,
  58. VK_PRINT = 0x2A,
  59. VK_EXECUTE = 0x2B,
  60. VK_SNAPSHOT = 0x2C,
  61. VK_INSERT = 0x2D,
  62. VK_DELETE = 0x2E,
  63. VK_HELP = 0x2F,
  64.  
  65. VK_0 = 0x30,
  66. VK_1 = 0x31,
  67. VK_2 = 0x32,
  68. VK_3 = 0x33,
  69. VK_4 = 0x34,
  70. VK_5 = 0x35,
  71. VK_6 = 0x36,
  72. VK_7 = 0x37,
  73. VK_8 = 0x38,
  74. VK_9 = 0x39,
  75.  
  76. VK_A = 0x41,
  77. VK_B = 0x42,
  78. VK_C = 0x43,
  79. VK_D = 0x44,
  80. VK_E = 0x45,
  81. VK_F = 0x46,
  82. VK_G = 0x47,
  83. VK_H = 0x48,
  84. VK_I = 0x49,
  85. VK_J = 0x4A,
  86. VK_K = 0x4B,
  87. VK_L = 0x4C,
  88. VK_M = 0x4D,
  89. VK_N = 0x4E,
  90. VK_O = 0x4F,
  91. VK_P = 0x50,
  92. VK_Q = 0x51,
  93. VK_R = 0x52,
  94. VK_S = 0x53,
  95. VK_T = 0x54,
  96. VK_U = 0x55,
  97. VK_V = 0x56,
  98. VK_W = 0x57,
  99. VK_X = 0x58,
  100. VK_Y = 0x59,
  101. VK_Z = 0x5A,
  102.  
  103. VK_LWIN = 0x5B,
  104. VK_RWIN = 0x5C,
  105. VK_APPS = 0x5D,
  106. VK_SLEEP = 0x5F,
  107. VK_NUMPAD0 = 0x60,
  108. VK_NUMPAD1 = 0x61,
  109. VK_NUMPAD2 = 0x62,
  110. VK_NUMPAD3 = 0x63,
  111. VK_NUMPAD4 = 0x64,
  112. VK_NUMPAD5 = 0x65,
  113. VK_NUMPAD6 = 0x66,
  114. VK_NUMPAD7 = 0x67,
  115. VK_NUMPAD8 = 0x68,
  116. VK_NUMPAD9 = 0x69,
  117. VK_MULTIPLY = 0x6A,
  118. VK_ADD = 0x6B,
  119. VK_SEPARATOR = 0x6C,
  120. VK_SUBTRACT = 0x6D,
  121. VK_DECIMAL = 0x6E,
  122. VK_DIVIDE = 0x6F,
  123. VK_F1 = 0x70,
  124. VK_F2 = 0x71,
  125. VK_F3 = 0x72,
  126. VK_F4 = 0x73,
  127. VK_F5 = 0x74,
  128. VK_F6 = 0x75,
  129. VK_F7 = 0x76,
  130. VK_F8 = 0x77,
  131. VK_F9 = 0x78,
  132. VK_F10 = 0x79,
  133. VK_F11 = 0x7A,
  134. VK_F12 = 0x7B,
  135. VK_F13 = 0x7C,
  136. VK_F14 = 0x7D,
  137. VK_F15 = 0x7E,
  138. VK_F16 = 0x7F,
  139. VK_F17 = 0x80,
  140. VK_F18 = 0x81,
  141. VK_F19 = 0x82,
  142. VK_F20 = 0x83,
  143. VK_F21 = 0x84,
  144. VK_F22 = 0x85,
  145. VK_F23 = 0x86,
  146. VK_F24 = 0x87,
  147. VK_NUMLOCK = 0x90,
  148. VK_SCROLL = 0x91,
  149. VK_OEM_NEC_EQUAL = 0x92, // '=' key on numpad
  150. VK_OEM_FJ_JISHO = 0x92, // 'Dictionary' key
  151. VK_OEM_FJ_MASSHOU = 0x93, // 'Unregister word' key
  152. VK_OEM_FJ_TOUROKU = 0x94, // 'Register word' key
  153. VK_OEM_FJ_LOYA = 0x95, // 'Left OYAYUBI' key
  154. VK_OEM_FJ_ROYA = 0x96, // 'Right OYAYUBI' key
  155. VK_LSHIFT = 0xA0,
  156. VK_RSHIFT = 0xA1,
  157. VK_LCONTROL = 0xA2,
  158. VK_RCONTROL = 0xA3,
  159. VK_LMENU = 0xA4,
  160. VK_RMENU = 0xA5,
  161.  
  162. VK_OEM_1 = 0xBA, // ';:' for US
  163. VK_OEM_PLUS = 0xBB, // '+' any country
  164. VK_OEM_COMMA = 0xBC, // ',' any country
  165. VK_OEM_MINUS = 0xBD, // '-' any country
  166. VK_OEM_PERIOD = 0xBE, // '.' any country
  167. VK_OEM_2 = 0xBF, // '/?' for US
  168. VK_OEM_3 = 0xC0, // '`~' for US
  169.  
  170. VK_ATTN = 0xF6,
  171. VK_CRSEL = 0xF7,
  172. VK_EXSEL = 0xF8,
  173. VK_EREOF = 0xF9,
  174. VK_PLAY = 0xFA,
  175. VK_ZOOM = 0xFB,
  176. VK_NONAME = 0xFC,
  177. VK_PA1 = 0xFD,
  178. VK_OEM_CLEAR = 0xFE
  179.   */
  180.  
  181. #endregion
  182.  
  183. #region Unmanaged Code
  184. [DllImport("user32", CharSet = CharSet.Auto, EntryPoint = "SendMessage")]
  185. private extern static int SendMessageInt(
  186. IntPtr handle,
  187. int msg,
  188. int wParam,
  189. int lParam
  190. );
  191. private const int EM_LINEINDEX = 0x00BB;
  192. private const int EM_POSFROMCHAR = 0x00D6;
  193. private const int EM_CHARFROMPOS = 0x00D7;
  194.  
  195. [DllImport("user32")]
  196. private static extern int GetKeyState(KEY key);
  197.  
  198. #endregion
  199.  
  200. public static bool isKeyDown(KEY key)
  201. {
  202. return (((int)GetKeyState(key)) & 0x8000) == 0x8000;
  203. }
  204.  
  205. /// <summary>
  206. /// Returns the index of the character under the specified
  207. /// point in the control, or the nearest character if there
  208. /// is no character under the point.
  209. /// </summary>
  210. /// <param name="txt">The text box control to check.</param>
  211. /// <param name="pt">The point to find the character for,
  212. /// specified relative to the client area of the text box.</param>
  213. /// <returns>(int) index of the character under the specified
  214. /// point in the control</returns>
  215. public static int CharFromPos(
  216. System.Windows.Forms.TextBox txt,
  217. Point pt
  218. )
  219. {
  220. {
  221. // Convert the point into a DWord with horizontal position
  222. // in the loword and vertical position in the hiword:
  223. int xy = (pt.X & 0xFFFF) + ((pt.Y & 0xFFFF) << 16);
  224. // Get the position from the text box.
  225. int res = SendMessageInt(txt.Handle, EM_CHARFROMPOS, 0, xy);
  226. // the Platform SDK appears to be incorrect on this matter.
  227. // the hiword is the line number and the loword is the index
  228. // of the character on this line
  229. int lineNumber = ((res & 0xFFFF) >> 16);
  230. int charIndex = (res & 0xFFFF);
  231.  
  232. // Find the index of the first character on the line within
  233. // the control:
  234. int lineStartIndex = SendMessageInt(txt.Handle, EM_LINEINDEX,
  235. lineNumber, 0);
  236. // Return the combined index:
  237. return lineStartIndex + charIndex;
  238. }
  239. }
  240.  
  241. /// <summary>
  242. /// Returns the position of the specified character
  243. /// </summary>
  244. /// <param name="txt">The text box to find the character in.</param>
  245. /// <param name="charIndex">The index of the character whose
  246. /// position needs to be found.</param>
  247. /// <returns>The position of the character relative to the client
  248. /// area of the control.</returns>
  249. public static Point PosFromChar(
  250. System.Windows.Forms.TextBox txt,
  251. int charIndex
  252. )
  253. {
  254. {
  255. int xy = SendMessageInt(txt.Handle, EM_POSFROMCHAR, charIndex, 0);
  256. return new Point(xy);
  257. }
  258. }
  259.  
  260. // private constructor, methods are static
  261. private TextHelper()
  262. {
  263. // intentionally left blank
  264. }
  265. }
  266. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/model/ 
IcôneNomTailleModification
IcôneNomTailleModification
| _ Répertoire parent0 octets1713562963 19/04/2024 23:42:43
| _config0 octets1541007188 31/10/2018 18:33:08
| _enums0 octets1541007189 31/10/2018 18:33:09
| _exceptions0 octets1541007189 31/10/2018 18:33:09
| _drawing0 octets1541007188 31/10/2018 18:33:08
| _win320 octets1541007190 31/10/2018 18:33:10
| _file0 octets1541007190 31/10/2018 18:33:10
| _comparators0 octets1541007188 31/10/2018 18:33:08
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/model/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csWebHelper.cs841 octets31/10/2018 18:32:48-refusé-
Afficher le fichier .cs|.csHistory.cs6.96 Ko31/10/2018 18:32:48-refusé-
Afficher le fichier .cs|.csValueObject.cs664 octets31/10/2018 18:32:48-refusé-
Afficher le fichier .cs|.csExport.cs13.3 Ko31/10/2018 18:32:47-refusé-
Afficher le fichier .cs|.csDisposableObject.cs883 octets31/10/2018 18:32:47-refusé-
Afficher le fichier .cs|.csStat.cs3.63 Ko31/10/2018 18:32:48-refusé-
Afficher le fichier .cs|.csTextHelper.cs8.11 Ko31/10/2018 18:32:48-refusé-
Afficher le fichier .cs|.csUnits.cs2.07 Ko31/10/2018 18:32:48-refusé-

Utilisation de l'explorateur de code

  • Navigation :
    • Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
    • Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
    • La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
    • Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
  • Affichage :
    • Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
  • Actions :
    • Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 16/10/2009, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/cs-broldev-source-rf-model//TextHelper.cs.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.