public static void DrawBottomPointingThumb(Graphics g, Rectangle bounds, TrackBarThumbState state)
		{
			if (!IsSupported)
				throw new InvalidOperationException ();

			VisualStyleRenderer vsr;

			switch (state) {
				case TrackBarThumbState.Disabled:
					vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Disabled);
					break;
				case TrackBarThumbState.Hot:
					vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Hot);
					break;
				case TrackBarThumbState.Normal:
				default:
					vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Normal);
					break;
				case TrackBarThumbState.Pressed:
					vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbBottom.Pressed);
					break;
			}

			vsr.DrawBackground (g, bounds);
		}
 protected override void Draw(Graphics dc, string title, string text, Rectangle rect, Rectangle titleRect, Rectangle bodyRect, Image img, int iconWidth)
 {
     if (IsDefined(VisualStyleElement.ToolTip.BalloonTitle.Normal) && IsDefined(VisualStyleElement.ToolTip.Balloon.Normal))
     {
         VisualStyleRenderer titleRenderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.BalloonTitle.Normal);
         VisualStyleRenderer balloonRenderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.Balloon.Normal);
         balloonRenderer.DrawBackground(dc, rect);
         // drawing title
         titleRenderer.DrawText(dc,
             new Rectangle(Padding.Left + iconWidth, Padding.Top, rect.Width - iconWidth - (Padding.Left + Padding.Right), titleRect.Height),
             title, false, TextFormatFlags.Left | TextFormatFlags.WordEllipsis | TextFormatFlags.VerticalCenter);
         // drawing text
         Rectangle balloonTextBounds = new Rectangle(Padding.Left + iconWidth, Padding.Top + titleRect.Height, rect.Width - iconWidth - (Padding.Left + Padding.Right), rect.Height - (Padding.Top + titleRect.Height + Padding.Bottom));
         balloonRenderer.DrawText(dc, balloonTextBounds,
             text, false, TextFormatFlags.Left | TextFormatFlags.WordBreak | TextFormatFlags.VerticalCenter);
     }
     else
     {
         dc.FillRectangle(SystemBrushes.Info, rect);
         dc.DrawRectangle(Pens.Black, new Rectangle(0, 0, rect.Width - 1, rect.Height - 1));
         dc.DrawString(title, new Font(SystemFonts.DefaultFont, FontStyle.Bold), SystemBrushes.InfoText,
             new PointF(Padding.Left + iconWidth, Padding.Top), new StringFormat(StringFormatFlags.NoWrap));
         dc.DrawString(text, SystemFonts.DefaultFont, SystemBrushes.InfoText,
             new RectangleF(Padding.Left + iconWidth, Padding.Top + titleRect.Height, bodyRect.Width, bodyRect.Height),
             new StringFormat());
     }
 }
 public override void OnRendererTabPageArea(Graphics gfx, Rectangle tabPageAreaRct)
 {
     if (Application.RenderWithVisualStyles)
     {
         VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Tab.Pane.Normal);
         renderer.DrawBackground(gfx, tabPageAreaRct);
     }
     else
     {
         Rectangle linesRct = tabPageAreaRct;
         // Draw top 2px line.
         using (Brush brush = new SolidBrush(Color.FromArgb(2, 111, 194)))
             gfx.FillRectangle(brush, linesRct.Left, linesRct.Top, linesRct.Width, 2);
         // Draw left, right and bottom 1px lines.
         using (Pen pen = new Pen(Color.FromArgb(183, 192, 197)))
         {
             // Create border points.
             Point[] points = new Point[]
             {
                 // Left point.
                 new Point(linesRct.Left, linesRct.Top + 2),
                 // Bottom points.
                 new Point(linesRct.Left, linesRct.Bottom - 1),
                 new Point(linesRct.Right - 1, linesRct.Bottom - 1),
                 // Right point.
                 new Point(linesRct.Right - 1, linesRct.Top + 2)
             };
             gfx.DrawLines(pen, points);
         }
     }
 }
        private void RenderItemInternal(ToolStripItemRenderEventArgs e)
        {
            ToolStripItem      item         = e.Item;
            Graphics           dc           = e.Graphics;
            ToolBarState       toolBarState = GetToolBarState(item);
            VisualStyleElement normal       = VisualStyleElement.ToolBar.Button.Normal;

            if (ToolStripManager.VisualStylesEnabled && System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsElementDefined(normal))
            {
                System.Windows.Forms.VisualStyles.VisualStyleRenderer visualStyleRenderer = VisualStyleRenderer;
                visualStyleRenderer.SetParameters(normal.ClassName, normal.Part, (int)toolBarState);
                visualStyleRenderer.DrawBackground(dc, new Rectangle(Point.Empty, item.Size));
            }
            else
            {
                this.RenderSmall3DBorderInternal(dc, new Rectangle(Point.Empty, item.Size), toolBarState, item.RightToLeft == RightToLeft.Yes);
            }
            Rectangle contentRectangle = item.ContentRectangle;

            if (item.BackgroundImage != null)
            {
                ControlPaint.DrawBackgroundImage(dc, item.BackgroundImage, item.BackColor, item.BackgroundImageLayout, contentRectangle, contentRectangle);
            }
            else
            {
                ToolStrip currentParent = item.GetCurrentParent();
                if (((currentParent != null) && (toolBarState != ToolBarState.Checked)) && (item.BackColor != currentParent.BackColor))
                {
                    FillBackground(dc, contentRectangle, item.BackColor);
                }
            }
        }
 public static void DrawCloseButton(IDeviceContext dc, Rectangle rect, Padding padding, ToolTipBalloonCloseButtonState buttonState)
 {
     VisualStyleElement btn = GetCloseButtonVS(buttonState);
     VisualStyleRenderer renderer = new VisualStyleRenderer(btn);
     Rectangle btnRect = GetCloseButtonRect(dc, rect, padding, buttonState);
     renderer.DrawBackground(dc, btnRect);
 }
Beispiel #6
0
 private static void DrawThemeBackground(IDeviceContext dc, VisualStyleElement element, Rectangle bounds, Rectangle clipRectangle)
 {
     if( DialogHelper.IsTaskDialogThemeSupported )
     {
         VisualStyleRenderer renderer = new VisualStyleRenderer(element);
         renderer.DrawBackground(dc, bounds, clipRectangle);
     }
 }
		protected override void OnPaint(PaintEventArgs e)
		{
			Graphics g = e.Graphics;
			if(g == null) { base.OnPaint(e); return; }

			int nNormalizedPos = m_nPosition - m_nMinimum;
			int nNormalizedMax = m_nMaximum - m_nMinimum;

			Rectangle rectClient = this.ClientRectangle;
			Rectangle rectDraw;
			if(VisualStyleRenderer.IsSupported)
			{
				VisualStyleRenderer vsr = new VisualStyleRenderer(
					VisualStyleElement.ProgressBar.Bar.Normal);
				vsr.DrawBackground(g, rectClient);

				rectDraw = vsr.GetBackgroundContentRectangle(g, rectClient);
			}
			else
			{
				g.FillRectangle(SystemBrushes.Control, rectClient);

				g.DrawLine(Pens.Gray, 0, 0, rectClient.Width - 1, 0);
				g.DrawLine(Pens.Gray, 0, 0, 0, rectClient.Height - 1);
				g.DrawLine(Pens.White, rectClient.Width - 1, 0,
					rectClient.Width - 1, rectClient.Height - 1);
				g.DrawLine(Pens.White, 0, rectClient.Height - 1,
					rectClient.Width - 1, rectClient.Height - 1);

				rectDraw = new Rectangle(rectClient.X + 1, rectClient.Y + 1,
					rectClient.Width - 2, rectClient.Height - 2);
			}

			Rectangle rectGradient = new Rectangle(rectDraw.X, rectDraw.Y,
				rectDraw.Width, rectDraw.Height);
			if((rectGradient.Width & 1) == 0) ++rectGradient.Width;

			int nDrawWidth = (int)((float)rectDraw.Width * ((float)nNormalizedPos /
				(float)nNormalizedMax));

			Color clrStart = Color.FromArgb(255, 128, 0);
			Color clrEnd = Color.FromArgb(0, 255, 0);

			bool bRtl = (this.RightToLeft == RightToLeft.Yes);
			if(bRtl)
			{
				Color clrTemp = clrStart;
				clrStart = clrEnd;
				clrEnd = clrTemp;
			}
			
			using(LinearGradientBrush brush = new LinearGradientBrush(rectGradient,
				clrStart, clrEnd, LinearGradientMode.Horizontal))
			{
				g.FillRectangle(brush, (bRtl ? (rectDraw.Width - nDrawWidth + 1) :
					rectDraw.Left), rectDraw.Top, nDrawWidth, rectDraw.Height);
			}
		}
