Geen cache-versie.

Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code LNG204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

TextBoxDragDrop.cs

Description du code

TextBoxDragDrop.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.ComponentModel;
  3. using System.Drawing;
  4. using System.IO;
  5. using System.Text;
  6. using System.Windows.Forms;
  7. using be.gaudry.model;
  8. using be.gaudry.model.config;
  9. using be.gaudry.observer;
  10.  
  11. namespace be.gaudry.view.controls
  12. {
  13.  
  14. public partial class TextBoxDragDrop : TextBox
  15. {
  16. private int lastSelStart = 0;
  17. private int lastSelLength = 0;
  18. private bool candidateToDragDrop = false;
  19.  
  20. public TextBoxDragDrop()
  21. {
  22. InitializeComponent();
  23. init();
  24. }
  25.  
  26. public TextBoxDragDrop(IContainer container)
  27. {
  28. container.Add(this);
  29. InitializeComponent();
  30. init();
  31. }
  32.  
  33. private void init()
  34. {
  35. this.DragDrop += new System.Windows.Forms.DragEventHandler(this.onTextBox_DragDrop);
  36. this.DragEnter += new System.Windows.Forms.DragEventHandler(this.onTextBox_DragEnter);
  37. this.AllowDrop = true;
  38. SourcesManager.addSource(new Source(
  39. "drag and drop",
  40. "TextBoxDragDrop",
  41. "http://msdn2.microsoft.com/fr-fr/library/system.windows.forms.drageventargs(VS.80).aspx",
  42. "Gestion des touches pour le drag and drop"
  43. )
  44. );
  45. }
  46.  
  47.  
  48. protected override void OnMouseUp(MouseEventArgs e)
  49. {
  50. base.OnMouseUp(e);
  51. if (lastSelLength == 0)
  52. {
  53. lastSelLength = SelectionLength;
  54. lastSelStart = SelectionStart;
  55. }
  56. else
  57. {
  58. lastSelLength = 0;
  59. lastSelStart = 0;
  60. candidateToDragDrop = false;
  61. }
  62. }
  63.  
  64. protected override void OnMouseDown(MouseEventArgs e)
  65. {
  66. base.OnMouseDown(e);
  67. //todo test if cursor is over the selected text
  68. if (lastSelLength > 0)
  69. {
  70. candidateToDragDrop = true;
  71. }
  72. }
  73.  
  74. protected override void OnMouseMove(MouseEventArgs e)
  75. {
  76. base.OnMouseMove(e);
  77. //todo : test if cursor is over the selected text
  78. if (candidateToDragDrop)
  79. {
  80. DragDropEffects dr;
  81. if (lastSelLength == Text.Length)//we may use move of a entire string
  82. {
  83. if (!TextHelper.isKeyDown(TextHelper.KEY.CONTROL))
  84. {
  85. dr = DoDragDrop(Text, DragDropEffects.Move);
  86. if (dr == DragDropEffects.Move)
  87. Text = "";
  88. }
  89. else
  90. {
  91. DoDragDrop(Text, DragDropEffects.Copy);
  92. }
  93. }
  94. else
  95. {
  96. //get selected text
  97. try
  98. {
  99. string str = Text.Substring(lastSelStart, lastSelLength);
  100. //we may not use DragDropEffects.All or move because we drag only a part of string
  101. dr = DoDragDrop(str, DragDropEffects.Copy);
  102. //remove selected text to simulate move
  103. if (dr == DragDropEffects.Copy && !TextHelper.isKeyDown(TextHelper.KEY.CONTROL))
  104. {
  105. Text = Text.Remove(lastSelStart, lastSelLength);
  106. }
  107. }
  108. catch (Exception ex)
  109. {
  110. StaticObservable.notify(new Notification(
  111. Notification.VERBOSE.lowError,
  112. string.Format("{0} : {1}",this.GetType().ToString(),this.Name),
  113. "Erreur de drag and drop",
  114. ex,
  115. this
  116. ));
  117. }
  118. }
  119. //reinit
  120. lastSelLength = 0;
  121. lastSelStart = 0;
  122. candidateToDragDrop = false;
  123. }
  124. }
  125.  
  126. /*
  127.   protected override void OnDragEnter(DragEventArgs e)
  128.   {
  129.   base.OnDragEnter(e);
  130.   e.Effect = DragDropEffects.All;
  131.   }
  132.   protected override void OnDragDrop(DragEventArgs e)
  133.   {
  134.   base.OnDragDrop(e);
  135.   if (e.Effect != DragDropEffects.None) //e.Data.GetDataPresent(typeof(string)))
  136.   {
  137.   Text = Text.Insert(
  138.   SelectionStart,
  139.   //(string)e.Data.GetData(typeof(string))
  140.   getDropObjectAsText(e)
  141.   );
  142.   }
  143.   this.SelectionLength = 0;
  144.   this.SelectionStart = Text.Length;
  145.   this.Focus();
  146.   }
  147.   */
  148.  
  149. private void onTextBox_DragEnter(object sender, DragEventArgs e)
  150. {
  151. //if (e.Data.GetDataPresent(typeof(string)))
  152. //{
  153. //e.Effect = DragDropEffects.Copy;
  154. //}
  155. //e.Effect = DragDropEffects.All;
  156.  
  157. if ((e.KeyState & 4) == 4 &&
  158. (e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
  159. {
  160. // SHIFT KeyState for move.
  161. e.Effect = DragDropEffects.Move;
  162. }
  163. else if ((e.KeyState & 8) == 8 &&
  164. (e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy)
  165. {
  166. // CTL KeyState for copy.
  167. e.Effect = DragDropEffects.Copy;
  168. }
  169. else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
  170. {
  171. // By default, the drop action should be move, if allowed.
  172. e.Effect = DragDropEffects.Move;
  173. }
  174. else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy)
  175. {
  176. e.Effect = DragDropEffects.Copy;
  177. }
  178. else
  179. e.Effect = DragDropEffects.None;
  180. }
  181.  
  182. private void onTextBox_DragDrop(object sender, DragEventArgs e)
  183. {
  184. //allow drop for other types (file, etc)
  185. if (e.Effect!= DragDropEffects.None) //e.Data.GetDataPresent(typeof(string)))
  186. {
  187. Text = Text.Insert(
  188. SelectionStart,
  189. //(string)e.Data.GetData(typeof(string))
  190. getDropObjectAsText(e)
  191. );
  192. this.SelectionLength = 0;
  193. this.SelectionStart = Text.Length;
  194. this.Focus();
  195. }
  196. }
  197.  
  198. protected override void OnDragOver(DragEventArgs e)
  199. {
  200. base.OnDragOver(e);
  201. //get insertion point
  202. Point pt = this.PointToClient(new Point(e.X, e.Y));
  203. SelectionStart = TextHelper.CharFromPos(this, pt);
  204. }
  205.  
  206. /*private void setEffect(DragEventArgs e)
  207.   {
  208.   if((e.KeyState & 4) == 4 &&
  209.   (e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
  210.   {
  211.  
  212.   // SHIFT KeyState for move.
  213.   e.Effect = DragDropEffects.Move;
  214.  
  215.   }
  216.  
  217.   else if ((e.KeyState & 8) == 8 &&
  218.   (e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy)
  219.   {
  220.  
  221.   // CTL KeyState for copy.
  222.   e.Effect = DragDropEffects.Copy;
  223.  
  224.   }
  225.   else
  226.   e.Effect = DragDropEffects.None;
  227.  
  228.   }*/
  229.  
  230. protected virtual string getDropObjectAsText(DragEventArgs e)
  231. {
  232. if (e.Data.GetDataPresent(typeof(string)))
  233. {
  234. return (string)e.Data.GetData(typeof(string));
  235. }
  236. if (e.Data.GetDataPresent(DataFormats.FileDrop))
  237. {
  238. string[] DropFiles = (string[])e.Data.GetData(DataFormats.FileDrop);
  239. StringBuilder str = new StringBuilder();
  240. foreach (string s in DropFiles)
  241. {
  242. if (str.Length > 0)
  243. str.Append(", ");
  244. str.Append(Path.GetFileNameWithoutExtension(s));
  245. }
  246. return str.ToString();
  247. }
  248. //MessageBox.Show("Impossible de déposer l'élément ici");
  249. e.Effect = DragDropEffects.None;
  250. return "";
  251. }
  252.  
  253. }
  254. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/view/controls/ 
IcôneNomTailleModification
Pas de sous-répertoires.
IcôneNomTailleModification
| _ Répertoire parent0 octets1715723074 14/05/2024 23:44:34
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/view/controls/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csToolBarHomeControl.Designer.cs7.41 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csWizardUserControl.Designer.cs6.79 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csHeaderPanel.Designer.cs1.19 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csDGVLayoutOptionsControl.cs7.55 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csXPGroupBox.cs15.83 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csWizardXpUserControl.Designer.cs7.85 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csToolBarHomeControl.cs2.32 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csVersionControl.Designer.cs4.09 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csWizardUserControl.cs2.01 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .resx|.resxWizardXpUserControl.resx5.68 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csBrolBoxUserControl.Designer.cs5.92 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .resx|.resxChartControl.resx6.58 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csHeaderPanel.cs35.93 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csIWizardUC.cs2.35 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .resx|.resxAboutUserControl.resx5.68 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .cs|.csTextBoxDragDrop.cs8.59 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csSystemInfoControl.cs5.46 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .resx|.resxXPGroupBox.resx17.7 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csHeaderPanelNativeMethods.cs21.09 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csToolBarManagerControl.cs6.99 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csTextBoxDragDrop.Designer.cs1.11 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .resx|.resxSystemInfoControl.resx6.22 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csSystemInfoControl.Designer.cs4.79 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .resx|.resxHeaderPanel.resx5.85 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csScrollablePictureBoxUserControl.cs5.55 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csBrolBoxUserControl.cs4.7 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .resx|.resxDGVLayoutOptionsControl.resx5.68 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .resx|.resxWizardUserControl.resx5.68 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csUpdateControl.cs7.55 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csIconList.cs2.68 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csVersionControl.cs463 octets31/10/2018 18:33:12-refusé-
Afficher le fichier .resx|.resxBrolBoxUserControl.resx5.68 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .cs|.csAboutUserControl.cs6.75 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .resx|.resxToolBarManagerControl.resx5.88 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csToolBarManagerControl.Designer.cs10.66 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csIToolBarControl.cs1.07 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csWizardXpUserControl.cs8.11 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csImageCombo.cs15.49 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csAboutUserControl.Designer.cs12.31 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .resx|.resxScrollablePictureBoxUserControl.resx5.68 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csScrollablePictureBoxUserControl.Designer.cs5.64 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .resx|.resxVersionControl.resx5.68 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csChartControl.Designer.cs18.45 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .cs|.csUpdateControl.Designer.cs3.92 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .resx|.resxUpdateControl.resx5.68 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csChartControl.cs15.11 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .cs|.csDGVLayoutOptionsControl.Designer.cs17.39 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csToolStrip.cs1.06 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csIconList.Designer.cs1.1 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .resx|.resxToolBarHomeControl.resx48.51 Ko31/10/2018 18:33:12-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.

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 16/10/2009 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/cs-broldev-source-rf-view/controls/TextBoxDragDrop.cs.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.