Exemple #1
0
		public static void DrawParentBackground (Graphics g, Rectangle bounds, Control childControl)
		{
			if (!VisualStyleRenderer.IsSupported)
				return;
			
			VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.Button.GroupBox.Normal);

			vsr.DrawParentBackground (g, bounds, childControl);
		}
Exemple #2
0
		/// <summary>
		/// Raises the <see cref="E:Paint"/> event.
		/// </summary>
		/// <param name="e"></param>
		protected override void OnPaint(PaintEventArgs e)
		{
			if (Application.RenderWithVisualStyles)
			{
				var renderer = new VisualStyleRenderer(VisualStyleElement.TextBox.TextEdit.Normal);
				renderer.DrawParentBackground(e.Graphics, ClientRectangle, this);
			}
			base.OnPaint(e);
		}
        protected override void PaintButton(Graphics graphics, Rectangle bounds)
        {
            if (Application.RenderWithVisualStyles || DesktopWindowManager.IsCompositionEnabled())
            {
                try
                {
                    VisualStyleRenderer rnd = new VisualStyleRenderer(StyleClass, StylePart, (int)ButtonState);
                    if (this.IsDesignMode() || !DesktopWindowManager.IsCompositionEnabled())
                    {
                        rnd.DrawParentBackground(graphics, this.Bounds, this);
                        rnd.DrawBackground(graphics, this.Bounds, bounds);
                    }
                    else
                    {
                        rnd.DrawGlassBackground(graphics, this.Bounds, bounds);
                    }
                    return;
                }
                catch { }
            }

            //base.PaintButton(graphics, bounds);
            Rectangle sr = this.ClientRectangle;
            sr.Offset(0, sr.Height * ((int)ButtonState - 1));
            graphics.Clear(this.Parent.BackColor);
            if (imageStrip != null)
                graphics.DrawImage(imageStrip, this.Bounds, sr, GraphicsUnit.Pixel);
            else
                using (Brush br = new SolidBrush(this.BackColor))
                    graphics.FillRectangle(br, sr);
        }
        private void PaintNonClientRegion(ref Message m)
        {
            IntPtr handle = Handle;

            NativeMethods.RECT windowRect;
            NativeMethods.GetWindowRect(handle, out windowRect);
            windowRect = new NativeMethods.RECT(
                0,
                0,
                windowRect.Right - windowRect.Left,
                windowRect.Bottom - windowRect.Top);

            using (var deviceContext = new NativeMethods.DeviceContext(handle))
            {
                var renderer = new VisualStyleRenderer(
                    Enabled
                        ? ReadOnly
                            ? VisualStyleElement.TextBox.TextEdit.ReadOnly
                            : VisualStyleElement.TextBox.TextEdit.Normal
                        : VisualStyleElement.TextBox.TextEdit.Disabled);

                int clipResult =
                    NativeMethods.ExcludeClipRect(
                        deviceContext.GetHdc(),
                        _borderRect.Left,
                        _borderRect.Top,
                        windowRect.Right - _borderRect.Right,
                        windowRect.Bottom - _borderRect.Bottom);

                if (clipResult == NativeMethods.SIMPLEREGION
                    || clipResult == NativeMethods.COMPLEXREGION)
                {
                    if (renderer.IsBackgroundPartiallyTransparent())
                        renderer.DrawParentBackground(deviceContext, windowRect.ToRectangle(), this);

                    renderer.DrawBackground(deviceContext, windowRect.ToRectangle());
                }
            }

            m.Result = IntPtr.Zero;
        }