Beispiel #8
0
 // If possible, give the window that nice gradient look
 protected override void OnPaintBackground(PaintEventArgs e)
 {
     if (VisualStyleRenderer.IsSupported) {
       VisualStyleRenderer VSR = new VisualStyleRenderer(VisualStyleElement.Tab.Body.Normal);
     VSR.DrawBackground(e.Graphics, this.ClientRectangle, e.ClipRectangle);
       }
       else
     base.OnPaintBackground(e);
 }
		public static void DrawVerticalChunks (Graphics g, Rectangle bounds)
		{
			if (!IsSupported)
				throw new InvalidOperationException ();

			VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ProgressBar.ChunkVertical.Normal);

			vsr.DrawBackground (g, bounds);
		}
Beispiel #10
0
		public static void DrawGroupBox (Graphics g, Rectangle bounds, string groupBoxText, Font font, Color textColor, TextFormatFlags flags, GroupBoxState state)
		{
			Size font_size = TextRenderer.MeasureText (groupBoxText, font);

			if (Application.RenderWithVisualStyles || always_use_visual_styles == true) {
				VisualStyleRenderer vsr;
				Rectangle new_bounds;

				switch (state) {
					case GroupBoxState.Normal:
					default:
						vsr = new VisualStyleRenderer (VisualStyleElement.Button.GroupBox.Normal);
						new_bounds = new Rectangle (bounds.Left, bounds.Top + (int)(font_size.Height / 2) - 1, bounds.Width, bounds.Height - (int)(font_size.Height / 2) + 1);
						break;
					case GroupBoxState.Disabled:
						vsr = new VisualStyleRenderer (VisualStyleElement.Button.GroupBox.Disabled);
						new_bounds = new Rectangle (bounds.Left, bounds.Top + (int)(font_size.Height / 2) - 2, bounds.Width, bounds.Height - (int)(font_size.Height / 2) + 2);
						break;
				}

				if (groupBoxText == String.Empty)
					vsr.DrawBackground (g, bounds);
				else
					vsr.DrawBackgroundExcludingArea (g, new_bounds, new Rectangle (bounds.Left + 9, bounds.Top, font_size.Width - 3, font_size.Height));

				if (textColor == Color.Empty)
					textColor = vsr.GetColor (ColorProperty.TextColor);

				if (groupBoxText != String.Empty)
					TextRenderer.DrawText (g, groupBoxText, font, new Point (bounds.Left + 8, bounds.Top), textColor, flags);
			}
			else {
				// MS has a pretty big bug when rendering the non-visual styles group box.  Instead of using the height
				// part of the bounds as height, they use it as the bottom, so the boxes are drawn in completely different
				// places.  Rather than emulate this bug, we do it correctly.  After googling for a while, I don't think
				// anyone has ever actually used this class for anything, so it should be fine.  :)
				Rectangle new_bounds = new Rectangle (bounds.Left, bounds.Top + (int)(font_size.Height / 2), bounds.Width, bounds.Height - (int)(font_size.Height / 2));
				
				// Don't paint over the background where we are going to put the text
				Region old_clip = g.Clip;
				g.SetClip (new Rectangle (bounds.Left + 9, bounds.Top, font_size.Width - 3, font_size.Height), System.Drawing.Drawing2D.CombineMode.Exclude);
				
				ControlPaint.DrawBorder3D (g, new_bounds, Border3DStyle.Etched);
				
				g.Clip = old_clip;

				if (groupBoxText != String.Empty) {
					if (textColor == Color.Empty)
						textColor = state == GroupBoxState.Normal ? SystemColors.ControlText :
							SystemColors.GrayText;
					TextRenderer.DrawText (g, groupBoxText, font, new Point (bounds.Left + 8, bounds.Top), textColor, flags);
				}
			}
		}
        private void RenderSeparatorInternal(Graphics g, ToolStripItem item, Rectangle bounds, bool vertical)
        {
            VisualStyleElement element = vertical ? VisualStyleElement.ToolBar.SeparatorHorizontal.Normal : VisualStyleElement.ToolBar.SeparatorVertical.Normal;

            if (ToolStripManager.VisualStylesEnabled && System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsElementDefined(element))
            {
                System.Windows.Forms.VisualStyles.VisualStyleRenderer visualStyleRenderer = VisualStyleRenderer;
                visualStyleRenderer.SetParameters(element.ClassName, element.Part, GetItemState(item));
                visualStyleRenderer.DrawBackground(g, bounds);
            }
            else
            {
                Color foreColor   = item.ForeColor;
                Color backColor   = item.BackColor;
                Pen   controlDark = SystemPens.ControlDark;
                bool  pen         = GetPen(foreColor, ref controlDark);
                try
                {
                    if (vertical)
                    {
                        if (bounds.Height >= 4)
                        {
                            bounds.Inflate(0, -2);
                        }
                        bool flag2 = item.RightToLeft == RightToLeft.Yes;
                        Pen  pen2  = flag2 ? SystemPens.ButtonHighlight : controlDark;
                        Pen  pen3  = flag2 ? controlDark : SystemPens.ButtonHighlight;
                        int  num   = bounds.Width / 2;
                        g.DrawLine(pen2, num, bounds.Top, num, bounds.Bottom);
                        num++;
                        g.DrawLine(pen3, num, bounds.Top, num, bounds.Bottom);
                    }
                    else
                    {
                        if (bounds.Width >= 4)
                        {
                            bounds.Inflate(-2, 0);
                        }
                        int num2 = bounds.Height / 2;
                        g.DrawLine(controlDark, bounds.Left, num2, bounds.Right, num2);
                        num2++;
                        g.DrawLine(SystemPens.ButtonHighlight, bounds.Left, num2, bounds.Right, num2);
                    }
                }
                finally
                {
                    if (pen && (controlDark != null))
                    {
                        controlDark.Dispose();
                    }
                }
            }
        }
 public override void DrawCloseButton(Graphics dc, Rectangle rect, TooltipCloseButtonState buttonState)
 {
     VisualStyleElement btn = GetCloseButtonVS(buttonState);
     Rectangle btnRect = GetCloseButtonRect(dc, rect, buttonState);
     if (IsDefined(btn))
     {
         VisualStyleRenderer renderer = new VisualStyleRenderer(btn);
         renderer.DrawBackground(dc, btnRect);
     }
     else
         base.DrawCloseButton(dc, rect, buttonState);
 }
        private void VerticleProgressBar_Paint(object sender, PaintEventArgs e)
        {
            VisualStyleRenderer rBar = new VisualStyleRenderer(VisualStyleElement.ProgressBar.BarVertical.Normal);

            rBar.DrawBackground(e.Graphics, e.ClipRectangle);

            VisualStyleRenderer rChunk = new VisualStyleRenderer(VisualStyleElement.ProgressBar.ChunkVertical.Normal);

            rChunk.DrawBackground(e.Graphics, new Rectangle(
                new Point(e.ClipRectangle.Left + 1, e.ClipRectangle.Top + 1 + (int)(this.Size.Height * (1 - _value))),
                new Size(this.Size.Width - 2, (int)(this.Size.Height * _value) - 2)));
        }
 private static void RenderStatusStripBackground(ToolStripRenderEventArgs e)
 {
     if (Application.RenderWithVisualStyles)
     {
         System.Windows.Forms.VisualStyles.VisualStyleRenderer visualStyleRenderer = VisualStyleRenderer;
         visualStyleRenderer.SetParameters(VisualStyleElement.Status.Bar.Normal);
         visualStyleRenderer.DrawBackground(e.Graphics, new Rectangle(0, 0, e.ToolStrip.Width - 1, e.ToolStrip.Height - 1));
     }
     else if (!SystemInformation.InLockedTerminalSession())
     {
         e.Graphics.Clear(e.BackColor);
     }
 }
Beispiel #15
0
 // The UseVisualStyleBackColor only uses a plain background color, not the background rendering for
 // the current visual style.  This corrects that error.
 protected override void OnPaintBackground(PaintEventArgs e)
 {
     if (!VisualStyleRenderer.IsSupported || !this.UseVisualStyleBackColor) {
     base.OnPaintBackground(e);
     return;
       }
     TabControl P = this.Parent as TabControl;
       if (P == null || P.Appearance != TabAppearance.Normal) {
     base.OnPaintBackground(e);
     return;
       }
     VisualStyleRenderer VSR = new VisualStyleRenderer(VisualStyleElement.Tab.Body.Normal);
       VSR.DrawBackground(e.Graphics, this.ClientRectangle, e.ClipRectangle);
 }
