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);
                }
            }
        }
        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);
            }
        }
        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();
                    }
                }
            }
        }
 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);
     }
 }
        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 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);
                }
            }
        }
 protected override void WndProc(ref Message m)
 {
     //if native updown is destroyed we need release our hook
     if (m.Msg == NativeMethods.WM_DESTROY || m.Msg == NativeMethods.WM_NCDESTROY)
         this.ReleaseHandle();
     else if (m.Msg == NativeMethods.WM_WINDOWPOSCHANGING)
     {
         //When a scroller position is changed we should remember that new position.
         NativeMethods.WINDOWPOS wp = (NativeMethods.WINDOWPOS)m.GetLParam(typeof(NativeMethods.WINDOWPOS));
         this.x = wp.x;
     }
     else if (m.Msg == NativeMethods.WM_MOUSEMOVE && parentControl.lastHotIndex > 0 &&
         parentControl.lastHotIndex != parentControl.SelectedIndex)
     {
         //redrawing a former hot tab as normal one
         using (Graphics context = Graphics.FromHwnd(parentControl.Handle))
         {
             VisualStyleRenderer rend = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Normal);
             parentControl.DrawTabItem(context, parentControl.lastHotIndex, parentControl.GetTabRect(parentControl.lastHotIndex), rend);
             if (parentControl.lastHotIndex - parentControl.SelectedIndex == 1)
             {
                 Rectangle selRect = parentControl.GetTabRect(parentControl.SelectedIndex);
                 selRect.Inflate(2, 2);
                 rend.SetParameters(rend.Class, rend.Part, (int)TabItemState.Selected);
                 parentControl.DrawTabItem(context, parentControl.SelectedIndex, selRect, rend);
             }
         }
     }
     else if (m.Msg == NativeMethods.WM_LBUTTONDOWN)
     {
         Rectangle invalidRect = parentControl.GetTabRect(parentControl.SelectedIndex);
         invalidRect.X = 0; invalidRect.Width = 2;
         invalidRect.Inflate(0, 2);
         parentControl.Invalidate(invalidRect);
     }
     base.WndProc(ref m);
 }
Ejemplo n.º 8
0
		private void SetLayout()
		{
			if (isMin6 && Application.RenderWithVisualStyles)
			{
				VisualStyleRenderer theme;
				using (Graphics g = this.CreateGraphics())
				{
					// Back button
					theme = new VisualStyleRenderer(VisualStyleElementEx.Navigation.BackButton.Normal);
					Size bbSize = theme.GetPartSize(g, ThemeSizeType.Draw);

					// Title
					theme.SetParameters(VisualStyleElementEx.AeroWizard.TitleBar.Active);
					titleBar.Height = Math.Max(theme.GetMargins2(g, MarginProperty.ContentMargins).Top, bbSize.Height + 2);
					titleBar.ColumnStyles[0].Width = bbSize.Width + 4F;
					titleBar.ColumnStyles[1].Width = titleImageIcon != null ? titleImageList.ImageSize.Width + 4F : 0;
					backButton.Size = bbSize;

					// Header
					theme.SetParameters(VisualStyleElementEx.AeroWizard.HeaderArea.Normal);
					headerLabel.Margin = theme.GetMargins2(g, MarginProperty.ContentMargins);
					headerLabel.ForeColor = theme.GetColor(ColorProperty.TextColor);

					// Content
					theme.SetParameters(VisualStyleElementEx.AeroWizard.ContentArea.Normal);
					this.BackColor = theme.GetColor(ColorProperty.FillColor);
					Padding cp = theme.GetMargins2(g, MarginProperty.ContentMargins);
					contentArea.ColumnStyles[0].Width = cp.Left;
					contentArea.RowStyles[1].Height = cp.Bottom;

					// Command
					theme.SetParameters(VisualStyleElementEx.AeroWizard.CommandArea.Normal);
					cp = theme.GetMargins2(g, MarginProperty.ContentMargins);
					commandArea.RowStyles[0].Height = cp.Top;
					commandArea.RowStyles[2].Height = cp.Bottom;
					commandArea.ColumnStyles[2].Width = contentArea.ColumnStyles[2].Width = cp.Right;
				}
			}
			else
			{
				backButton.Size = new Size(Properties.Resources.BackBtnStrip.Width, Properties.Resources.BackBtnStrip.Height / 4);
			}
		}