Exemple #5
0
		protected override void WndProc(ref Message m)
		{
			const int WM_ERASEBKGND = 0x14;
			
			switch (m.Msg)
			{
				case WM_ERASEBKGND:
					if (Application.RenderWithVisualStyles)
					{
						VisualStyleRenderer rend = new VisualStyleRenderer(VisualStyleElement.TextBox.TextEdit.Normal);
						
						rend.DrawParentBackground(new DeviceContext(m.WParam), this.ClientRectangle, this);
						
						m.Result = (IntPtr)1;
						return;
					}
					break;
			}
			
			base.WndProc(ref m);
		}
        private void PaintPriv(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            if(g == null) { base.OnPaint(e); return; }

            int nNormPos = m_nPosition - m_nMinimum;
            int nNormMax = m_nMaximum - m_nMinimum;
            if(nNormMax <= 0) { Debug.Assert(false); nNormMax = 100; }
            if(nNormPos < 0) { Debug.Assert(false); nNormPos = 0; }
            if(nNormPos > nNormMax) { Debug.Assert(false); nNormPos = nNormMax; }

            Rectangle rectClient = this.ClientRectangle;
            Rectangle rectDraw;
            VisualStyleElement vse = VisualStyleElement.ProgressBar.Bar.Normal;
            if(VisualStyleRenderer.IsSupported &&
                VisualStyleRenderer.IsElementDefined(vse))
            {
                VisualStyleRenderer vsr = new VisualStyleRenderer(vse);

                if(vsr.IsBackgroundPartiallyTransparent())
                    vsr.DrawParentBackground(g, rectClient, this);

                vsr.DrawBackground(g, rectClient);

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

                Pen penGray = SystemPens.ControlDark;
                Pen penWhite = SystemPens.ControlLight;
                g.DrawLine(penGray, 0, 0, rectClient.Width - 1, 0);
                g.DrawLine(penGray, 0, 0, 0, rectClient.Height - 1);
                g.DrawLine(penWhite, rectClient.Width - 1, 0,
                    rectClient.Width - 1, rectClient.Height - 1);
                g.DrawLine(penWhite, 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);
            }

            int nDrawWidth = (int)((float)rectDraw.Width * (float)nNormPos /
                (float)nNormMax);

            Color clrStart = Color.FromArgb(255, 128, 0);
            Color clrEnd = Color.FromArgb(0, 255, 0);
            if(!this.Enabled)
            {
                clrStart = UIUtil.ColorToGrayscale(SystemColors.ControlDark);
                clrEnd = UIUtil.ColorToGrayscale(SystemColors.ControlLight);
            }

            bool bRtl = (this.RightToLeft == RightToLeft.Yes);
            if(bRtl)
            {
                Color clrTemp = clrStart;
                clrStart = clrEnd;
                clrEnd = clrTemp;
            }

            // Workaround for Windows <= XP
            Rectangle rectGrad = new Rectangle(rectDraw.X, rectDraw.Y,
                rectDraw.Width, rectDraw.Height);
            if(!WinUtil.IsAtLeastWindowsVista && !NativeLib.IsUnix())
                rectGrad.Inflate(1, 0);

            using(LinearGradientBrush brush = new LinearGradientBrush(rectGrad,
                clrStart, clrEnd, LinearGradientMode.Horizontal))
            {
                g.FillRectangle(brush, (bRtl ? (rectDraw.Width - nDrawWidth + 1) :
                    rectDraw.Left), rectDraw.Top, nDrawWidth, rectDraw.Height);
            }

            PaintText(g, rectDraw);
        }
Exemple #7
0
        public static void DrawCommandButton(
            Graphics g, 
            PushButtonState state, 
            Rectangle rect, 
            Color backColor,
            Control childControl)
        {
            VisualStyleElement element = null;
            int alpha = 255;
            
            if (OS.IsVistaOrLater)
            {
                const string className = "BUTTON";
                const int partID = NativeConstants.BP_COMMANDLINK;
                int stateID;

                switch (state)
                {
                    case PushButtonState.Default:
                        stateID = NativeConstants.CMDLS_DEFAULTED;
                        break;

                    case PushButtonState.Disabled:
                        stateID = NativeConstants.CMDLS_DISABLED;
                        break;
                        
                    case PushButtonState.Hot:
                        stateID = NativeConstants.CMDLS_HOT;
                        break;

                    case PushButtonState.Normal:
                        stateID = NativeConstants.CMDLS_NORMAL;
                        break;

                    case PushButtonState.Pressed:
                        stateID = NativeConstants.CMDLS_PRESSED;
                        break;

                    default:
                        throw new InvalidEnumArgumentException();
                }

                try
                {
                    element = VisualStyleElement.CreateElement(className, partID, stateID);

                    if (!VisualStyleRenderer.IsElementDefined(element))
                    {
                        element = null;
                    }
                }

                catch (InvalidOperationException)
                {
                    element = null;
                }
            }

            if (element == null)
            {
                switch (state)
                {
                    case PushButtonState.Default:
                        element = VisualStyleElement.Button.PushButton.Default;
                        alpha = 95;
                        break;

                    case PushButtonState.Disabled:
                        element = VisualStyleElement.Button.PushButton.Disabled;
                        break;

                    case PushButtonState.Hot:
                        element = VisualStyleElement.Button.PushButton.Hot;
                        break;

                    case PushButtonState.Normal:
                        alpha = 0;
                        element = VisualStyleElement.Button.PushButton.Normal;
                        break;
                    case PushButtonState.Pressed:
                        element = VisualStyleElement.Button.PushButton.Pressed;
                        break;

                    default:
                        throw new InvalidEnumArgumentException();
                }
            }

            if (element != null)
            {
                try
                {
                    VisualStyleRenderer renderer = new VisualStyleRenderer(element);
                    renderer.DrawParentBackground(g, rect, childControl);
                    renderer.DrawBackground(g, rect);
                }

                catch (Exception)
                {
                    element = null;
                }
            }

            if (element == null)
            {
                ButtonRenderer.DrawButton(g, rect, state);
            }

            if (alpha != 255)
            {
                using (Brush backBrush = new SolidBrush(Color.FromArgb(255 - alpha, backColor)))
                {
                    CompositingMode oldCM = g.CompositingMode;

                    try
                    {
                        g.CompositingMode = CompositingMode.SourceOver;
                        g.FillRectangle(backBrush, rect);
                    }

                    finally
                    {
                        g.CompositingMode = oldCM;
                    }
                }
            }
        }