Beispiel #16
0
        /// <summary>
        /// Paints the sizing grip.
        /// </summary>
        /// <param name="e">The <see cref="System.Windows.Forms.PaintEventArgs" /> instance containing the event data.</param>
        public void PaintSizeGrip(PaintEventArgs e)
        {
            if (e == null || e.Graphics == null || !_resizable)
            {
                return;
            }
            Size clientSize = Content.ClientSize;

            using (Bitmap gripImage = new Bitmap(0x10, 0x10))
            {
                using (Graphics g = Graphics.FromImage(gripImage))
                {
                    if (Application.RenderWithVisualStyles)
                    {
                        if (_sizeGripRenderer == null)
                        {
                            _sizeGripRenderer = new VS.VisualStyleRenderer(VS.VisualStyleElement.Status.Gripper.Normal);
                        }
                        _sizeGripRenderer.DrawBackground(g, new Rectangle(0, 0, 0x10, 0x10));
                    }
                    else
                    {
                        ControlPaint.DrawSizeGrip(g, Content.BackColor, 0, 0, 0x10, 0x10);
                    }
                }
                GraphicsState gs = e.Graphics.Save();
                e.Graphics.ResetTransform();
                if (_resizableTop)
                {
                    if (_resizableLeft)
                    {
                        e.Graphics.RotateTransform(180);
                        e.Graphics.TranslateTransform(-clientSize.Width, -clientSize.Height);
                    }
                    else
                    {
                        e.Graphics.ScaleTransform(1, -1);
                        e.Graphics.TranslateTransform(0, -clientSize.Height);
                    }
                }
                else if (_resizableLeft)
                {
                    e.Graphics.ScaleTransform(-1, 1);
                    e.Graphics.TranslateTransform(-clientSize.Width, 0);
                }
                e.Graphics.DrawImage(gripImage, clientSize.Width - 0x10, clientSize.Height - 0x10 + 1, 0x10, 0x10);
                e.Graphics.Restore(gs);
            }
        }
Beispiel #17
0
        private static void DrawHeaderBackground(Graphics gr, VisualStyleRenderer renderer, Rectangle rect)
        {
            if (renderer != null)
                renderer.DrawBackground(gr, rect);
            else
            {
                gr.FillRectangle(SystemBrushes.Control, rect);

                gr.DrawLine(SystemPens.ControlDark, rect.X, rect.Bottom - 2, rect.Right, rect.Bottom - 2);
                gr.DrawLine(SystemPens.ControlLightLight, rect.X, rect.Bottom - 1, rect.Right, rect.Bottom - 1);

                gr.DrawLine(SystemPens.ControlDark, rect.Right - 2, rect.Y, rect.Right - 2, rect.Bottom - 2);
                gr.DrawLine(SystemPens.ControlLightLight, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 1);
            }
        }
        protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
        {
            if (e.Item.IsOnDropDown && IsSupported)
            {

                var renderer = new VisualStyleRenderer("menu", 14, GetItemState(e.Item));

                var backgroundRectangle = new Rectangle(e.Item.ContentRectangle.X + 1, 0, e.Item.ContentRectangle.Width - 1, e.Item.Bounds.Height);
                renderer.DrawBackground(e.Graphics, backgroundRectangle, backgroundRectangle);

            }
            else
            {
                base.OnRenderMenuItemBackground(e);
            }
        }
		private void DrawBackground() {

			if (_backgroundOverlay == null) {
				_backgroundOverlay = Utilities.ResourceHelper.GetResourcePNG("shell32.dll", "632");
			}

			VisualStyleElement cpGradient = VisualStyleElement.CreateElement("CONTROLPANEL", 1, 0);
			VisualStyleRenderer renderer = new VisualStyleRenderer(cpGradient);
			Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);

			using (Graphics g = Graphics.FromImage(_background)) {
				renderer.DrawBackground(g, rect);
				g.DrawImage(_backgroundOverlay, 0, 0, _backgroundOverlay.Width, _backgroundOverlay.Height);
			}

		}
Beispiel #20
0
        private void NotesTip_Draw(object sender, DrawToolTipEventArgs e)
        {
            // *******************************************************************
            if (Application.RenderWithVisualStyles)
            {
                VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.Standard.Normal);
                renderer.DrawBackground(e.Graphics, e.Bounds);
            }
            else
            {
                e.Graphics.FillRectangle(SystemBrushes.Info, e.Bounds);
                e.Graphics.DrawRectangle(SystemPens.WindowFrame, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1));
            }
            // ******************************************************************

            // Draw something
        }
 public override void OnRendererTabPageArea(Graphics gfx, Rectangle tabPageAreaRct)
 {
     if (Application.RenderWithVisualStyles)
     {
         VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Tab.Body.Normal);
         renderer.DrawBackground(gfx, tabPageAreaRct);
     }
     else
     {
         Rectangle linesRct = tabPageAreaRct;
         linesRct.Width -= 1;
         linesRct.Height -= 1;
         // Draw 1px border rectangle.
         using (Pen pen = new Pen(Color.FromArgb(202, 202, 214)))
             gfx.DrawRectangle(pen, linesRct);
     }
 }
        protected override void OnRenderGrip(ToolStripGripRenderEventArgs e)
        {
            Graphics  dc     = e.Graphics;
            Rectangle bounds = new Rectangle(Point.Empty, e.GripBounds.Size);
            bool      flag   = e.GripDisplayStyle == ToolStripGripDisplayStyle.Vertical;

            if (ToolStripManager.VisualStylesEnabled && System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsElementDefined(VisualStyleElement.Rebar.Gripper.Normal))
            {
                System.Windows.Forms.VisualStyles.VisualStyleRenderer visualStyleRenderer = VisualStyleRenderer;
                if (flag)
                {
                    visualStyleRenderer.SetParameters(VisualStyleElement.Rebar.Gripper.Normal);
                    bounds.Height = ((bounds.Height - 2) / 4) * 4;
                    bounds.Y      = Math.Max(0, ((e.GripBounds.Height - bounds.Height) - 2) / 2);
                }
                else
                {
                    visualStyleRenderer.SetParameters(VisualStyleElement.Rebar.GripperVertical.Normal);
                }
                visualStyleRenderer.DrawBackground(dc, bounds);
            }
            else
            {
                Color backColor = e.ToolStrip.BackColor;
                FillBackground(dc, bounds, backColor);
                if (flag)
                {
                    if (bounds.Height >= 4)
                    {
                        bounds.Inflate(0, -2);
                    }
                    bounds.Width = 3;
                }
                else
                {
                    if (bounds.Width >= 4)
                    {
                        bounds.Inflate(-2, 0);
                    }
                    bounds.Height = 3;
                }
                this.RenderSmall3DBorderInternal(dc, bounds, ToolBarState.Hot, e.ToolStrip.RightToLeft == RightToLeft.Yes);
            }
        }
        protected override void OnRenderOverflowButtonBackground(ToolStripItemRenderEventArgs e)
        {
            ToolStripItem item = e.Item;
            Graphics      dc   = e.Graphics;

            if (ToolStripManager.VisualStylesEnabled && System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsElementDefined(VisualStyleElement.Rebar.Chevron.Normal))
            {
                VisualStyleElement normal = VisualStyleElement.Rebar.Chevron.Normal;
                System.Windows.Forms.VisualStyles.VisualStyleRenderer visualStyleRenderer = VisualStyleRenderer;
                visualStyleRenderer.SetParameters(normal.ClassName, normal.Part, GetItemState(item));
                visualStyleRenderer.DrawBackground(dc, new Rectangle(Point.Empty, item.Size));
            }
            else
            {
                this.RenderItemInternal(e);
                Color arrowColor = item.Enabled ? SystemColors.ControlText : SystemColors.ControlDark;
                base.DrawArrow(new ToolStripArrowRenderEventArgs(dc, item, new Rectangle(Point.Empty, item.Size), arrowColor, ArrowDirection.Down));
            }
        }
        protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
        {
            if (e.ToolStrip.IsDropDown && IsSupported)
            {

                var renderer = new VisualStyleRenderer("menu", 10, 0);
                var clip = e.Graphics.Clip;
                var clientRectangle = e.ToolStrip.ClientRectangle;
                clientRectangle.Inflate(-1, -1);
                e.Graphics.ExcludeClip(clientRectangle);
                renderer.DrawBackground(e.Graphics, e.ToolStrip.ClientRectangle, e.AffectedBounds);
                e.Graphics.Clip = clip;


            }
            else
            {
                base.OnRenderToolStripBorder(e);
            }

        }
        protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
        {
            ToolStrip toolStrip      = e.ToolStrip;
            Graphics  g              = e.Graphics;
            Rectangle affectedBounds = e.AffectedBounds;

            if (base.ShouldPaintBackground(toolStrip))
            {
                if (toolStrip is StatusStrip)
                {
                    RenderStatusStripBackground(e);
                }
                else if (DisplayInformation.HighContrast)
                {
                    FillBackground(g, affectedBounds, SystemColors.ButtonFace);
                }
                else if (DisplayInformation.LowResolution)
                {
                    FillBackground(g, affectedBounds, (toolStrip is ToolStripDropDown) ? SystemColors.ControlLight : e.BackColor);
                }
                else if (toolStrip.IsDropDown)
                {
                    FillBackground(g, affectedBounds, !ToolStripManager.VisualStylesEnabled ? e.BackColor : SystemColors.Menu);
                }
                else if (toolStrip is MenuStrip)
                {
                    FillBackground(g, affectedBounds, !ToolStripManager.VisualStylesEnabled ? e.BackColor : SystemColors.MenuBar);
                }
                else if (ToolStripManager.VisualStylesEnabled && System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsElementDefined(VisualStyleElement.Rebar.Band.Normal))
                {
                    System.Windows.Forms.VisualStyles.VisualStyleRenderer visualStyleRenderer = VisualStyleRenderer;
                    visualStyleRenderer.SetParameters(VisualStyleElement.ToolBar.Bar.Normal);
                    visualStyleRenderer.DrawBackground(g, affectedBounds);
                }
                else
                {
                    FillBackground(g, affectedBounds, !ToolStripManager.VisualStylesEnabled ? e.BackColor : SystemColors.MenuBar);
                }
            }
        }
