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.

RebarRenderer.cs

Description du code

RebarRenderer.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. /*
  2.   Purpose: Renderers ToolsStrip and MenuStrip with Microsoft Internet Explorer Rebar style.
  3.   - Full support of themes (including third-party themes and software like StyleXP).
  4.   - Clear rendering with disabled themes.
  5.   - Support of both Rtl and Ltr directions.
  6.  
  7.   Original file name: RebarRenderer.cs
  8.  
  9.   Copyright: Mike Chaliy. All rights reserved.
  10.  
  11.   License: This work is licensed under a Creative Commons Attribution 2.5 License (http://creativecommons.org/licenses/by/2.5/).
  12.   <rdf:RDF xmlns="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  13.   <Work rdf:about="">
  14.   <license rdf:resource="http://creativecommons.org/licenses/by/2.5/" />
  15.   <dc:title>.Net ToolStrip Rebar Renderer</dc:title>
  16.   <dc:date>2006</dc:date>
  17.   <dc:description>Renders ToolsStrip and MenuStrip with Microsoft Internet Explorer Rebar style. Full support of themes (including third-party themes and software like StyleXP). Clear rendering with disabled themes. Support of both Rtl and Ltr directions. Sources included.</dc:description>
  18.   <dc:creator>
  19.   <Agent>
  20.   <dc:title>Mike Chaliy</dc:title>
  21.   </Agent>
  22.   </dc:creator>
  23.   <dc:rights>
  24.   <Agent>
  25.   <dc:title>Mike Chaliy</dc:title>
  26.   </Agent>
  27.   </dc:rights>
  28.   <dc:source rdf:resource="http://www.chaliy.com/Sources/RebarRenderer/" />
  29.   </Work>
  30.   <License rdf:about="http://creativecommons.org/licenses/by/2.5/">
  31.   <permits rdf:resource="http://web.resource.org/cc/Reproduction"/>
  32.   <permits rdf:resource="http://web.resource.org/cc/Distribution"/>
  33.   <requires rdf:resource="http://web.resource.org/cc/Notice"/>
  34.   <requires rdf:resource="http://web.resource.org/cc/Attribution"/>
  35.   <permits rdf:resource="http://web.resource.org/cc/DerivativeWorks"/>
  36.   </License>
  37.   </rdf:RDF>
  38. */
  39.  
  40. using System;
  41. using System.Drawing;
  42. using System.Windows.Forms;
  43. using System.Windows.Forms.VisualStyles;
  44.  
  45. namespace Chaliy.Windows.Forms
  46. {
  47. /// <summary>
  48. /// Explorer like <see cref="ToolStrip"/> renderer.
  49. /// </summary>
  50. /// <seealso cref="ToolStrip"/>
  51. /// <seealso cref="ToolStripManager"/>
  52. /// <seealso cref="ToolStripRenderer"/>
  53. public class RebarRenderer : ToolStripSystemRenderer
  54. {
  55. #region Fields
  56.  
  57. private static VisualStyleRenderer RebarStyleRenderer;
  58. private static VisualStyleRenderer RebarBandStyleRenderer;
  59.  
  60. private EventHandler _locationChangedEnventHandler;
  61.  
  62. #endregion
  63.  
  64. #region Constructors
  65.  
  66. /// <summary>
  67. /// Initializes the <see cref="RebarRenderer"/> class.
  68. /// </summary>
  69. [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline")]
  70. static RebarRenderer()
  71. {
  72. if (VisualStyleRenderer.IsSupported)
  73. {
  74. // For some reasons Rebar zero part (Rebar by itself) was not added to the VisualStyleElements.
  75. RebarRenderer.RebarStyleRenderer = new VisualStyleRenderer("Rebar", 0, 0);
  76. RebarRenderer.RebarBandStyleRenderer = new VisualStyleRenderer(VisualStyleElement.Rebar.Band.Normal);
  77. }
  78. }
  79.  
  80. /// <summary>
  81. /// Initializes a new instance of the <see cref="RebarRenderer"/> class.
  82. /// </summary>
  83. public RebarRenderer()
  84. {
  85. this._locationChangedEnventHandler = new EventHandler(this.ChildControlLocationChanged);
  86. }
  87.  
  88. #endregion
  89.  
  90. #region Implementation
  91.  
  92. /// <summary>
  93. /// Initializes the specified <see cref="T:System.Windows.Forms.ToolStripPanel"></see>.
  94. /// </summary>
  95. /// <param name="toolStripPanel">The <see cref="T:System.Windows.Forms.ToolStripPanel"></see>.</param>
  96. protected override void InitializePanel(ToolStripPanel toolStripPanel)
  97. {
  98. toolStripPanel.SizeChanged += new EventHandler(this.PanelSizeChanged);
  99.  
  100. // Because many of the themes use gradients and so on, we need to refresh all toolbars event they simply moved.
  101. foreach (ToolStripPanelRow row in toolStripPanel.Rows)
  102. {
  103. foreach (ToolStrip toolStrip in row.Controls)
  104. {
  105. if (toolStrip != null)
  106. {
  107. this.ConnectToolStrip(toolStrip);
  108. }
  109. }
  110. }
  111.  
  112. // This need to workaroud issue the Initalize does not invoked when using ToolStripManager.Renderer.
  113. toolStripPanel.ControlAdded += new ControlEventHandler(PanelControlAdded);
  114. toolStripPanel.ControlRemoved += new ControlEventHandler(PanelControlRemoved);
  115.  
  116. base.InitializePanel(toolStripPanel);
  117. }
  118.  
  119. private void DisconnectToolStrip(ToolStrip toolStrip)
  120. {
  121. if (toolStrip != null)
  122. {
  123. toolStrip.LocationChanged -= this._locationChangedEnventHandler;
  124.  
  125. if ((ToolStripManager.VisualStylesEnabled && VisualStyleRenderer.IsSupported) == false)
  126. {
  127. toolStrip.BackColor = Color.Empty;
  128. }
  129. }
  130. }
  131.  
  132. private void ConnectToolStrip(ToolStrip toolStrip)
  133. {
  134. if (toolStrip != null)
  135. {
  136. toolStrip.LocationChanged += this._locationChangedEnventHandler;
  137.  
  138. // This is needed for proper rendering without visual styles enbaled.
  139. if ((ToolStripManager.VisualStylesEnabled && VisualStyleRenderer.IsSupported) == false)
  140. {
  141. toolStrip.BackColor = Color.Transparent;
  142. }
  143. }
  144. }
  145.  
  146. private void PanelControlRemoved(object sender, ControlEventArgs e)
  147. {
  148. this.DisconnectToolStrip(e.Control as ToolStrip);
  149. }
  150.  
  151. private void PanelControlAdded(object sender, ControlEventArgs e)
  152. {
  153. this.ConnectToolStrip(e.Control as ToolStrip);
  154. }
  155.  
  156. private void ChildControlLocationChanged(object sender, EventArgs e)
  157. {
  158. Control control = sender as Control;
  159. if (control != null)
  160. {
  161. control.Parent.Invalidate(true);
  162. }
  163. }
  164.  
  165. private void PanelSizeChanged(object sender, EventArgs e)
  166. {
  167. ToolStripPanel toolStripPanel = sender as ToolStripPanel;
  168. if (toolStripPanel != null)
  169. {
  170. toolStripPanel.Invalidate(true);
  171. }
  172. }
  173.  
  174. /// <summary>
  175. /// Raises the render tool strip background event.
  176. /// </summary>
  177. /// <param name="e">The <see cref="System.Windows.Forms.ToolStripRenderEventArgs"/> instance containing the event data.</param>
  178. protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
  179. {
  180. if (ToolStripManager.VisualStylesEnabled && VisualStyleRenderer.IsSupported)
  181. {
  182. if (e.ToolStrip is ToolStripDropDownMenu)
  183. {
  184. base.OnRenderToolStripBackground(e);
  185. }
  186. else if (e.ToolStrip is ToolStrip || e.ToolStrip is MenuStrip)
  187. {
  188. // Rebar style have interesting bottom border.
  189. // Because it does not same like other borders of the tool strip
  190. // we can not use standard mechanizm to draw borders.
  191. // If tool strip will be parented to the ToolStripPanel
  192. // we will paint bands, in other way we will paint full rebar.
  193. if (e.ToolStrip.Parent is ToolStripPanel)
  194. {
  195. if (RebarRenderer.RebarBandStyleRenderer.IsBackgroundPartiallyTransparent())
  196. {
  197. RebarRenderer.RebarBandStyleRenderer.DrawParentBackground(e.Graphics, e.ToolStrip.ClientRectangle, e.ToolStrip);
  198. }
  199. RebarRenderer.RebarBandStyleRenderer.DrawBackground(e.Graphics, e.ToolStrip.ClientRectangle, e.AffectedBounds);
  200. }
  201. else
  202. {
  203. RebarRenderer.RebarStyleRenderer.DrawBackground(e.Graphics, e.ToolStrip.ClientRectangle);
  204. }
  205. }
  206. }
  207. }
  208.  
  209. /// <summary>
  210. /// Raises the render tool strip border event.
  211. /// </summary>
  212. /// <param name="e">The <see cref="System.Windows.Forms.ToolStripRenderEventArgs"/> instance containing the event data.</param>
  213. protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
  214. {
  215. if (!(e.ToolStrip.Parent is ToolStripPanel))
  216. {
  217. base.OnRenderToolStripBorder(e);
  218. }
  219. }
  220.  
  221. /// <summary>
  222. /// Raises the <see cref="E:System.Windows.Forms.ToolStripRenderer.RenderToolStripPanelBackground"></see> event.
  223. /// </summary>
  224. /// <param name="e">A <see cref="T:System.Windows.Forms.ToolStripPanelRenderEventArgs"></see> that contains the event data.</param>
  225. protected override void OnRenderToolStripPanelBackground(ToolStripPanelRenderEventArgs e)
  226. {
  227. if (ToolStripManager.VisualStylesEnabled && VisualStyleRenderer.IsSupported)
  228. {
  229. e.Handled = true;
  230. RebarRenderer.RebarStyleRenderer.DrawBackground(e.Graphics, e.ToolStripPanel.ClientRectangle);
  231.  
  232. Edges edge = Edges.Top;
  233. switch (e.ToolStripPanel.Dock)
  234. {
  235. case DockStyle.Left:
  236. edge = Edges.Right;
  237. break;
  238.  
  239. case DockStyle.Right:
  240. edge = Edges.Left;
  241. break;
  242. }
  243. foreach (ToolStripPanelRow row in e.ToolStripPanel.Rows)
  244. {
  245. Rectangle edgeBounds = row.Bounds;
  246. if (edge == Edges.Top)
  247. {
  248. edgeBounds.Offset(0, -1);
  249. }
  250. RebarRenderer.RebarBandStyleRenderer.DrawEdge(e.Graphics, edgeBounds, edge, EdgeStyle.Etched, EdgeEffects.None);
  251. }
  252. }
  253. else
  254. {
  255. e.Handled = true;
  256.  
  257. Size paddingSize = SystemInformation.Border3DSize;
  258.  
  259. Rectangle bounds = e.ToolStripPanel.ClientRectangle;
  260. RebarRenderer.FillRectangle(e.Graphics, bounds, SystemColors.Menu);
  261. ControlPaint.DrawBorder3D(e.Graphics, bounds, Border3DStyle.Etched, Border3DSide.All);
  262.  
  263. foreach (ToolStripPanelRow row in e.ToolStripPanel.Rows)
  264. {
  265. Rectangle edgeBounds = row.Bounds;
  266. edgeBounds.Width -= paddingSize.Width;
  267. ControlPaint.DrawBorder3D(e.Graphics, edgeBounds, Border3DStyle.Etched, Border3DSide.Bottom);
  268. }
  269. }
  270. }
  271.  
  272. private static void FillRectangle(Graphics g, Rectangle rectangle, Color color)
  273. {
  274. if (color.IsSystemColor)
  275. {
  276. g.FillRectangle(SystemBrushes.FromSystemColor(color), rectangle);
  277. }
  278. else
  279. {
  280. using (Brush brush = new SolidBrush(color))
  281. {
  282. g.FillRectangle(brush, rectangle);
  283. }
  284. }
  285.  
  286. }
  287.  
  288. #endregion
  289. }
  290. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/view/style/ 
IcôneNomTailleModification
IcôneNomTailleModification
| _ Répertoire parent0 octets1716496476 23/05/2024 22:34:36
| _vista0 octets1541007202 31/10/2018 18:33:22
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/view/style/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csOffice2007Renderer.cs58.44 Ko31/10/2018 18:33:16-refusé-
Afficher le fichier .cs|.csStyleHelper.cs1.44 Ko31/10/2018 18:33:16-refusé-
Afficher le fichier .cs|.csProfessionalColorTableFactory.cs57.94 Ko31/10/2018 18:33:16-refusé-
Afficher le fichier .cs|.csControlStyleColors.cs4.76 Ko31/10/2018 18:33:15-refusé-
Afficher le fichier .cs|.csCustomSystemColors.cs14.28 Ko31/10/2018 18:33:15-refusé-
Afficher le fichier .cs|.csStyleFactory.cs18.11 Ko31/10/2018 18:33:16-refusé-
Afficher le fichier .cs|.csRebarRenderer.cs11.97 Ko31/10/2018 18:33:16-refusé-
Afficher le fichier .cs|.csOrangeStyleColors.cs14.47 Ko31/10/2018 18:33:16-refusé-
Afficher le fichier .cs|.csOffice2007ColorTable.cs13.46 Ko31/10/2018 18:33:15-refusé-
Afficher le fichier .cs|.csXpStyle.cs1.42 Ko31/10/2018 18:33:16-refusé-
Afficher le fichier .cs|.csOffice2007Helpers.cs4.16 Ko31/10/2018 18:33:15-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/style//RebarRenderer.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.