Ejemplo n.º 9
0
		public override void OnRenderSplitButtonBackground (ToolStripItemRenderEventArgs e)
		{
			if (!ThemeVisualStyles.RenderClientAreas) {
				base.OnRenderSplitButtonBackground (e);
				return;
			}
			VisualStyleElement element, drop_down_element;
			if (IsDisabled (e.Item)) {
				element = VisualStyleElement.ToolBar.SplitButton.Disabled;
				drop_down_element = VisualStyleElement.ToolBar.SplitButtonDropDown.Disabled;;
			} else if (IsPressed (e.Item)) {
				element = VisualStyleElement.ToolBar.SplitButton.Pressed;
				drop_down_element = VisualStyleElement.ToolBar.SplitButtonDropDown.Pressed;
			} else if (IsChecked (e.Item))
				if (IsHot (e.Item)) {
					element = VisualStyleElement.ToolBar.SplitButton.HotChecked;
					drop_down_element = VisualStyleElement.ToolBar.SplitButtonDropDown.HotChecked;
				} else {
					element = VisualStyleElement.ToolBar.Button.Checked;
					drop_down_element = VisualStyleElement.ToolBar.SplitButtonDropDown.Checked;
				}
			else if (IsHot (e.Item)) {
				element = VisualStyleElement.ToolBar.SplitButton.Hot;
				drop_down_element = VisualStyleElement.ToolBar.SplitButtonDropDown.Hot;
			} else {
				element = VisualStyleElement.ToolBar.SplitButton.Normal;
				drop_down_element = VisualStyleElement.ToolBar.SplitButtonDropDown.Normal;
			}
			if (!VisualStyleRenderer.IsElementDefined (element) ||
				!VisualStyleRenderer.IsElementDefined (drop_down_element)) {
				base.OnRenderSplitButtonBackground (e);
				return;
			}
			ToolStripSplitButton tool_strip_split_button = (ToolStripSplitButton)e.Item;
			VisualStyleRenderer renderer = new VisualStyleRenderer (element);
			renderer.DrawBackground (e.Graphics, tool_strip_split_button.ButtonBounds);
			renderer.SetParameters (drop_down_element);
			renderer.DrawBackground (e.Graphics, tool_strip_split_button.DropDownButtonBounds);
		}
 protected override void OnPaint(PaintEventArgs e)
 {
     int height = base.ClientSize.Height / 2;
     if (Application.RenderWithVisualStyles)
     {
         VisualStyleRenderer renderer = new VisualStyleRenderer((this.mouseOver == UpDownBase.ButtonID.Up) ? VisualStyleElement.Spin.Up.Hot : VisualStyleElement.Spin.Up.Normal);
         if (!base.Enabled)
         {
             renderer.SetParameters(VisualStyleElement.Spin.Up.Disabled);
         }
         else if (this.pushed == UpDownBase.ButtonID.Up)
         {
             renderer.SetParameters(VisualStyleElement.Spin.Up.Pressed);
         }
         renderer.DrawBackground(e.Graphics, new Rectangle(0, 0, 0x10, height));
         if (!base.Enabled)
         {
             renderer.SetParameters(VisualStyleElement.Spin.Down.Disabled);
         }
         else if (this.pushed == UpDownBase.ButtonID.Down)
         {
             renderer.SetParameters(VisualStyleElement.Spin.Down.Pressed);
         }
         else
         {
             renderer.SetParameters((this.mouseOver == UpDownBase.ButtonID.Down) ? VisualStyleElement.Spin.Down.Hot : VisualStyleElement.Spin.Down.Normal);
         }
         renderer.DrawBackground(e.Graphics, new Rectangle(0, height, 0x10, height));
     }
     else
     {
         ControlPaint.DrawScrollButton(e.Graphics, new Rectangle(0, 0, 0x10, height), ScrollButton.Up, (this.pushed == UpDownBase.ButtonID.Up) ? ButtonState.Pushed : (base.Enabled ? ButtonState.Normal : ButtonState.Inactive));
         ControlPaint.DrawScrollButton(e.Graphics, new Rectangle(0, height, 0x10, height), ScrollButton.Down, (this.pushed == UpDownBase.ButtonID.Down) ? ButtonState.Pushed : (base.Enabled ? ButtonState.Normal : ButtonState.Inactive));
     }
     if (height != ((base.ClientSize.Height + 1) / 2))
     {
         using (Pen pen = new Pen(this.parent.BackColor))
         {
             Rectangle clientRectangle = base.ClientRectangle;
             e.Graphics.DrawLine(pen, clientRectangle.Left, clientRectangle.Bottom - 1, clientRectangle.Right - 1, clientRectangle.Bottom - 1);
         }
     }
     base.OnPaint(e);
 }
        /// <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);
                IntPtr ppv;
                using (new SafeDCObjectHandle(memoryHdc, CreateDIBSection(SafeDCHandle.Null, ref info, DIBColorMode.DIB_RGB_COLORS, out 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);
                }
            }
        }