Exemple #8
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Draws the button with an image.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void DrawArrow(PaintEventArgs e)
		{
			Rectangle rc = ClientRectangle;

			// If possible, render the button with visual styles. Otherwise,
			// paint the plain Windows 2000 push button.
			VisualStyleElement element = GetCorrectVisualStyleArrowElement();
			if (PaintingHelper.CanPaintVisualStyle(element))
			{
				VisualStyleRenderer renderer = new VisualStyleRenderer(element);
				renderer.DrawParentBackground(e.Graphics, rc, this);
				renderer.DrawBackground(e.Graphics, rc);
				return;
			}

			if (Font.SizeInPoints != 12)
				Font = new Font(Font.FontFamily, 12, GraphicsUnit.Point);

			ControlPaint.DrawButton(e.Graphics, rc,
				(m_state == PaintState.HotDown ? ButtonState.Pushed : ButtonState.Normal));

#if __MonoCS__
			// Linux doesn't have the Marlett font, so use standard Unicode dingbats here.
			string arrowGlyph = (m_drawLeftArrowButton ? "\u25C4" : "\u25BA");
#else
			// In the Marlett font, '3' is the left arrow and '4' is the right.
			string arrowGlyph = (m_drawLeftArrowButton ? "3" : "4");
#endif
			Color clr = (Enabled ? SystemColors.ControlText : SystemColors.GrayText);
			TextRenderer.DrawText(e.Graphics, arrowGlyph, Font, rc,	clr, m_txtFmtflags);
		}
Exemple #9
0
 /// <summary>
 /// Primary function for painting the button. This method should be overridden instead of OnPaint.
 /// </summary>
 /// <param name="graphics">The graphics.</param>
 /// <param name="bounds">The bounds.</param>
 protected virtual void PaintButton(Graphics graphics, Rectangle bounds)
 {
     VisualStyleRenderer rnd = null;
     bool vsOk = Application.RenderWithVisualStyles;
     if (vsOk)
     {
         rnd = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal);
         rnd.DrawParentBackground(graphics, bounds, this);
     }
     else
         graphics.Clear(this.Parent.BackColor);
     if (this.Image != null || (this.ImageList != null && this.ImageList.Images.Count == 1))
     {
         Image img = (this.Image != null) ? this.Image : this.ImageList.Images[0];
         if (Enabled)
         {
             if (vsOk)
                 rnd.DrawImage(graphics, bounds, img);
             else
                 graphics.DrawImage(img, bounds);
         }
         else
             ControlPaint.DrawImageDisabled(graphics, img, 0, 0, this.BackColor);
     }
     else if (this.ImageList != null && this.ImageList.Images.Count > 1)
     {
         int idx = (int)ButtonState - 1;
         if (this.ImageList.Images.Count == 2)
             idx = ButtonState == PushButtonState.Disabled ? 1 : 0;
         if (this.ImageList.Images.Count == 3)
             idx = ButtonState == PushButtonState.Normal ? 0 : idx - 1;
         if (vsOk)
             rnd.DrawImage(graphics, bounds, this.ImageList, idx);
         else
             graphics.DrawImage(this.ImageList.Images[idx], bounds);
     }
     else
     {
         if (vsOk)
         {
             rnd.SetParameters(rnd.Class, rnd.Part, (int)ButtonState);
             rnd.DrawBackground(graphics, bounds);
         }
         else
         {
             System.Windows.Forms.ButtonState bs = System.Windows.Forms.ButtonState.Flat;
             switch (this.ButtonState)
             {
                 case PushButtonState.Disabled:
                     bs |= System.Windows.Forms.ButtonState.Inactive;
                     break;
                 case PushButtonState.Pressed:
                     bs |= System.Windows.Forms.ButtonState.Pushed;
                     break;
                 default:
                     break;
             }
             ControlPaint.DrawButton(graphics, bounds, bs);
         }
     }
 }