Beispiel #26
0
        public void PaintSizeGrip(PaintEventArgs e)
        {
            if (e == null || !_resizable)
            {
                return;
            }
            var clientSize = Content.ClientSize;

            if (Application.RenderWithVisualStyles)
            {
                if (_sizeGripRenderer == null)
                {
                    _sizeGripRenderer = new VS.VisualStyleRenderer(VS.VisualStyleElement.Status.Gripper.Normal);
                }
                _sizeGripRenderer.DrawBackground(e.Graphics,
                                                 new Rectangle(clientSize.Width - 0x10, clientSize.Height - 0x10, 0x10, 0x10));
            }
            else
            {
                ControlPaint.DrawSizeGrip(e.Graphics, Content.BackColor, clientSize.Width - 0x10, clientSize.Height - 0x10, 0x10, 0x10);
            }
        }
		private void SimpleStyleRenderer_Paint(object sender, PaintEventArgs e)
		{
			VisualStyleElement element = VisualStyleElement.Button.CheckBox.CheckedNormal;
			
			if (Application.RenderWithVisualStyles &&
				VisualStyleRenderer.IsElementDefined(element))
			{
				VisualStyleRenderer renderer = new VisualStyleRenderer(element);
				Rectangle rectCheck = new Rectangle(10, 10, 50, 50);
				Rectangle rectBox = new Rectangle(10, 10, 200, 50);
				Rectangle rectText = new Rectangle(50, 25, 150, 25);
				renderer.DrawBackground(e.Graphics, rectCheck);
				renderer.DrawEdge(e.Graphics, rectBox, 
					Edges.Bottom | Edges.Top | Edges.Left | Edges.Right,
					EdgeStyle.Etched, EdgeEffects.Flat);
				renderer.DrawText(e.Graphics, rectText, "Styled checkbox", false, TextFormatFlags.Top);
			}
			else
			{
				// (Perform ControlPaint drawing here.)
			}

		}
Beispiel #28
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Draw a background that looks like a list view header.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected override void OnPaintBackground(PaintEventArgs e)
		{
			Rectangle rc = ClientRectangle;
			e.Graphics.FillRectangle(SystemBrushes.Window, rc);
			VisualStyleElement element = VisualStyleElement.Header.Item.Normal;

			// Draw the background, preferrably using visual styles.
			if (!PaintingHelper.CanPaintVisualStyle(element))
				ControlPaint.DrawButton(e.Graphics, rc, ButtonState.Normal);
			else
			{
				// Add 2 so the separator that's drawn at the right
				// side of normal list resultView header isn't visible.
				rc.Width += 2;

				if (m_showWindowBackgroudOnTopAndRightEdge)
				{
					// Shrink the rectangle so the top and left
					// edge window background don't get clobbered.
					rc.Height--;
					rc.Y++;
					rc.X++;
				}

				VisualStyleRenderer renderer = new VisualStyleRenderer(element);
				renderer.DrawBackground(e.Graphics, rc);

				if (m_showWindowBackgroudOnTopAndRightEdge)
				{
					// Draw a window background color line down the right edge.
					rc = ClientRectangle;
					e.Graphics.DrawLine(SystemPens.Window,
						new Point(rc.Width - 1, 0), new Point(rc.Width - 1, rc.Bottom));
				}
			}
		}
Beispiel #29
0
        /// <summary>
        /// Paints the background.
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data.</param>
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            switch (_borderStyle)
            {
                case BorderStyle.Fixed3D:
                    {
                        if (TextBoxRenderer.IsSupported)
                        {
                            VisualStyleElement state = VisualStyleElement.TextBox.TextEdit.Normal;
                            Color backColor = BackColor;

                            if (Enabled)
                            {
                                if (ReadOnly)
                                    state = VisualStyleElement.TextBox.TextEdit.ReadOnly;
                                else if (Focused)
                                    state = VisualStyleElement.TextBox.TextEdit.Focused;
                            }
                            else
                            {
                                state = VisualStyleElement.TextBox.TextEdit.Disabled;
                                backColor = BackColorDisabled;
                            }

                            var vsr = new VisualStyleRenderer(state);
                            vsr.DrawBackground(pevent.Graphics, ClientRectangle);

                            Rectangle rectContent = vsr.GetBackgroundContentRectangle(pevent.Graphics, ClientRectangle);
                            pevent.Graphics.FillRectangle(new SolidBrush(backColor), rectContent);
                        }
                        else
                        {
                            // draw background
                            pevent.Graphics.FillRectangle(new SolidBrush(BackColor), ClientRectangle);

                            // draw default border
                            ControlPaint.DrawBorder3D(pevent.Graphics, ClientRectangle, Border3DStyle.Sunken);
                        }

                        break;
                    }
                case BorderStyle.FixedSingle:
                    {
                        // draw background
                        pevent.Graphics.FillRectangle(new SolidBrush(BackColor), ClientRectangle);

                        // draw fixed single border
                        ControlPaint.DrawBorder(pevent.Graphics, ClientRectangle, Color.Black, ButtonBorderStyle.Solid);
                        break;
                    }
            }
        }
        /// <summary>
        /// Draw a more-or-less pure themed header background.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="r"></param>
        /// <param name="columnIndex"></param>
        /// <param name="isSelected"></param>
        protected void DrawThemedBackground(Graphics g, Rectangle r, int columnIndex, bool isSelected) {
            int part = 1; // normal item
            if (columnIndex == 0 &&
                VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.ItemLeft.Normal))
                part = 2; // left item
            if (columnIndex == this.ListView.Columns.Count - 1 &&
                VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.ItemRight.Normal))
                part = 3; // right item

            int state = 1; // normal state
            if (isSelected)
                state = 3; // pressed
            else if (columnIndex == this.ColumnIndexUnderCursor)
                state = 2; // hot

            VisualStyleRenderer renderer = new VisualStyleRenderer("HEADER", part, state);
            renderer.DrawBackground(g, r);
        }
Beispiel #31
0
        private void DrawButton(Graphics e, mcButtonState state,mcHeaderButtons button,Rectangle rect)
        {
            Bitmap image = null;
            int x = 0;
            int y = 0;
            int corr = 0;

            if (Application.RenderWithVisualStyles)
            {
                VisualStyleElement element = VisualStyleElement.Button.PushButton.Normal;

                if (m_calendar.Enabled)
                {
                    if (state == mcButtonState.Hot)
                        element = VisualStyleElement.Button.PushButton.Hot;
                    else if (state == mcButtonState.Inactive)
                        element = VisualStyleElement.Button.PushButton.Disabled;
                    else if (state == mcButtonState.Pushed)
                        element = VisualStyleElement.Button.PushButton.Pressed;
                }
                else element = VisualStyleElement.Button.PushButton.Disabled;

                VisualStyleRenderer renderer = new VisualStyleRenderer(element);
                renderer.DrawBackground(e, rect);
                switch (button)
                {
                    case mcHeaderButtons.PreviousMonth:
                    {
                        image = m_prevMonthVs;
                        x = rect.Left + 5;
                        y = rect.Top + 5;
                        break;
                    }
                    case mcHeaderButtons.PreviousYear:
                    {
                        image = m_prevYearVs;
                        x = rect.Left + 4;
                        y = rect.Top + 5;
                        break;
                    }
                    case mcHeaderButtons.NextMonth:
                    {
                        image = m_nextMonthVs;
                        x = rect.Right - 13;
                        y = rect.Top + 5;
                        break;
                    }
                    case mcHeaderButtons.NextYear:
                    {
                        image = m_nextYearVs;
                        x = rect.Right - 16; 
                        y = rect.Top + 5;
                        break;
                    }
                
                }
                
                if ((m_calendar.Enabled) && (state!=mcButtonState.Inactive))  
                    e.DrawImageUnscaled(image, new Point(x,y));
                else
                    ControlPaint.DrawImageDisabled(e, image, x, y, Color.Transparent);
                
            }
            else
            {
                ButtonState btnState = ButtonState.Normal;
                if (m_calendar.Enabled)
                {
                    if (state == mcButtonState.Hot)
                        btnState = ButtonState.Normal;
                    else if (state == mcButtonState.Inactive)
                        btnState = ButtonState.Inactive;
                    else if (state == mcButtonState.Pushed)
                        btnState = ButtonState.Pushed;
                }
                else btnState = ButtonState.Inactive;

                switch (button)
                {
                    case mcHeaderButtons.PreviousMonth:
                    {
                        ControlPaint.DrawScrollButton(e, rect, ScrollButton.Left, btnState);
                        break;
                    }
                    case mcHeaderButtons.NextMonth:
                    {
                        ControlPaint.DrawScrollButton(e, rect, ScrollButton.Right, btnState);
                        break;
                    }
                    case mcHeaderButtons.NextYear:
                    {

                        ControlPaint.DrawButton(e, rect, btnState);
                        if (state == mcButtonState.Pushed)
                            corr = 1;
                        if ((m_calendar.Enabled) && (m_nextYearBtnState != mcButtonState.Inactive))
                            e.DrawImage(m_nextYear, new Point(rect.Left + 3, rect.Top + 2 + corr));
                        else
                            e.DrawImage(m_nextYearDisabled, new Point(rect.Left + 3, rect.Top + 2 + corr));
                
                        break;
                    }
                    case mcHeaderButtons.PreviousYear:
                    {

                        ControlPaint.DrawButton(e, rect, btnState);
                        if (state == mcButtonState.Pushed)
                            corr = 1;
                        if ((m_calendar.Enabled) && (m_prevYearBtnState != mcButtonState.Inactive))
                            e.DrawImage(m_prevYear, new Point(rect.Left, rect.Top + 2 + corr));
                        else
                            e.DrawImage(m_prevYearDisabled, new Point(rect.Left, rect.Top + 2 + corr));  
                
                        break;
                    }
                }
                
            }
        }