Ejemplo n.º 12
0
            protected override void OnPaint(PaintEventArgs e)
            {
                if (Application.RenderWithVisualStyles)
                {
                    VisualStyleRenderer vsr;

                    // ReSharper disable AssignNullToNotNullAttribute
                    if (IsUp)
                    {
                        vsr = new VisualStyleRenderer(
                            _captured
                                ? VisualStyleElement.Spin.Up.Hot
                                : VisualStyleElement.Spin.Up.Normal);

                        if (!Enabled)
                            vsr.SetParameters(VisualStyleElement.Spin.Up.Disabled);
                        else if (_pushed)
                            vsr.SetParameters(VisualStyleElement.Spin.Up.Pressed);
                    }
                    else
                    {
                        vsr = new VisualStyleRenderer(
                            _captured
                                ? VisualStyleElement.Spin.Down.Hot
                                : VisualStyleElement.Spin.Down.Normal);

                        if (!Enabled)
                            vsr.SetParameters(VisualStyleElement.Spin.Down.Disabled);
                        else if (_pushed)
                            vsr.SetParameters(VisualStyleElement.Spin.Down.Pressed);
                    }
                    // ReSharper restore AssignNullToNotNullAttribute

                    vsr.DrawBackground(e.Graphics, new Rectangle(0, 0, Width, Height));
                }
                else
                {
                    ControlPaint.DrawScrollButton(
                        e.Graphics,
                        new Rectangle(0, 0, Width, Height),
                        IsUp ? ScrollButton.Up : ScrollButton.Down,
                        _pushed
                            ? ButtonState.Pushed
                            : (Enabled
                                ? ButtonState.Normal
                                : ButtonState.Inactive));
                }
            }
        protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e)
        {
            if (e.Item.IsOnDropDown && IsSupported)
            {

                var renderer = new VisualStyleRenderer("menu", 12, e.Item.Enabled ? 2 : 1);

                var bounds = new Rectangle(e.Item.ContentRectangle.X + 1, 0, e.Item.Bounds.Height, e.Item.Bounds.Height);

                if (e.Item.RightToLeft == RightToLeft.Yes)
                    bounds = new Rectangle(e.ToolStrip.ClientSize.Width - bounds.X - bounds.Width, bounds.Y, bounds.Width, bounds.Height);

                renderer.DrawBackground(e.Graphics, bounds);

                var imageRectangle = e.ImageRectangle;

                imageRectangle.X = bounds.X + bounds.Width / 2 - imageRectangle.Width / 2;
                imageRectangle.Y = bounds.Y + bounds.Height / 2 - imageRectangle.Height / 2;

                renderer.SetParameters("menu", 11, e.Item.Enabled ? 1 : 2);

                renderer.DrawBackground(e.Graphics, imageRectangle);

            }
            else
            {
                base.OnRenderItemCheck(e);
            }
        }
