MDIParentForm.MDIFeatures.cs

Description du code

MDIParentForm.MDIFeatures.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.Collections.Generic;
  3. using System.Windows.Forms;
  4. using be.gaudry.model.exceptions;
  5.  
  6. namespace be.gaudry.view
  7. {
  8. partial class MDIParentForm
  9. {
  10. #region declarations
  11. /// <summary>
  12. /// Used to prevent toolstrip bug with the office style
  13. /// </summary>
  14. private string toolStripPadding=" ";
  15. /// <summary>
  16. /// Available menus on the <code>MDIParentForm</code>
  17. /// Used e.g. to define where putting a menu item
  18. /// </summary>
  19. public enum MENU
  20. {
  21. file,
  22. display,
  23. tools,
  24. toolBars,
  25. window,
  26. help
  27. }
  28. /// <summary>
  29. /// Used to store instances of childs
  30. /// </summary>
  31. private Dictionary<Type, Form> mdiChilds = new Dictionary<Type, Form>();
  32. //private System.ComponentModel.BackgroundWorker openMdiChildBGW;
  33. #endregion
  34.  
  35. #region single instance of child
  36.  
  37. /// <summary>
  38. /// Ensure having only one instance of this type of child form in the MDI parent (this)
  39. /// Create new child if not exists, <b>and show it</b>.
  40. /// Use this method only if you don't have to call some method before opening the form.
  41. /// Otherwise, call the <code>createMDIChild()</code> method to get the instance, call the needed method on the child, and call the
  42. /// </summary>
  43. /// <typeparam name="T">Type of the form to show.</typeparam>
  44. /// <returns>New form if not existed, or existing form</returns>
  45. protected T showMDIChild<T>() where T : Form, new()
  46. {
  47. return showMDIChild<T>("");
  48. }
  49. /// <summary>
  50. /// Ensure having only one instance of this type of child form in the MDI parent (this)
  51. /// Create new child if not exists, <b>and show it</b>.
  52. /// Use this method only if you don't have to call some method before opening the form.
  53. /// Otherwise, call the <code>createMDIChild()</code> method to get the instance, call the needed method on the child, and call the
  54. /// </summary>
  55. /// <typeparam name="T">Type of the form to show.</typeparam>
  56. /// <param name="progressInfo">Text to display along the progress of creating instance</param>
  57. /// <returns>New form if not existed, or existing form</returns>
  58. protected T showMDIChild<T>(string progressInfo) where T : Form, new()
  59. {
  60. T child = createMDIChild<T>(progressInfo);
  61. showMDIChild(child);
  62. child.WindowState = FormWindowState.Maximized;
  63. return child;
  64. }
  65. /// <summary>
  66. /// Show an instance of form.
  67. /// This method <b>may not ensure single instance of child form</b>.
  68. /// To ensure single instance, use <code>createMDIChild()</code> method to get the single instance of the child form
  69. /// to have this method parameter.
  70. /// </summary>
  71. /// <param name="child">Form to show</param>
  72. protected void showMDIChild(Form child)
  73. {
  74. if (child != null)
  75. {
  76. child.Show();
  77. child.Activate();
  78. }
  79. }
  80. /// <summary>
  81. /// Ensure having only one instance of this type of child form in the MDI parent (this)
  82. /// Create new child if not exists, <b>but don't show it</b>.
  83. /// </summary>
  84. /// <typeparam name="T">Type of the form to show.</typeparam>
  85. /// <returns>New form if not existed, or existing form</returns>
  86. protected T createMDIChild<T>() where T : Form, new()
  87. {
  88. return createMDIChild<T>("");
  89. }
  90. /// <summary>
  91. /// Ensure having only one instance of this type of child form in the MDI parent (this)
  92. /// Create new child if not exists, <b>but don't show it</b>.
  93. /// </summary>
  94. /// <typeparam name="T">Type of the form to show.</typeparam>
  95. /// <param name="progressInfo">Text to display along the progress of creating instance</param>
  96. /// <returns>New form if not existed, or existing form</returns>
  97. protected T createMDIChild<T>(string progressInfo) where T : Form, new()
  98. {
  99. // Create new child if not exists in the collection and add it
  100. if (!this.mdiChilds.ContainsKey(typeof(T)))
  101. {
  102.  
  103. bool showProgress = !string.Empty.Equals(progressInfo);
  104. if (showProgress)
  105. {
  106. /*if (statusStrip.Visible)
  107.   {
  108.   startProgress();
  109.   setStatusMessage(progressInfo);
  110.   }
  111.   else
  112.   {*/
  113. Splasher.show(progressInfo);
  114. //}
  115. //System.Threading.Thread.Sleep(10000);
  116. }
  117. T mdiChildForm = new T();
  118. // Set up the necessary properties
  119. mdiChildForm.MdiParent = this;
  120. mdiChildForm.WindowState = FormWindowState.Maximized;
  121. if (mdiChildForm is IMDIChild)
  122. {
  123. MenuStrip menuStrip = ((IMDIChild)mdiChildForm).getMainMenuStrip();
  124. if (menuStrip != null)
  125. {
  126. menuStrip.Visible = false;
  127. }
  128. }
  129. // Remove form from the collection when the mdiChild is closed
  130. mdiChildForm.FormClosed += new FormClosedEventHandler(delegate(object sender, FormClosedEventArgs e)
  131. {
  132. this.mdiChilds.Remove(sender.GetType());
  133. });
  134. //
  135.  
  136.  
  137. this.mdiChilds.Add(typeof(T), mdiChildForm);
  138. //if (showProgress)
  139. //{
  140. /*if (statusStrip.Visible)
  141.   {
  142.   stopProgress();
  143.   resetStatusStrip();
  144.   }
  145.   else
  146.   {*/
  147. Splasher.close();
  148. //}
  149. //}
  150. }
  151.  
  152. // return the child
  153. T formToActivate = (T)this.mdiChilds[typeof(T)];
  154. return formToActivate;
  155. }
  156. #endregion
  157.  
  158. #region menu
  159. /// <summary>
  160. /// Add a menuItem on the main <code>MenuStrip</code> to open a single instance of the mdiChild.
  161. /// Add necessary actions on click.
  162. /// </summary>
  163. /// <typeparam name="T">Type of the mdiChild to open</typeparam>
  164. /// <param name="childTsMi"><code>ToolStripMenuItem</code> to use on the main MenuStrip.</param>
  165. /// <param name="progressInfo">Text to display along the progress of creating instance. Empty string or null value may be used to avoid displaying progression.</param>
  166. /// <exception cref="be.gaudry.exceptions.PluginException">Plugin exception if childTsMi is null or don't have text to display.</exception>
  167. public void addChildMenu<T>(ToolStripMenuItem childTsMi, string progressInfo) where T : Form, new()
  168. {
  169. if (childTsMi == null || string.Empty.Equals(childTsMi.Text))
  170. {
  171. throw new PluginException("Tentative d'ajout d'un menu vide ou dont le titre n'est pas spécifié.");
  172. }
  173. mainMenuStrip.Items.Insert(2, childTsMi);
  174. //Console.WriteLine("add menu : " + typeof(T));
  175. childTsMi.Click += new EventHandler(delegate(object sender, EventArgs e)
  176. {
  177. if (string.Empty.Equals(progressInfo))
  178. {
  179. showMDIChild<T>();
  180. }
  181. else
  182. {
  183. showMDIChild<T>(progressInfo);
  184. }
  185. });
  186. }
  187. /// <summary>
  188. /// Add a menuItem on the main <code>MenuStrip</code> to open a single instance of the mdiChild.
  189. /// Add necessary actions on click.
  190. /// </summary>
  191. /// <typeparam name="T">Type of the mdiChild to open</typeparam>
  192. /// <param name="childTsMi"><code>ToolStripMenuItem</code> to use on the main MenuStrip.</param>
  193. /// <param name="menu">Location of the <code>ToolStripMenuItem</code></param>
  194. /// <param name="progressInfo">Text to display along the progress of creating instance. Empty string or null value may be used to avoid displaying progression.</param>
  195. /// <exception cref="be.gaudry.exceptions.PluginException">Plugin exception if childTsMi is null or don't have text to display.</exception>
  196. public void addChildMenu<T>(ToolStripMenuItem childTsMi, MENU menu, string progressInfo) where T : Form, new()
  197. {
  198. if (childTsMi == null || string.Empty.Equals(childTsMi.Text))
  199. {
  200. throw new PluginException("Tentative d'ajout d'un menu vide ou dont le titre n'est pas spécifié.");
  201. }
  202. switch (menu)
  203. {
  204. case MENU.display: displayTsMi.DropDownItems.Add(childTsMi); break;
  205. case MENU.file: fileTsMi.DropDownItems.Add(childTsMi); break;
  206. case MENU.help: helpTsMi.DropDownItems.Add(childTsMi); break;
  207. case MENU.tools: toolsTsMi.DropDownItems.Add(childTsMi); break;
  208. case MENU.toolBars: displayToolBarTsMi.DropDownItems.Add(childTsMi); break;
  209. case MENU.window: windowTsMi.DropDownItems.Add(childTsMi); break;
  210. }
  211. //Console.WriteLine("add menu : " + typeof(T));
  212. childTsMi.Click += new EventHandler(delegate(object sender, EventArgs e)
  213. {
  214. if (string.Empty.Equals(progressInfo))
  215. {
  216. showMDIChild<T>();
  217. }
  218. else
  219. {
  220. showMDIChild<T>(progressInfo);
  221. }
  222. });
  223. }
  224. #endregion
  225.  
  226. #region open child in another thread
  227. /*private void initBackgroundWorker()
  228.   {
  229.   this.openMdiChildBGW = new System.ComponentModel.BackgroundWorker();
  230.   this.openMdiChildBGW.WorkerReportsProgress = true;
  231.   this.openMdiChildBGW.WorkerSupportsCancellation = true;
  232.   this.openMdiChildBGW.DoWork += new System.ComponentModel.DoWorkEventHandler(this.openMdiChildBGW_DoWork);
  233.   this.openMdiChildBGW.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.openMdiChildBGW_RunWorkerCompleted);
  234.   this.openMdiChildBGW.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.openMdiChildBGW_ProgressChanged);
  235.   }
  236.   private void openMdiChildBGW_DoWork(object sender, DoWorkEventArgs e)
  237.   {
  238.  
  239.   }
  240.  
  241.   private void openMdiChildBGW_ProgressChanged(object sender, ProgressChangedEventArgs e)
  242.   {
  243.  
  244.   }
  245.  
  246.   private void openMdiChildBGW_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  247.   {
  248.  
  249.   }*/
  250. #endregion
  251.  
  252. #region IMDIParent Membres
  253. public bool joinToolStrip(ToolStrip ts)
  254. {
  255. this.topTSP.Join(ts);//this.topTSP.Join(ts, 1);
  256. return true;
  257. }
  258. public void setStatusMessage(string copyright, string version, string message)
  259. {
  260. if (InvokeRequired)
  261. {
  262. Invoke((MethodInvoker)delegate()
  263. {
  264. setStatusMessage(copyright, version, message);
  265. });
  266. }
  267. else
  268. {
  269. copyrightTssLbl.Text = copyright;
  270. versionTssLbl.Text = version;
  271. infosTssLbl.Image = null;
  272. infosTssLbl.Text = message + toolStripPadding;
  273. }
  274. }
  275.  
  276. public void setStatusMessage(string message)
  277. {
  278. if (InvokeRequired)
  279. {
  280. Invoke((MethodInvoker)delegate()
  281. {
  282. setStatusMessage(message);
  283. });
  284. }
  285. else
  286. {
  287. infosTssLbl.Image = null;
  288. infosTssLbl.Text = message + toolStripPadding;
  289. }
  290. }
  291. /// <summary>
  292. /// Displays a message on the StatusStrip
  293. /// </summary>
  294. /// <param name="image">Image to display</param>
  295. /// <param name="message">Text to display on the status label</param>
  296. /// <param name="tooltip">Text to display on the status tooltip</param>
  297. public void setStatusMessage(System.Drawing.Image image, string message, string tooltip)
  298. {
  299. if (InvokeRequired)
  300. {
  301. Invoke((MethodInvoker)delegate()
  302. {
  303. setStatusMessage(message);
  304. });
  305. }
  306. else
  307. {
  308. infosTssLbl.Image = image;
  309. infosTssLbl.Text = message + toolStripPadding;
  310. infosTssLbl.ToolTipText = tooltip;
  311. }
  312. }
  313. public void resetStatusStrip()
  314. {
  315. setStatusMessage(
  316. "Copyright © 2006 BrolDev",
  317. Application.ProductName + " " + Application.ProductVersion,
  318. ""
  319. );
  320. }
  321. public void startProgress()
  322. {
  323. /*if (InvokeRequired)
  324.   {
  325.   Invoke((MethodInvoker)delegate()
  326.   {
  327.   startProgress();
  328.   });
  329.   }
  330.   else
  331.   {
  332.   toolStripProgressBar.Style = ProgressBarStyle.Marquee;
  333.   toolStripProgressBar.Width = 300;
  334.   toolStripProgressBar.Visible = true;
  335.   }*/
  336. }
  337.  
  338. public void stopProgress()
  339. {
  340. /*if (InvokeRequired)
  341.   {
  342.   Invoke((MethodInvoker)delegate()
  343.   {
  344.   stopProgress();
  345.   });
  346.   }
  347.   else
  348.   {
  349.   toolStripProgressBar.Visible = false;
  350.   toolStripProgressBar.Width = 1;
  351.   toolStripProgressBar.Style = ProgressBarStyle.Blocks;
  352.   }*/
  353. }
  354. #endregion
  355. }
  356. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/view/ 
IcôneNomTailleModification
IcôneNomTailleModification
| _ Répertoire parent0 octets1732256057 22/11/2024 07:14:17
| _dialogs0 octets1541007195 31/10/2018 18:33:15
| _style0 octets1541007196 31/10/2018 18:33:16
| _utils0 octets1541007196 31/10/2018 18:33:16
| _controls0 octets1541007193 31/10/2018 18:33:13
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/view/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csDummyDoc.cs1.95 Ko31/10/2018 18:32:48-refusé-
Afficher le fichier .cs|.csIMDIParent.cs2.33 Ko31/10/2018 18:32:49-refusé-
Afficher le fichier .cs|.csMDIChildForm.cs11.93 Ko31/10/2018 18:32:49-refusé-
Afficher le fichier .cs|.csSplashForm.Designer.cs4.45 Ko31/10/2018 18:32:49-refusé-
Afficher le fichier .cs|.csSourcesForm.Designer.cs8.14 Ko31/10/2018 18:32:49-refusé-
Afficher le fichier .cs|.csDummyDoc.Designer.cs6.42 Ko31/10/2018 18:32:48-refusé-
Afficher le fichier .cs|.csSplashForm.cs1.02 Ko31/10/2018 18:32:49-refusé-
Afficher le fichier .cs|.csMDIParentForm.cs13.52 Ko31/10/2018 18:32:49-refusé-
Afficher le fichier .resx|.resxSplashForm.resx5.68 Ko31/10/2018 18:32:49-refusé-
Afficher le fichier .cs|.csMDIParentForm.MDIFeatures.cs14.33 Ko31/10/2018 18:32:49-refusé-
Afficher le fichier .resx|.resxMDIChildForm.resx5.68 Ko31/10/2018 18:32:49-refusé-
Afficher le fichier .cs|.csTestForm.cs350 octets31/10/2018 18:32:49-refusé-
Afficher le fichier .cs|.csSplasher.cs2.81 Ko31/10/2018 18:32:49-refusé-
Afficher le fichier .resx|.resxDummyDoc.resx7.02 Ko31/10/2018 18:32:48-refusé-
Afficher le fichier .cs|.csMDIParentForm.Designer.cs44.09 Ko31/10/2018 18:32:49-refusé-
Afficher le fichier .resx|.resxSourcesForm.resx41.87 Ko31/10/2018 18:32:49-refusé-
Afficher le fichier .cs|.csSourcesForm.cs1.83 Ko31/10/2018 18:32:49-refusé-
Afficher le fichier .cs|.csTestForm.Designer.cs1.15 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .resx|.resxMDIParentForm.resx42.14 Ko31/10/2018 18:32:49-refusé-
Afficher le fichier .cs|.csMDIChildForm.Designer.cs1.46 Ko31/10/2018 18:32:49-refusé-
Afficher le fichier .cs|.csIMDIChild.cs151 octets31/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-view//MDIParentForm.MDIFeatures.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.