Beispiel #32
0
        private void DrawGlyph( Graphics g, Point p, bool expanded )
        {
            if( VisualStyleRenderer.IsSupported )
            {
                VisualStyleElement vse = expanded ? VisualStyleElement.TreeView.Glyph.Opened : VisualStyleElement.TreeView.Glyph.Closed;
                VisualStyleRenderer vsr = new VisualStyleRenderer( vse );
                Size ecSize = vsr.GetPartSize( g, ThemeSizeType.Draw );

                vsr.DrawBackground( g, new Rectangle( p.X, p.Y, ecSize.Width, ecSize.Height ) );
            }
            else
            {
                g.FillRectangle( SystemBrushes.Window, new Rectangle( p.X, p.Y, 8, 8 ) );

                using( Pen pen = new Pen( Color.FromArgb( 128, 128, 128 ) ))
                {
                    g.DrawRectangle( pen, new Rectangle( p.X, p.Y, 8, 8 ) );
                }

                using( Pen pen = new Pen( Color.Black ) )
                {
                    g.DrawLine( pen, new Point( p.X + 2, p.Y + 4 ), new Point( p.X + 6, p.Y + 4 ) );

                    if( !expanded )
                    {
                        g.DrawLine( pen, new Point( p.X + 4, p.Y + 2 ), new Point( p.X + 4, p.Y + 6 ) );
                    }
                }
            }
        }
        private Color GetActiveTabBtmCol(ToolStrip strip, ToolStripItem active)
        {
            Color toolbarColour = SystemColors.Control;

            if (VisualStyleRenderer.IsSupported)
            {
                // Visual styles are enabled, so draw the correct background behind the toolbars
                Bitmap background = new Bitmap(strip.Width, strip.Height);
                Graphics graphics = Graphics.FromImage(background);

                try
                {
                    VisualStyleRenderer rebar = new VisualStyleRenderer("Rebar", 0, 0);
                    rebar.DrawBackground(graphics, new Rectangle(0, 0, strip.Width, strip.Height));
                    toolbarColour = background.GetPixel(active.Bounds.Left + Convert.ToInt32(active.Width / 2), 0);
                }
                catch (ArgumentException)
                {
                    // The 'Rebar' background image style did not exist
                }
            }

            return toolbarColour;
        }
        protected override void OnRenderSplitButtonBackground(ToolStripItemRenderEventArgs e)
        {
            ToolStripSplitButton item   = e.Item as ToolStripSplitButton;
            Graphics             dc     = e.Graphics;
            bool  rightToLeft           = item.RightToLeft == RightToLeft.Yes;
            Color arrowColor            = item.Enabled ? SystemColors.ControlText : SystemColors.ControlDark;
            VisualStyleElement element  = rightToLeft ? VisualStyleElement.ToolBar.SplitButton.Normal : VisualStyleElement.ToolBar.SplitButtonDropDown.Normal;
            VisualStyleElement element2 = rightToLeft ? VisualStyleElement.ToolBar.DropDownButton.Normal : VisualStyleElement.ToolBar.SplitButton.Normal;
            Rectangle          bounds   = new Rectangle(Point.Empty, item.Size);

            if ((ToolStripManager.VisualStylesEnabled && System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsElementDefined(element)) && System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsElementDefined(element2))
            {
                System.Windows.Forms.VisualStyles.VisualStyleRenderer visualStyleRenderer = VisualStyleRenderer;
                visualStyleRenderer.SetParameters(element2.ClassName, element2.Part, GetSplitButtonItemState(item));
                Rectangle buttonBounds = item.ButtonBounds;
                if (rightToLeft)
                {
                    buttonBounds.Inflate(2, 0);
                }
                visualStyleRenderer.DrawBackground(dc, buttonBounds);
                visualStyleRenderer.SetParameters(element.ClassName, element.Part, GetSplitButtonDropDownItemState(item));
                visualStyleRenderer.DrawBackground(dc, item.DropDownButtonBounds);
                Rectangle contentRectangle = item.ContentRectangle;
                if (item.BackgroundImage != null)
                {
                    ControlPaint.DrawBackgroundImage(dc, item.BackgroundImage, item.BackColor, item.BackgroundImageLayout, contentRectangle, contentRectangle);
                }
                this.RenderSeparatorInternal(dc, item, item.SplitterBounds, true);
                if (rightToLeft || (item.BackgroundImage != null))
                {
                    base.DrawArrow(new ToolStripArrowRenderEventArgs(dc, item, item.DropDownButtonBounds, arrowColor, ArrowDirection.Down));
                }
            }
            else
            {
                Rectangle rectangle4 = item.ButtonBounds;
                if (item.BackgroundImage != null)
                {
                    Rectangle clipRect = item.Selected ? item.ContentRectangle : bounds;
                    if (item.BackgroundImage != null)
                    {
                        ControlPaint.DrawBackgroundImage(dc, item.BackgroundImage, item.BackColor, item.BackgroundImageLayout, bounds, clipRect);
                    }
                }
                else
                {
                    FillBackground(dc, rectangle4, item.BackColor);
                }
                ToolBarState splitButtonToolBarState = GetSplitButtonToolBarState(item, false);
                this.RenderSmall3DBorderInternal(dc, rectangle4, splitButtonToolBarState, rightToLeft);
                Rectangle dropDownButtonBounds = item.DropDownButtonBounds;
                if (item.BackgroundImage == null)
                {
                    FillBackground(dc, dropDownButtonBounds, item.BackColor);
                }
                splitButtonToolBarState = GetSplitButtonToolBarState(item, true);
                switch (splitButtonToolBarState)
                {
                case ToolBarState.Pressed:
                case ToolBarState.Hot:
                    this.RenderSmall3DBorderInternal(dc, dropDownButtonBounds, splitButtonToolBarState, rightToLeft);
                    break;
                }
                base.DrawArrow(new ToolStripArrowRenderEventArgs(dc, item, dropDownButtonBounds, arrowColor, ArrowDirection.Down));
            }
        }