Ejemplo n.º 14
0
            /// <include file='doc\UpDownBase.uex' path='docs/doc[@for="UpDownBase.UpDownButtons.OnPaint"]/*' />
            /// <devdoc>
            ///     Handles painting the buttons on the control.
            ///
            /// </devdoc>
            protected override void OnPaint(PaintEventArgs e) {
                int half_height = ClientSize.Height / 2;

                /* Draw the up and down buttons */

                if (Application.RenderWithVisualStyles) {
                    VisualStyleRenderer vsr = new VisualStyleRenderer(mouseOver == ButtonID.Up ? VisualStyleElement.Spin.Up.Hot : VisualStyleElement.Spin.Up.Normal);

                    if (!Enabled) {
                        vsr.SetParameters(VisualStyleElement.Spin.Up.Disabled);
                    }
                    else if (pushed == ButtonID.Up) {
                        vsr.SetParameters(VisualStyleElement.Spin.Up.Pressed);
                    }

                    vsr.DrawBackground(e.Graphics, new Rectangle(0, 0, DefaultButtonsWidth, half_height));

                    if (!Enabled) {
                        vsr.SetParameters(VisualStyleElement.Spin.Down.Disabled);
                    }
                    else if (pushed == ButtonID.Down) {
                        vsr.SetParameters(VisualStyleElement.Spin.Down.Pressed);
                    }
                    else {
                        vsr.SetParameters(mouseOver == ButtonID.Down ? VisualStyleElement.Spin.Down.Hot : VisualStyleElement.Spin.Down.Normal);
                    }

                    vsr.DrawBackground(e.Graphics, new Rectangle(0, half_height, DefaultButtonsWidth, half_height));
                }
                else {
                    ControlPaint.DrawScrollButton(e.Graphics,
                                                  new Rectangle(0, 0, DefaultButtonsWidth, half_height),
                                                  ScrollButton.Up,
                                                  pushed == ButtonID.Up ? ButtonState.Pushed : (Enabled ? ButtonState.Normal : ButtonState.Inactive));

                    ControlPaint.DrawScrollButton(e.Graphics,
                                                  new Rectangle(0, half_height, DefaultButtonsWidth, half_height),
                                                  ScrollButton.Down,
                                                  pushed == ButtonID.Down ? ButtonState.Pushed : (Enabled ? ButtonState.Normal : ButtonState.Inactive));
                }

                if (half_height != (ClientSize.Height + 1) / 2) {
                    // When control has odd height, a line needs to be drawn below the buttons with the backcolor.
                    using (Pen pen = new Pen(this.parent.BackColor)) {
                        Rectangle clientRect = ClientRectangle;
                        e.Graphics.DrawLine(pen, clientRect.Left, clientRect.Bottom - 1, clientRect.Right - 1, clientRect.Bottom - 1);
                    }
                }

                base.OnPaint(e); // raise paint event, just in case this inner class goes public some day
            }
Ejemplo n.º 15
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="TriStateTreeView"/> class.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public TriStateTreeView()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			if (Application.RenderWithVisualStyles)
			{
				using (Bitmap bmp = new Bitmap(m_TriStateImages.ImageSize.Width,
					m_TriStateImages.ImageSize.Height))
				{
					Rectangle rc = new Rectangle(0, 0, bmp.Width, bmp.Height);
					using (Graphics graphics = Graphics.FromImage(bmp))
					{
						VisualStyleRenderer renderer =
							new VisualStyleRenderer(VisualStyleElement.Button.CheckBox.CheckedDisabled);
						renderer.DrawBackground(graphics, rc, rc);
						m_TriStateImages.Images[0] = bmp;

						renderer.SetParameters(VisualStyleElement.Button.CheckBox.UncheckedNormal);
						renderer.DrawBackground(graphics, rc, rc);
						m_TriStateImages.Images[1] = bmp;

						renderer.SetParameters(VisualStyleElement.Button.CheckBox.CheckedNormal);
						renderer.DrawBackground(graphics, rc, rc);
						m_TriStateImages.Images[2] = bmp;
					}
				}
			}

			int index = GetCheckImageIndex(CheckState.Unchecked);
			ImageList = m_TriStateImages;
			ImageIndex = index;
			SelectedImageIndex = index;
		}
Ejemplo n.º 16
0
 private static void CalcSize(Graphics g)
 {
     if (VisualStyleInformation.IsEnabledByUser) {
         VisualStyleRenderer renderer = new VisualStyleRenderer(_elementTop.VSElement);
         _markSizeTopBottom = renderer.GetPartSize(g, ThemeSizeType.True);
         renderer.SetParameters(_elementLeft.VSElement);
         _markSizeLeftRight = renderer.GetPartSize(g, ThemeSizeType.True);
     }
     else {
         _markSizeTopBottom = new Size(16, 16); //���̃T�C�Y�ł͐ݒ�ɂ���Ă̓_������
         _markSizeLeftRight = new Size(16, 16);
     }
 }
