WindowsVistaRenderer.cs
Description du code
WindowsVistaRenderer.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
Code c# (WindowsVistaRenderer.cs) (779 lignes)
using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; namespace be.gaudry.view.style { /// <summary> /// Renders toolstrip items using Windows Vista look and feel /// </summary> /// <remarks> /// 2007 José Manuel Menéndez Poo /// Visit my blog for upgrades and other renderers - www.menendezpoo.com /// </remarks> public class WindowsVistaRenderer : ToolStripRenderer { #region Static /// <summary> /// Creates the glow of the buttons /// </summary> /// <param name="rectangle"></param> /// <returns></returns> private static GraphicsPath CreateBottomRadialPath(Rectangle rectangle) { RectangleF rect = rectangle; rect.X -= rect.Width * .35f; rect.Y -= rect.Height * .15f; rect.Width *= 1.7f; rect.Height *= 2.3f; path.AddEllipse(rect); path.CloseFigure(); return path; } /// <summary> /// Creates the chevron for the overflow button /// </summary> /// <param name="overflowButtonSize"></param> /// <returns></returns> private static GraphicsPath CreateOverflowChevron(Size overflowButtonSize) { int segmentWidth = 3; int segmentHeight = 3; int segmentSeparation = 5; int chevronWidth = segmentWidth + segmentSeparation; int chevronHeight = segmentHeight * 2; int chevronLeft = (r.Width - chevronWidth) / 2; int chevronTop = (r.Height - chevronHeight) / 2; // Segment \ path.AddLine( // Segment / path.AddLine( path.StartFigure(); // Segment \ path.AddLine( // Segment / path.AddLine( return path; } #endregion #region Fields private WindowsVistaColorTable _colorTable; private bool _glossyEffect; private bool _bgglow; private int _toolstripRadius; private int _buttonRadius; #endregion #region Ctor public WindowsVistaRenderer() { GlossyEffect = true; BackgroundGlow = true; ToolStripRadius = 2; ButtonRadius = 2; } #endregion #region Properties /// <summary> /// Gets or sets the buttons rectangle radius /// </summary> public int ButtonRadius { get { return _buttonRadius; } set { _buttonRadius = value; } } /// <summary> /// Gets or sets the radius of the rectangle of the hole ToolStrip /// </summary> public int ToolStripRadius { get { return _toolstripRadius; } set { _toolstripRadius = value; } } /// <summary> /// Gets ors sets if background glow should be rendered /// </summary> public bool BackgroundGlow { get { return _bgglow; } set { _bgglow = value; } } /// <summary> /// Gets or sets if glossy effect should be rendered /// </summary> public bool GlossyEffect { get { return _glossyEffect; } set { _glossyEffect = value; } } /// <summary> /// Gets or sets the color table of the renderer /// </summary> public WindowsVistaColorTable ColorTable { get { return _colorTable; } set { _colorTable = value; } } #endregion #region Methods /// <summary> /// Initializes properties for ToolStripMenuItem objects /// </summary> /// <param name="item"></param> protected virtual void InitializeToolStripMenuItem(ToolStripMenuItem item) { item.AutoSize = false; item.Height = 26; item.TextAlign = ContentAlignment.MiddleLeft; foreach (ToolStripItem subitem in item.DropDownItems) { { InitializeToolStripMenuItem(subitem as ToolStripMenuItem); } } } /// <summary> /// Gets a rounded rectangle representing the hole area of the toolstrip /// </summary> /// <param name="toolStrip"></param> /// <returns></returns> private GraphicsPath GetToolStripRectangle(ToolStrip toolStrip) { return GraphicsTools.CreateRoundRectangle( } /// <summary> /// Draws the glossy effect on the toolbar /// </summary> /// <param name="g"></param> /// <param name="t"></param> /// <returns></returns> private void DrawGlossyEffect(Graphics g, ToolStrip t) { DrawGlossyEffect(g, t, 0); } /// <summary> /// Draws the glossy effect on the toolbar /// </summary> /// <param name="g"></param> /// <param name="t"></param> /// <returns></returns> private void DrawGlossyEffect(Graphics g, ToolStrip t, int offset) { t.Width - 1, (t.Height - 1) / 2); ColorTable.GlossyEffectNorth, ColorTable.GlossyEffectSouth)) { using (GraphicsPath border = GraphicsTools.CreateTopRoundRectangle(glossyRect, ToolStripRadius)) { g.FillPath(b, border); } } } /// <summary> /// Renders the background of a button /// </summary> /// <param name="e"></param> private void DrawVistaButtonBackground(ToolStripItemRenderEventArgs e) { bool chk = false; { } DrawVistaButtonBackground(e.Graphics, e.Item.Selected, e.Item.Pressed, chk); } /// <summary> /// Renders the background of a button on the specified rectangle using the specified device /// </summary> /// <param name="e"></param> private void DrawVistaButtonBackground(Graphics g, Rectangle r, bool selected, bool pressed, bool checkd) { g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle border = outerBorder; border.Inflate(-1, -1); Rectangle innerBorder = border; innerBorder.Inflate(-1, -1); Rectangle glossy = outerBorder; glossy.Height /= 2; Rectangle fill = innerBorder; fill.Height /= 2; Rectangle glow = Rectangle.FromLTRB(outerBorder.Left, outerBorder.Top + Convert.ToInt32(Convert.ToSingle(outerBorder.Height) * .5f), outerBorder.Right, outerBorder.Bottom); if (selected || pressed || checkd) { #region Layers //Outer border using (GraphicsPath path = GraphicsTools.CreateRoundRectangle(outerBorder, ButtonRadius)) { { g.DrawPath(p, path); } } //Checked fill if (checkd) { using (GraphicsPath path = GraphicsTools.CreateRoundRectangle(innerBorder, 2)) { using (Brush b = new SolidBrush(selected ? ColorTable.CheckedButtonFillHot : ColorTable.CheckedButtonFill)) { g.FillPath(b, path); } } } //Glossy effefct using (GraphicsPath path = GraphicsTools.CreateTopRoundRectangle(glossy, ButtonRadius)) { ColorTable.GlossyEffectNorth, ColorTable.GlossyEffectSouth)) { g.FillPath(b, path); } } //Border using (GraphicsPath path = GraphicsTools.CreateRoundRectangle(border, ButtonRadius)) { { g.DrawPath(p, path); } } Color fillNorth = pressed ? ColorTable.ButtonFillNorthPressed : ColorTable.ButtonFillNorth; Color fillSouth = pressed ? ColorTable.ButtonFillSouthPressed : ColorTable.ButtonFillSouth; //Fill using (GraphicsPath path = GraphicsTools.CreateTopRoundRectangle(fill, ButtonRadius)) { fillNorth, fillSouth)) { g.FillPath(b, path); } } Color innerBorderColor = pressed || checkd ? ColorTable.ButtonInnerBorderPressed : ColorTable.ButtonInnerBorder; //Inner border using (GraphicsPath path = GraphicsTools.CreateRoundRectangle(innerBorder, ButtonRadius)) { { g.DrawPath(p, path); } } //Glow using (GraphicsPath clip = GraphicsTools.CreateRoundRectangle(glow, 2)) { g.SetClip(clip, CombineMode.Intersect); Color glowColor = ColorTable.Glow; if (checkd) { if (selected) { glowColor = ColorTable.CheckedGlowHot; } else { glowColor = ColorTable.CheckedGlow; } } using (GraphicsPath brad = CreateBottomRadialPath(glow)) { { { int opacity = 255; RectangleF bounds = brad.GetBounds(); pgr.CenterColor = Color.FromArgb(opacity, glowColor); } g.FillPath(pgr, brad); } } g.ResetClip(); } #endregion } } /// <summary> /// Draws the background of a menu, vista style /// </summary> /// <param name="e"></param> private void DrawVistaMenuBackground(ToolStripItemRenderEventArgs e) { DrawVistaMenuBackground(e.Graphics, } /// <summary> /// Draws the background of a menu, vista style /// </summary> /// <param name="g"></param> /// <param name="r"></param> /// <param name="highlighted"></param> private void DrawVistaMenuBackground(Graphics g, Rectangle r, bool highlighted, bool isMainMenu) { //g.Clear(ColorTable.MenuBackground); int margin = 2; int left = 22; #region IconSeparator if (!isMainMenu) { { g.DrawLine(p, } { g.DrawLine(p, } } #endregion if (highlighted) { #region Draw Rectangle using (GraphicsPath path = GraphicsTools.CreateRoundRectangle( { ColorTable.MenuHighlightNorth, ColorTable.MenuHighlightSouth)) { g.FillPath(b, path); } { g.DrawPath(p, path); } } #endregion } } /// <summary> /// Draws the border of the vista menu window /// </summary> /// <param name="g"></param> /// <param name="r"></param> private void DrawVistaMenuBorder(Graphics g, Rectangle r) { { g.DrawRectangle(p, } } #endregion protected override void Initialize(ToolStrip toolStrip) { base.Initialize(toolStrip); toolStrip.AutoSize = false; toolStrip.Height = 35; toolStrip.ForeColor = ColorTable.Text; toolStrip.GripStyle = ToolStripGripStyle.Hidden; } protected override void InitializeItem(ToolStripItem item) { base.InitializeItem(item); //Don't Affect ForeColor of TextBoxes and ComboBoxes { item.ForeColor = ColorTable.Text; } { ToolStripSplitButton btn = item as ToolStripSplitButton; btn.DropDownButtonWidth = 18; foreach (ToolStripItem subitem in btn.DropDownItems) { { InitializeToolStripMenuItem(subitem as ToolStripMenuItem); } } } { ToolStripDropDownButton btn = item as ToolStripDropDownButton; btn.ShowDropDownArrow = false; foreach (ToolStripItem subitem in btn.DropDownItems) { { InitializeToolStripMenuItem(subitem as ToolStripMenuItem); } } } } protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e) { { #region Draw Rectangled Border DrawVistaMenuBorder(e.Graphics, #endregion } else { #region Draw Rounded Border e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; using (GraphicsPath path = GetToolStripRectangle(e.ToolStrip)) { { e.Graphics.DrawPath(p, path); } } #endregion } } protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e) { { return; } #region Background ColorTable.BackgroundNorth, ColorTable.BackgroundSouth)) { using (GraphicsPath border = GetToolStripRectangle(e.ToolStrip)) { e.Graphics.FillPath(b, border); } } #endregion if (GlossyEffect) { #region Glossy Effect DrawGlossyEffect(e.Graphics, e.ToolStrip, 1); #endregion } if (BackgroundGlow) { #region BackroundGlow int glowSize = Convert.ToInt32(Convert.ToSingle(e.ToolStrip.Height) * 0.15f); e.ToolStrip.Height - glowSize - 1, e.ToolStrip.Width - 1, glowSize); Color.FromArgb(0, ColorTable.BackgroundGlow), ColorTable.BackgroundGlow)) { using (GraphicsPath border = GraphicsTools.CreateBottomRoundRectangle(glow, ToolStripRadius)) { e.Graphics.FillPath(b, border); } } #endregion } } protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e) { { e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; } { e.TextRectangle = r; e.TextColor = ColorTable.MenuText; } base.OnRenderItemText(e); } protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e) { DrawVistaButtonBackground(e); } protected override void OnRenderDropDownButtonBackground(ToolStripItemRenderEventArgs e) { DrawVistaButtonBackground(e); ToolStripDropDownButton item = e.Item as ToolStripDropDownButton; if (item == null) return; e.Graphics, e.Item, arrowBounds, ColorTable.DropDownArrow, ArrowDirection.Down)); } protected override void OnRenderSplitButtonBackground(ToolStripItemRenderEventArgs e) { DrawVistaButtonBackground(e); ToolStripSplitButton item = e.Item as ToolStripSplitButton; if(item==null) return; Rectangle arrowBounds = item.DropDownButtonBounds; Rectangle dropDownBounds = item.DropDownButtonBounds; DrawVistaButtonBackground(e.Graphics, buttonBounds, item.ButtonSelected, item.ButtonPressed, false); DrawVistaButtonBackground(e.Graphics, dropDownBounds, item.DropDownButtonSelected, item.DropDownButtonPressed, false); e.Graphics, e.Item, arrowBounds, ColorTable.DropDownArrow, ArrowDirection.Down)); } protected override void OnRenderItemImage(ToolStripItemImageRenderEventArgs e) { if (!e.Item.Enabled) { base.OnRenderItemImage(e); } else { if (e.Image != null) { e.Graphics.DrawImage(e.Image, e.ImageRectangle); } } } protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e) { { DrawVistaButtonBackground(e); } else { DrawVistaMenuBackground(e.Graphics, } } protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e) { if (e.Item.IsOnDropDown) { int left = 20; int right = e.Item.Width - 3; int top = e.Item.Height / 2; top--; //e.Graphics.Clear(ColorTable.MenuBackground); { e.Graphics.DrawLine(p, } { e.Graphics.DrawLine(p, } } else { int top = 3; int left = e.Item.Width / 2; left--; int height = e.Item.Height - top * 2; separator.Location, ColorTable.SeparatorNorth, ColorTable.SeparatorSouth)) { e.Graphics.FillRectangle(b, separator); } } } protected override void OnRenderOverflowButtonBackground(ToolStripItemRenderEventArgs e) { DrawVistaButtonBackground(e); //Chevron is obtained from the character: » (Alt+0187) { sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; } } protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e) { { e.ArrowColor = ColorTable.MenuText; } base.OnRenderArrow(e); } } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Pas de sous-répertoires. | |||
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1730802906 05/11/2024 11:35:06 |
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/style/vista//WindowsVistaRenderer.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.