Beispiel #35
0
        protected override void OnRenderButtonBackground(System.Windows.Forms.ToolStripItemRenderEventArgs e)
        {
            System.Drawing.Rectangle rectangle1;

            System.Drawing.Graphics graphics1 = e.Graphics;
            Oranikle.Studio.Controls.CtrlTabStrip       ctrlTabStrip       = e.ToolStrip as Oranikle.Studio.Controls.CtrlTabStrip;
            Oranikle.Studio.Controls.CtrlTabStripButton ctrlTabStripButton = e.Item as Oranikle.Studio.Controls.CtrlTabStripButton;
            if ((ctrlTabStrip == null) || (ctrlTabStripButton == null))
            {
                if (currentRenderer != null)
                {
                    currentRenderer.DrawButtonBackground(e);
                    return;
                }
                base.OnRenderButtonBackground(e);
                return;
            }
            bool flag1 = ctrlTabStripButton.Checked;
            bool flag2 = ctrlTabStripButton.Selected;
            int  i1 = 0, i2 = 0;

            System.Drawing.Rectangle rectangle3 = ctrlTabStripButton.Bounds;
            int i3 = rectangle3.Width - 1;

            System.Drawing.Rectangle rectangle4 = ctrlTabStripButton.Bounds;
            int i4 = rectangle4.Height - 1;

            if (UseVS)
            {
                if (ctrlTabStrip.Orientation == System.Windows.Forms.Orientation.Horizontal)
                {
                    if (!flag1)
                    {
                        i1 = 2;
                        i4--;
                    }
                    else
                    {
                        i1 = 1;
                    }
                    rectangle1 = new System.Drawing.Rectangle(0, 0, i3, i4);
                }
                else
                {
                    if (!flag1)
                    {
                        i2 = 2;
                        i3--;
                    }
                    else
                    {
                        i2 = 1;
                    }
                    rectangle1 = new System.Drawing.Rectangle(0, 0, i4, i3);
                }
                using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(rectangle1.Width, rectangle1.Height))
                {
                    System.Windows.Forms.VisualStyles.VisualStyleElement visualStyleElement = System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Normal;
                    if (flag1)
                    {
                        visualStyleElement = System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Pressed;
                    }
                    if (flag2)
                    {
                        visualStyleElement = System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Hot;
                    }
                    if (!ctrlTabStripButton.Enabled)
                    {
                        visualStyleElement = System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Disabled;
                    }
                    if (!flag1 || flag2)
                    {
                        rectangle1.Width++;
                    }
                    else
                    {
                        rectangle1.Height++;
                    }
                    using (System.Drawing.Graphics graphics2 = System.Drawing.Graphics.FromImage(bitmap))
                    {
                        System.Windows.Forms.VisualStyles.VisualStyleRenderer visualStyleRenderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(visualStyleElement);
                        visualStyleRenderer.DrawBackground(graphics2, rectangle1);
                        if (ctrlTabStrip.Orientation == System.Windows.Forms.Orientation.Vertical)
                        {
                            if (Mirrored)
                            {
                                bitmap.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                            }
                            else
                            {
                                bitmap.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone);
                            }
                        }
                        else if (Mirrored)
                        {
                            bitmap.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipX);
                        }
                        if (Mirrored)
                        {
                            System.Drawing.Rectangle rectangle5 = ctrlTabStripButton.Bounds;
                            i2 = rectangle5.Width - bitmap.Width - i2;
                            System.Drawing.Rectangle rectangle6 = ctrlTabStripButton.Bounds;
                            i1 = rectangle6.Height - bitmap.Height - i1;
                        }
                        graphics1.DrawImage(bitmap, i2, i1);
                    }
                    return;
                }
            }
            if (ctrlTabStrip.Orientation == System.Windows.Forms.Orientation.Horizontal)
            {
                if (!flag1)
                {
                    i1  = ctrlTabStripButton.VerticalOffsetInactive;
                    i4 -= ctrlTabStripButton.VerticalOffsetInactive - 1;
                }
                else
                {
                    i1 = ctrlTabStripButton.VerticalOffset;
                }
                if (Mirrored)
                {
                    i2 = 1;
                    i1 = 0;
                }
                else
                {
                    i1++;
                }
                i3--;
            }
            else
            {
                if (!flag1)
                {
                    i2 = 2;
                    i3--;
                }
                else
                {
                    i2 = 1;
                }
                if (Mirrored)
                {
                    i2 = 0;
                    i1 = 1;
                }
            }
            i4--;
            rectangle1 = new System.Drawing.Rectangle(i2, i1, i3, i4);
            using (System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath())
            {
                if (Mirrored && (ctrlTabStrip.Orientation == System.Windows.Forms.Orientation.Horizontal))
                {
                    graphicsPath.AddLine(rectangle1.Left, rectangle1.Top, rectangle1.Left, rectangle1.Bottom - 2);
                    graphicsPath.AddArc(rectangle1.Left, rectangle1.Bottom - 3, 2, 2, 90.0F, 90.0F);
                    graphicsPath.AddLine(rectangle1.Left + 2, rectangle1.Bottom, rectangle1.Right - 2, rectangle1.Bottom);
                    graphicsPath.AddArc(rectangle1.Right - 2, rectangle1.Bottom - 3, 2, 2, 0.0F, 90.0F);
                    graphicsPath.AddLine(rectangle1.Right, rectangle1.Bottom - 2, rectangle1.Right, rectangle1.Top);
                }
                else if (!Mirrored && (ctrlTabStrip.Orientation == System.Windows.Forms.Orientation.Horizontal))
                {
                    int i5 = 1, i6 = 3;
                    graphicsPath.AddLine(rectangle1.Left, rectangle1.Bottom, rectangle1.Left, rectangle1.Top + i6);
                    graphicsPath.AddArc(rectangle1.Left, rectangle1.Top + i6 - 1, i6, i6, 180.0F, 90.0F);
                    graphicsPath.AddLine(rectangle1.Left + i6, rectangle1.Top, rectangle1.Right - i6 - i5, rectangle1.Top);
                    graphicsPath.AddArc(rectangle1.Right - i6 - i5, rectangle1.Top + i6 - 1, i6, i6, 270.0F, 90.0F);
                    graphicsPath.AddLine(rectangle1.Right - i5, rectangle1.Top + i6, rectangle1.Right - i5, rectangle1.Bottom);
                }
                else if (Mirrored && (ctrlTabStrip.Orientation == System.Windows.Forms.Orientation.Vertical))
                {
                    graphicsPath.AddLine(rectangle1.Left, rectangle1.Top, rectangle1.Right - 2, rectangle1.Top);
                    graphicsPath.AddArc(rectangle1.Right - 2, rectangle1.Top + 1, 2, 2, 270.0F, 90.0F);
                    graphicsPath.AddLine(rectangle1.Right, rectangle1.Top + 2, rectangle1.Right, rectangle1.Bottom - 2);
                    graphicsPath.AddArc(rectangle1.Right - 2, rectangle1.Bottom - 3, 2, 2, 0.0F, 90.0F);
                    graphicsPath.AddLine(rectangle1.Right - 2, rectangle1.Bottom, rectangle1.Left, rectangle1.Bottom);
                }
                else
                {
                    graphicsPath.AddLine(rectangle1.Right, rectangle1.Top, rectangle1.Left + 2, rectangle1.Top);
                    graphicsPath.AddArc(rectangle1.Left, rectangle1.Top + 1, 2, 2, 180.0F, 90.0F);
                    graphicsPath.AddLine(rectangle1.Left, rectangle1.Top + 2, rectangle1.Left, rectangle1.Bottom - 2);
                    graphicsPath.AddArc(rectangle1.Left, rectangle1.Bottom - 3, 2, 2, 90.0F, 90.0F);
                    graphicsPath.AddLine(rectangle1.Left + 2, rectangle1.Bottom, rectangle1.Right, rectangle1.Bottom);
                }
                System.Drawing.Color color1 = ctrlTabStripButton.BackColorInactive;
                if (flag1)
                {
                    color1 = ctrlTabStripButton.BackColor;
                }
                else if (flag2)
                {
                    color1 = ctrlTabStripButton.BackColorHot;
                }
                System.Drawing.Color color2 = ctrlTabStripButton.BackColor2Inactive;
                if (flag1)
                {
                    color2 = ctrlTabStripButton.BackColor2;
                }
                else if (flag2)
                {
                    color2 = ctrlTabStripButton.BackColor2Hot;
                }
                if (renderMode == System.Windows.Forms.ToolStripRenderMode.Professional)
                {
                    color1 = flag2 ? System.Windows.Forms.ProfessionalColors.ButtonCheckedGradientBegin : System.Windows.Forms.ProfessionalColors.ButtonCheckedGradientEnd;
                    using (System.Drawing.Drawing2D.LinearGradientBrush linearGradientBrush1 = new System.Drawing.Drawing2D.LinearGradientBrush(ctrlTabStripButton.ContentRectangle, color1, System.Windows.Forms.ProfessionalColors.ButtonCheckedGradientMiddle, System.Drawing.Drawing2D.LinearGradientMode.Vertical))
                    {
                        graphics1.FillPath(linearGradientBrush1, graphicsPath);
                        goto label_1;
                    }
                }
                using (System.Drawing.Drawing2D.LinearGradientBrush linearGradientBrush2 = new System.Drawing.Drawing2D.LinearGradientBrush(ctrlTabStripButton.ContentRectangle, color1, color2, System.Drawing.Drawing2D.LinearGradientMode.Vertical))
                {
                    graphics1.FillPath(linearGradientBrush2, graphicsPath);
                }
label_1:
                if (flag1)
                {
                    using (System.Drawing.Pen pen1 = new System.Drawing.Pen(ctrlTabStripButton.BorderColor))
                    {
                        graphics1.DrawPath(pen1, graphicsPath);
                        goto label_2;
                    }
                }
                if (flag2)
                {
                    using (System.Drawing.Pen pen2 = new System.Drawing.Pen(ctrlTabStripButton.BorderColorHot))
                    {
                        graphics1.DrawPath(pen2, graphicsPath);
                        goto label_2;
                    }
                }
                using (System.Drawing.Pen pen3 = new System.Drawing.Pen(ctrlTabStripButton.BorderColorInactive))
                {
                    graphics1.DrawPath(pen3, graphicsPath);
                }
label_2:
                if (ctrlTabStripButton.ShowCloseButton)
                {
                    System.Drawing.Image image = Oranikle.Studio.Controls.Properties.Resources.Icon_Close_Disabled_16;
                    if (flag2)
                    {
                        image = Oranikle.Studio.Controls.Properties.Resources.Icon_Close_16;
                    }
                    System.Drawing.Rectangle rectangle2 = new System.Drawing.Rectangle(i2 + i3 - ctrlTabStripButton.CloseButtonHorizontalOffset, ctrlTabStripButton.CloseButtonVerticalOffset, 8, 8);
                    graphics1.DrawImage(image, rectangle2);
                }
            }
        }