Ejemplo n.º 17
0
		protected override void OnPaint(PaintEventArgs e)
		{
			base.OnPaint(e);

			const int thumbPadding = 2;
			const int trackPadding = 2;

			var left = ClientRectangle.Left;
			var top = ClientRectangle.Top;
			var width = ClientRectangle.Width;
			var height = ClientRectangle.Height;
			var cursor = PointToClient(MousePosition);

			// paint focus rectangle
			if (ShowFocusRectangle && Focused) ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle);

			if (!IsLeftMouseButtonDown()) _thumbDragging = false;

			// compute object bounds
			if (Orientation == Orientation.Horizontal)
			{
				_trackBounds = new Rectangle(left + trackPadding, top + height/2 - _trackSize/2, width - 2*trackPadding, _trackSize);
				_thumbBounds = new Rectangle(ValueToPoint(Value).X - _thumbSize/2, top + thumbPadding, _thumbSize, height - 2*thumbPadding);
			}
			else
			{
				_trackBounds = new Rectangle(left + width/2 - _trackSize/2, top + trackPadding, _trackSize, height - 2*trackPadding);
				_thumbBounds = new Rectangle(left + thumbPadding, ValueToPoint(Value).Y - _thumbSize/2, width - 2*thumbPadding, _thumbSize);
			}

			if (System.Windows.Forms.Application.RenderWithVisualStyles)
			{
				if (Orientation == Orientation.Horizontal)
				{
					// paint track
					var renderer = new VisualStyleRenderer(VisualStyleElement.TrackBar.Track.Normal);
					renderer.DrawBackground(e.Graphics, _trackBounds);

					// paint thumb
					if (!Enabled)
						renderer.SetParameters(VisualStyleElement.TrackBar.Thumb.Disabled);
					else if (_thumbDragging)
						renderer.SetParameters(VisualStyleElement.TrackBar.Thumb.Pressed);
					else if (!_thumbBounds.Contains(cursor))
						renderer.SetParameters(Focused ? VisualStyleElement.TrackBar.Thumb.Focused : VisualStyleElement.TrackBar.Thumb.Normal);
					else
						renderer.SetParameters(IsLeftMouseButtonDown() ? VisualStyleElement.TrackBar.Thumb.Pressed : VisualStyleElement.TrackBar.Thumb.Hot);
					renderer.DrawBackground(e.Graphics, _thumbBounds);
				}
				else
				{
					// paint track
					var renderer = new VisualStyleRenderer(VisualStyleElement.TrackBar.TrackVertical.Normal);
					renderer.DrawBackground(e.Graphics, _trackBounds);

					// paint thumb
					if (!Enabled)
						renderer.SetParameters(VisualStyleElement.TrackBar.ThumbVertical.Disabled);
					else if (_thumbDragging)
						renderer.SetParameters(VisualStyleElement.TrackBar.ThumbVertical.Pressed);
					else if (!_thumbBounds.Contains(cursor))
						renderer.SetParameters(Focused ? VisualStyleElement.TrackBar.ThumbVertical.Focused : VisualStyleElement.TrackBar.ThumbVertical.Normal);
					else
						renderer.SetParameters(IsLeftMouseButtonDown() ? VisualStyleElement.TrackBar.ThumbVertical.Pressed : VisualStyleElement.TrackBar.ThumbVertical.Hot);
					renderer.DrawBackground(e.Graphics, _thumbBounds);
				}
			}
			else
			{
				// paint track
				ControlPaint.DrawBorder3D(e.Graphics, _trackBounds, Border3DStyle.Sunken);

				// paint thumb
				if (!Enabled)
					ControlPaint.DrawButton(e.Graphics, _thumbBounds, ButtonState.Inactive);
				else
					ControlPaint.DrawButton(e.Graphics, _thumbBounds, ButtonState.Normal);
			}
		}
Ejemplo n.º 18
0
 /// <summary>Sets the state of the <see cref="VisualStyleRenderer"/>.</summary>
 /// <param name="rnd">The <see cref="VisualStyleRenderer"/> instance.</param>
 /// <param name="state">The state.</param>
 public static void SetState(this VisualStyleRenderer rnd, int state) => rnd.SetParameters(rnd.Class, rnd.Part, state);