Exemple #10
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Draws the button with an image.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public void DrawArrow(PaintEventArgs e)
		{
			Rectangle rc = ClientRectangle;

			// If possible, render the button with visual styles. Otherwise,
			// paint the plain Windows 2000 push button.
			var element = GetCorrectVisualStyleArrowElement();
			if (PaintingHelper.CanPaintVisualStyle(element))
			{
				VisualStyleRenderer renderer = new VisualStyleRenderer(element);
				renderer.DrawParentBackground(e.Graphics, rc, this);
				renderer.DrawBackground(e.Graphics, rc);
				return;
			}

			if (Font.SizeInPoints != 12)
				Font = new Font(Font.FontFamily, 12, GraphicsUnit.Point);

			ControlPaint.DrawButton(e.Graphics, rc,
				(m_state == PaintState.HotDown ? ButtonState.Pushed : ButtonState.Normal));

			// In the Marlette font, '3' is the left arrow and '4' is the right.
			string arrowGlyph = (m_drawLeftArrowButton ? "3" : "4");

			Color clr = (Enabled ? SystemColors.ControlText : SystemColors.GrayText);

			// The 'r' in the Marlette font is the close button symbol 'X'
			TextRenderer.DrawText(e.Graphics, arrowGlyph, Font, rc, clr, FormatFlags);
		}
        protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
        {
            if (e.ToolStrip.IsDropDown && IsSupported)
            {

                var renderer = new VisualStyleRenderer("menu", 9, 0);

                if (renderer.IsBackgroundPartiallyTransparent())
                {
                    renderer.DrawParentBackground(e.Graphics, e.ToolStrip.ClientRectangle, e.ToolStrip);
                }

                renderer.DrawBackground(e.Graphics, e.ToolStrip.ClientRectangle, e.AffectedBounds);


            }
            else
            {
                base.OnRenderToolStripBackground(e);
            }
        }
Exemple #12
0
        /// <summary>
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"/> that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            if (Visible)
            {
                VisualStyleRenderer vs = null;
                if (Application.RenderWithVisualStyles || DesktopWindowManager.IsCompositionEnabled())
                {
                    vs = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active);
                    vs.DrawParentBackground(e.Graphics, base.ClientRectangle, this);
                }

                // Draw image
                Rectangle r = DeflateRect(base.ClientRectangle, base.Padding);
                if (this.Image != null)
                {
                    Rectangle ir = CalcImageRenderBounds(this.Image, r, base.RtlTranslateAlignment(this.ImageAlign));
                    if (this.ImageList != null && this.ImageIndex == 0)
                    {
                        if (vs != null & !this.IsDesignMode() & DesktopWindowManager.IsCompositionEnabled())
                            vs.DrawGlassIcon(e.Graphics, r, this.ImageList, this.ImageIndex);
                        else
                            this.ImageList.Draw(e.Graphics, r.X, r.Y, r.Width, r.Height, this.ImageIndex);
                    }
                    else
                    {
                        if (vs != null & !this.IsDesignMode() & DesktopWindowManager.IsCompositionEnabled())
                            vs.DrawGlassImage(e.Graphics, r, this.Image);
                        else
                            e.Graphics.DrawImage(this.Image, r);
                    }
                }

                // Draw text
                if (this.Text.Length > 0)
                {
                    TextFormatFlags tff = CreateTextFormatFlags(this.TextAlign, this.AutoEllipsis, this.UseMnemonic);
                    if (this.IsDesignMode() || vs == null || !DesktopWindowManager.IsCompositionEnabled())
                    {
                        Brush br = DesktopWindowManager.IsCompositionEnabled() ? SystemBrushes.ActiveCaptionText : SystemBrushes.ControlText;
                        e.Graphics.DrawString(Text, Font, br, base.ClientRectangle);
                    }
                    else
                        vs.DrawGlowingText(e.Graphics, base.ClientRectangle, Text, Font, ForeColor, tff);
                }
            }
        }