Beispiel #36
0
        /// <summary>
        /// Draws certain tab.
        /// </summary>
        /// <param name="g">The <see cref="System.Drawing.Graphics"/> object used to draw tab control.</param>
        /// <param name="index">Index of the tab being drawn.</param>
        /// <param name="tabRect">The <see cref="System.Drawing.Rectangle"/> object specifying tab bounds.</param>
        /// <param name="rend">The <see cref="System.Windows.Forms.VisualStyles.VisualStyleRenderer"/> object for rendering the tab.</param>
        private void DrawTabItem(Graphics g, int index, Rectangle tabRect, VisualStyleRenderer rend)
        {
            //if scroller is visible and the tab is fully placed under it we don't need to draw such tab
            if (fUpDown.X <= 0 || tabRect.X < fUpDown.X)
            {
                bool tabSelected = rend.State == (int)TabItemState.Selected;
                /* We will draw our tab on the bitmap and then will transfer image on the control
                 * graphic context.*/
                GDIMemoryContext memGDI = new GDIMemoryContext(g, tabRect.Width, tabRect.Height);
                Rectangle drawRect = new Rectangle(0, 0, tabRect.Width, tabRect.Height);
                using (Graphics bitmapContext = memGDI.CreateGraphics())
                {
                    rend.DrawBackground(bitmapContext, drawRect);
                    if (tabSelected && tabRect.X == 0)
                    {
                        int corrY = memGDI.Height - 1;
                        memGDI.SetPixel(0, corrY, memGDI.GetPixel(0, corrY - 1));
                    }
                    /* Important moment. If tab alignment is bottom we should flip image to display tab
                     * correctly.*/
                    if (this.Alignment == TabAlignment.Bottom) memGDI.FlipVertical();

                    Rectangle focusRect = Rectangle.Inflate(drawRect, -3, -3);//focus rect
                    TabPage pg = this.TabPages[index];//tab page whose tab we're drawing
                    //trying to get tab image if any
                    Image pagePict = this.GetImageByIndexOrKey(pg.ImageIndex, pg.ImageKey);
                    if (pagePict != null)
                    {
                        //If tab image is present we should draw it.
                        Point imgLoc = tabSelected ? new Point(8, 2) : new Point(6, 2);
                        if (this.Alignment == TabAlignment.Bottom) imgLoc.Y = drawRect.Bottom - 2 - pagePict.Height;
                        bitmapContext.DrawImageUnscaled(pagePict, imgLoc);
                        //Correcting rectangle for drawing text.
                        drawRect.X += imgLoc.X + pagePict.Width; drawRect.Width -= imgLoc.X + pagePict.Width;
                    }
                    //drawing tab text
                    TextRenderer.DrawText(bitmapContext, pg.Text, this.Font, drawRect, rend.GetColor(ColorProperty.TextColor),
                        TextFormatFlags.SingleLine | TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
                    //and finally drawing focus rect(if needed)
                    if (this.Focused && tabSelected)
                        ControlPaint.DrawFocusRectangle(bitmapContext, focusRect);
                }
                //If the tab has part under scroller we shouldn't draw that part.
                int shift = tabSelected ? 2 : 0;
                if (fUpDown.X > 0 && fUpDown.X >= tabRect.X - shift && fUpDown.X < tabRect.Right + shift)
                    tabRect.Width -= tabRect.Right - fUpDown.X + shift;
                memGDI.DrawContextClipped(g, tabRect);
            }
        }
Beispiel #37
0
        /// <summary>
        /// Gets the background image of the current visual style element within the specified background color. If <paramref name="states"/>
        /// is set, the resulting image will contain each of the state images side by side.
        /// </summary>
        /// <param name="rnd">The <see cref="VisualStyleRenderer"/> instance.</param>
        /// <param name="clr">The background color. This color cannot have an alpha channel.</param>
        /// <param name="states">The optional list of states to render side by side.</param>
        /// <returns>The background image.</returns>
        public static Bitmap GetBackgroundBitmap(this VisualStyleRenderer rnd, Color clr, int[] states = null)
        {
            const int wh = 200;

            if (rnd == null)
            {
                throw new ArgumentNullException(nameof(rnd));
            }
            rnd.SetParameters(rnd.Class, rnd.Part, 0);
            if (states == null)
            {
                states = new[] { rnd.State }
            }
            ;
            var i = states.Length;

            // Get image size
            Size imgSz;

            using (var sg = Graphics.FromHwnd(IntPtr.Zero))
                imgSz = rnd.GetPartSize(sg, new Rectangle(0, 0, wh, wh), ThemeSizeType.Draw);
            if (imgSz.Width == 0 || imgSz.Height == 0)
            {
                imgSz = new Size(rnd.GetInteger(IntegerProperty.Width), rnd.GetInteger(IntegerProperty.Height));
            }

            var bounds = new Rectangle(0, 0, imgSz.Width * i, imgSz.Height);

            // Draw each background linearly down the bitmap
            using (var memoryHdc = SafeDCHandle.ScreenCompatibleDCHandle)
            {
                // Create a device-independent bitmap and select it into our DC
                var info = new BITMAPINFO(bounds.Width, -bounds.Height);
                using (new SafeDCObjectHandle(memoryHdc, CreateDIBSection(SafeDCHandle.Null, ref info, DIBColorMode.DIB_RGB_COLORS, out var ppv, IntPtr.Zero, 0)))
                {
                    using (var memoryGraphics = Graphics.FromHdc(memoryHdc.DangerousGetHandle()))
                    {
                        // Setup graphics
                        memoryGraphics.CompositingMode    = CompositingMode.SourceOver;
                        memoryGraphics.CompositingQuality = CompositingQuality.HighQuality;
                        memoryGraphics.SmoothingMode      = SmoothingMode.HighQuality;
                        memoryGraphics.Clear(clr);

                        // Draw each background linearly down the bitmap
                        var rect = new Rectangle(0, 0, imgSz.Width, imgSz.Height);
                        foreach (var state in states)
                        {
                            rnd.SetParameters(rnd.Class, rnd.Part, state);
                            rnd.DrawBackground(memoryGraphics, rect);
                            rect.X += imgSz.Width;
                        }
                    }

                    // Copy DIB to Bitmap
                    var bmp = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb);
                    using (var primaryHdc = new SafeDCHandle(Graphics.FromImage(bmp)))
                        BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, RasterOperationMode.SRCCOPY);
                    return(bmp);
                }
            }
        }
        private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
        {
            e.DrawDefault = false;
            Rectangle rect = e.Bounds;
            if (rect.Height == 0)
            {
                ///在展开节点的时候会出现根节点绘制错误的问题
                return;
            }
            if ((e.State & TreeNodeStates.Selected) != 0)
            {
                if ((e.State & TreeNodeStates.Focused) != 0)
                {
                    e.Graphics.FillRectangle(SystemBrushes.Highlight, rect);
                }
                else
                {
                    e.Graphics.FillRectangle(SystemBrushes.Control, rect);
                }
            }
            else
            {
                e.Graphics.FillRectangle(Brushes.White, rect);
            }
            int IndentWidth = DatatreeView.Indent * e.Node.Level + 25;
            e.Graphics.DrawRectangle(SystemPens.Control, rect);
            Rectangle StringRect = new Rectangle(e.Bounds.X + IndentWidth, e.Bounds.Y, colName.Width - IndentWidth, e.Bounds.Height);
            e.Graphics.DrawString(e.Node.Text, this.Font, new SolidBrush(Color.Black), StringRect);

            //画框
            if (e.Node.GetNodeCount(true) > 0)
            {
                int LeftPoint = e.Bounds.X + IndentWidth - 20;
                //感谢 Shadower http://home.cnblogs.com/u/14697/ 贡献的代码
                var thisNode = e.Node;
                var glyph = thisNode.IsExpanded ? VisualStyleElement.TreeView.Glyph.Opened : VisualStyleElement.TreeView.Glyph.Closed;
                var vsr = new VisualStyleRenderer(glyph);
                vsr.DrawBackground(e.Graphics, new Rectangle(LeftPoint, e.Bounds.Y + 4, 16, 16));
            }

            for (int intColumn = 1; intColumn < 3; intColumn++)
            {
                rect.Offset(this.listView1.Columns[intColumn - 1].Width, 0);
                rect.Width = this.listView1.Columns[intColumn].Width;

                e.Graphics.DrawRectangle(SystemPens.Control, rect);
                BsonElement Element = e.Node.Tag as BsonElement;
                if (Element != null && !Element.Value.IsBsonDocument && !Element.Value.IsBsonArray)
                {
                    string strColumnText = String.Empty;
                    if (intColumn == 1)
                    {
                        strColumnText = Element.Value.ToString();
                    }
                    else
                    {
                        strColumnText = Element.Value.GetType().Name.Substring(4);
                    }
                    TextFormatFlags flags = TextFormatFlags.EndEllipsis;
                    switch (this.listView1.Columns[intColumn].TextAlign)
                    {
                        case HorizontalAlignment.Center:
                            flags |= TextFormatFlags.HorizontalCenter;
                            break;
                        case HorizontalAlignment.Left:
                            flags |= TextFormatFlags.Left;
                            break;
                        case HorizontalAlignment.Right:
                            flags |= TextFormatFlags.Right;
                            break;
                        default:
                            break;
                    }

                    rect.Y++;
                    if ((e.State & TreeNodeStates.Selected) != 0 &&
                        (e.State & TreeNodeStates.Focused) != 0)
                        TextRenderer.DrawText(e.Graphics, strColumnText, e.Node.NodeFont, rect, SystemColors.HighlightText, flags);
                    else
                        TextRenderer.DrawText(e.Graphics, strColumnText, e.Node.NodeFont, rect, e.Node.ForeColor, e.Node.BackColor, flags);
                    rect.Y--;
                }
            }
        }