Ejemplo n.º 19
0
Archivo: Meter.cs Proyecto: nhannd/Xian
	    protected override void OnPaint(PaintEventArgs e)
		{
			var clientRect = this.ClientRectangle;
			var fillRect = clientRect;
			fillRect.Width = (int)(_value / 100.0 * clientRect.Width);
			try
			{
				// draw background
				var renderer = new VisualStyleRenderer(VisualStyleElement.ProgressBar.Bar.Normal);
				renderer.SetParameters(VsStyles.ProgressBar.Progress,
					VsStyles.ProgressBar.ProgressParts.PP_BAR,
					VsStyles.ProgressBar.FillStates.PBFS_NORMAL);
				renderer.DrawBackground(e.Graphics, this.ClientRectangle);

				// draw filled portion
				renderer.SetParameters(VsStyles.ProgressBar.Progress,
				   VsStyles.ProgressBar.ProgressParts.PP_FILL, (int)_fillState);
				renderer.DrawBackground(e.Graphics, fillRect);
			}
			catch(Exception)
			{
				// the VisualStyles stuff can fail when the OS is < Win7, in which case
				// draw a very basic progress bar manually
				e.Graphics.DrawRectangle(Pens.DarkGray, 0, 0, clientRect.Width - 1, clientRect.Height - 1);
				e.Graphics.FillRectangle(GetStateBrush(), 1, 1,
					Math.Min(fillRect.Width, clientRect.Width - 2), clientRect.Height - 2);
			}

			base.OnPaint(e);
		}
		protected override Rectangle ManagedWindowDrawTitleBarAndBorders (Graphics dc, Rectangle clip, InternalWindowManager wm)
		{
			if (!render_non_client_areas)
				return base.ManagedWindowDrawTitleBarAndBorders (dc, clip, wm);
			VisualStyleElement title_bar_element = ManagedWindowGetTitleBarVisualStyleElement (wm);
			VisualStyleElement left_border_element;
			VisualStyleElement right_border_element;
			VisualStyleElement bottom_border_element;
			ManagedWindowGetBorderVisualStyleElements (wm, out left_border_element, out right_border_element, out bottom_border_element);
			if (!VisualStyleRenderer.IsElementDefined (title_bar_element) ||
				(!wm.IsMinimized && (
				!VisualStyleRenderer.IsElementDefined (left_border_element) ||
				!VisualStyleRenderer.IsElementDefined (right_border_element) ||
				!VisualStyleRenderer.IsElementDefined (bottom_border_element))))
				return base.ManagedWindowDrawTitleBarAndBorders (dc, clip, wm);
			VisualStyleRenderer renderer = new VisualStyleRenderer (title_bar_element);
			Rectangle title_bar_rectangle = ManagedWindowGetTitleBarRectangle (wm);
			renderer.DrawBackground (dc, title_bar_rectangle, clip);
			if (!wm.IsMinimized) {
				int border_width = ManagedWindowBorderWidth (wm);
				renderer.SetParameters (left_border_element);
				renderer.DrawBackground (dc, new Rectangle (
					0,
					title_bar_rectangle.Bottom,
					border_width,
					wm.Form.Height - title_bar_rectangle.Bottom
					), clip);
				renderer.SetParameters (right_border_element);
				renderer.DrawBackground (dc, new Rectangle (
					wm.Form.Width - border_width,
					title_bar_rectangle.Bottom,
					border_width,
					wm.Form.Height - title_bar_rectangle.Bottom
					), clip);
				renderer.SetParameters (bottom_border_element);
				renderer.DrawBackground (dc, new Rectangle (
					0,
					wm.Form.Height - border_width,
					wm.Form.Width,
					border_width
					), clip);
			}
			return title_bar_rectangle;
		}
        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));
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Draws our tab control.
        /// </summary>
        /// <param name="g">The <see cref="System.Drawing.Graphics"/> object used to draw tab control.</param>
        /// <param name="clipRect">The <see cref="System.Drawing.Rectangle"/> that specifies clipping rectangle
        /// of the control.</param>
        private void DrawCustomTabControl(Graphics g, Rectangle clipRect)
        {
            /* In this method we draw only those parts of the control which intersects with the
             * clipping rectangle. It's some kind of optimization.*/
            if (!this.Visible) return;

            //selected tab index and rectangle
            int iSel = this.SelectedIndex;
            Rectangle selRect = iSel != -1 ? this.GetTabRect(iSel) : Rectangle.Empty;

            Rectangle rcPage = this.ClientRectangle;
            //correcting page rectangle
            switch (this.Alignment)
            {
                case TabAlignment.Top:
                    {
                        int trunc = selRect.Height * this.RowCount + 2;
                        rcPage.Y += trunc; rcPage.Height -= trunc;
                    } break;
                case TabAlignment.Bottom: rcPage.Height -= (selRect.Height + XPTabControl.sAdjHeight) * this.RowCount; break;
            }

            //draw page itself
            if (rcPage.IntersectsWith(clipRect)) TabRenderer.DrawTabPage(g, rcPage);

            int tabCount = this.TabCount;
            if (tabCount == 0) return;

            //drawing unselected tabs
            this.lastHotIndex = HitTest();//hot tab
            VisualStyleRenderer tabRend = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Normal);
            for (int iTab = 0; iTab < tabCount; iTab++)
                if (iTab != iSel)
                {
                    Rectangle tabRect = this.GetTabRect(iTab);
                    if (tabRect.Right >= 3 && tabRect.IntersectsWith(clipRect))
                    {
                        TabItemState state = iTab == this.lastHotIndex ? TabItemState.Hot : TabItemState.Normal;
                        tabRend.SetParameters(tabRend.Class, tabRend.Part, (int)state);
                        DrawTabItem(g, iTab, tabRect, tabRend);
                    }
                }

            /* Drawing selected tab. We'll also increase selected tab's rectangle. It should be a little
             * bigger than other tabs.*/
            selRect.Inflate(2, 2);
            if (iSel != -1 && selRect.IntersectsWith(clipRect))
            {
                tabRend.SetParameters(tabRend.Class, tabRend.Part, (int)TabItemState.Selected);
                DrawTabItem(g, iSel, selRect, tabRend);
            }
        }
Ejemplo n.º 23
0
        protected override void OnPaint(PaintEventArgs e)
        {
            // Draw the background

            _ownerPropertyEnum.Property.ParentGrid.DrawManager.DrawPropertyValueBackground(e.Graphics,
                ClientRectangle, _ownerPropertyEnum);

            // Draw the combobox arrow

            Rectangle buttonRect = GetButtonRect(e.Graphics);

            if (Application.RenderWithVisualStyles)
            {
                VisualStyleRenderer renderer1 = new VisualStyleRenderer(_mouseOver ? VisualStyleElement.ComboBox.DropDownButton.Hot : VisualStyleElement.ComboBox.DropDownButton.Normal);
                if (_pushed)
                    renderer1.SetParameters(VisualStyleElement.ComboBox.DropDownButton.Pressed);

                renderer1.DrawBackground(e.Graphics, buttonRect);
            }
            else
            {
                ControlPaint.DrawComboButton(e.Graphics, buttonRect, _mouseOver ? ButtonState.Pushed : ButtonState.Normal);
            }

            if (Focused && (_ownerPropertyEnum.Property.InPlaceCtrlInAction == null))
            {
                Rectangle focusRect = buttonRect;
                focusRect.Inflate(-3, -3);
                ControlPaint.DrawFocusRectangle(e.Graphics, focusRect);
            }

            // Draw the value
            if (_edit == null)
            {
                Rectangle valueRect = ClientRectangle;
                valueRect.Width -= buttonRect.Width + 1;

                if (Focused && (_ownerPropertyEnum.Property.InPlaceCtrlInAction == null))
                {
                    Rectangle fillRect = _ownerPropertyEnum.Property.Value.GetStringValueRect(e.Graphics, valueRect, Point.Empty);
                    fillRect.Y++;
                    fillRect.Height-=2;
                    fillRect.X -= PropertyGrid.GlobalTextMargin / 2;
                    fillRect.Width = buttonRect.Left - 1 - fillRect.Left;
                    e.Graphics.FillRectangle(SystemBrushes.FromSystemColor(SystemColors.Highlight), fillRect);
                }

                Color valueColor;
                if (_ownerPropertyEnum.Property.Enabled == false)
                    valueColor = SystemColors.GrayText;
                else
                {
                    if (Focused && (_ownerPropertyEnum.Property.InPlaceCtrlInAction == null))
                        valueColor = SystemColors.HighlightText;
                    else
                        valueColor = _ownerPropertyEnum.Property.Value.ForeColor;
                }

                _ownerPropertyEnum.Property.Value.DrawValue(e.Graphics, valueRect, valueColor, _ownerPropertyEnum, Text);
            }

            base.OnPaint(e);
        }