Beispiel #39
0
        /// <summary>
        /// Draws a single tab.
        /// </summary>
        /// <param name="g">A <see cref="T:System.Drawing.Graphics"/> object used to draw the tab control.</param>
        /// <param name="index">An index of the tab being drawn.</param>
        /// <param name="tabRect">A <see cref="T:System.Drawing.Rectangle"/> object specifying tab's bounds.</param>
        /// <param name="rend">A <see cref="T:System.Windows.Forms.VisualStyles.VisualStyleRenderer"/> object for rendering the tab.</param>
        private void DrawTabItem(Graphics g, int index, Rectangle tabRect, VisualStyleRenderer rend)
        {
            //if the scroller is visible and the tab is fully placed under it, we don't need to draw such tab
            if (fUpDown.X > 0 && tabRect.X >= fUpDown.X) return;

            bool tabSelected = rend.State == (int)TabItemState.Selected;
            // We will draw our tab on a bitmap and then transfer image to the control's graphic context.
            using (GDIMemoryContext memGDI = new GDIMemoryContext(g, tabRect.Width, tabRect.Height))
            {
                Rectangle drawRect = new Rectangle(0, 0, tabRect.Width, tabRect.Height);
                rend.DrawBackground(memGDI.Graphics, drawRect);
                if (tabSelected && tabRect.X == 0)
                {
                    int corrY = memGDI.Height - 1;
                    memGDI.SetPixel(0, corrY, memGDI.GetPixel(0, corrY - 1));
                }
                /* An important moment. If tabs alignment is bottom, we should flip the image to display the tab
                             * correctly.*/
                if (this.Alignment == TabAlignment.Bottom) memGDI.FlipVertical();

                TabPage pg = this.TabPages[index];//tab page whose tab we're drawing
                //trying to get a tab image if any
                Image pagePict = this.GetImageByIndexOrKey(pg.ImageIndex, pg.ImageKey);
                if (pagePict != null)
                {
                    //If tab image is present we should draw it.
                    Point imgLoc = new Point(tabSelected ? 8 : 6, 2);
                    int imgRight = imgLoc.X + pagePict.Width;

                    if (this.Alignment == TabAlignment.Bottom)
                        imgLoc.Y = drawRect.Bottom - pagePict.Height - (tabSelected ? 4 : 2);
                    if (RightToLeftLayout) imgLoc.X = drawRect.Right - imgRight;
                    memGDI.Graphics.DrawImageUnscaled(pagePict, imgLoc);
                    //Correcting rectangle for drawing text.
                    drawRect.X += imgRight; drawRect.Width -= imgRight;
                }
                //drawing tab text
                TextRenderer.DrawText(memGDI.Graphics, pg.Text, this.Font, drawRect, rend.GetColor(ColorProperty.TextColor),
                    TextFormatFlags.SingleLine | TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
                //If the tab has part under scroller we shouldn't draw that part.
                if (fUpDown.X > 0 && fUpDown.X >= tabRect.X && fUpDown.X < tabRect.Right)
                    tabRect.Width -= tabRect.Right - fUpDown.X;
                memGDI.DrawContextClipped(g, tabRect);

            }
        }
        private void _ListAccounts_DrawItem(object sender, DrawListViewItemEventArgs e)
        {
            AccountListItem item = e.Item as AccountListItem;
            Bitmap image = item.Account.Type == AccountTypes.Regular ? _iconStandard : _iconApps;
            int elementState = 1;

            if ((e.State & ListViewItemStates.Selected) != 0) {
                if ((e.State & ListViewItemStates.Focused) != 0) {
                    elementState = 3; // Selected
                }
                else {
                    elementState = 5; // SelectedNotFocus;
                }
            }
            else if ((e.State & ListViewItemStates.Hot) != 0) {
                elementState = 2; // Hot
            }

            if (elementState > 1) {
                VisualStyleElement element = VisualStyleElement.CreateElement("Explorer::ListView", 1, elementState);

                VisualStyleRenderer renderer = new VisualStyleRenderer(element);

                renderer.DrawBackground(e.Graphics, item.Bounds);
            }

            PaintAccountGlyph(e.Graphics, e.Item.Bounds, item.Account);

            //int tileWidth = _userFrame.Width;
            //int tileHeight = (int)(((float)tileWidth / (float)image.Width) * image.Height);
            //RectangleF clipRect = new RectangleF(item.Bounds.Left + 14, item.Bounds.Top + 13, _userFrame.Width - 30, _userFrame.Height - 30);

            ////

            //e.Graphics.SetClip(clipRect);
            //e.Graphics.DrawImage(image, item.Bounds.Left, item.Bounds.Top + 10, tileWidth, tileHeight);
            //e.Graphics.ResetClip();

            //e.Graphics.DrawImage(_userFrame, new Rectangle(item.Bounds.Left, item.Bounds.Top, _userFrame.Width, _userFrame.Height));

            //Point addressPoint = new Point(item.Bounds.Left + _userFrame.Width, item.Bounds.Top);
            //Rectangle addressRect = new Rectangle(addressPoint.X, addressPoint.Y, item.Bounds.Width - _userFrame.Width, item.Bounds.Height);
            //Rectangle textExtent = _rendererListSmall.GetTextExtent(e.Graphics, addressRect, item.Account.FullAddress, TextFormatFlags.Left);
            //int center = (_userFrame.Height - textExtent.Height) / 2;

            //if (item.Account.Default) {
            //  Rectangle defaultExtent = _rendererListSmall.GetTextExtent(e.Graphics, addressRect, Locale.Current.JumpList.DefaultAccount, TextFormatFlags.Left);

            //  center -= (defaultExtent.Height / 2) + 4; // 4 is the additional padding we're adding
            //}

            //addressRect.Offset(0, center);

            //_rendererListSmall.DrawText(e.Graphics, addressRect, item.Account.FullAddress, false, TextFormatFlags.Left);

            //if (item.Account.Default) {
            //  addressRect.Offset(0, textExtent.Height + 4);

            //  _rendererListSmall.DrawText(e.Graphics, addressRect, Locale.Current.JumpList.DefaultAccount, true, TextFormatFlags.Left);
            //}
        }
        public static void Draw(IDeviceContext dc, Size minSize, Size maxSize, string title, string text, Rectangle titleRect, Rectangle rect, ToolTipIcon icon, Padding padding)
        {
            if (Application.RenderWithVisualStyles)
            {
                VisualStyleRenderer titleRenderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.BalloonTitle.Normal);
                VisualStyleRenderer balloonRenderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.Balloon.Normal);
                balloonRenderer.DrawBackground(dc, rect);

                if (icon == ToolTipIcon.None)
                {
                    titleRenderer.DrawText(dc, new Rectangle(padding.Left, padding.Top, rect.Width - (padding.Left + padding.Right), titleRect.Height),
                        title, false, TextFormatFlags.Left | TextFormatFlags.WordEllipsis | TextFormatFlags.VerticalCenter);

                    Rectangle balloonTextBounds = new Rectangle(padding.Left, padding.Top + titleRect.Height, rect.Width - (padding.Left + padding.Right), rect.Height - (padding.Top + titleRect.Height + padding.Bottom));

                    balloonRenderer.DrawText(dc, balloonTextBounds,
                        text, false, TextFormatFlags.Left | TextFormatFlags.WordBreak | TextFormatFlags.VerticalCenter);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }