Example #1
0
 private static void InitializeRenderer(VisualStyleElement element, int state)
 {
     if (visualStyleRenderer == null)
     {
         visualStyleRenderer = new VisualStyleRenderer(element.ClassName, element.Part, state);
     }
     else
     {
         visualStyleRenderer.SetParameters(element.ClassName, element.Part, state);
     }
 }
Example #2
0
        public void VisualStyleRenderer_SetParameters_InvokeVisualStyleElement_Success(VisualStyleElement element)
        {
            var renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Hot);

            renderer.SetParameters(element);
            Assert.Equal(element.ClassName, renderer.Class);
            Assert.Equal(element.Part, renderer.Part);
            Assert.Equal(element.State, renderer.State);
            Assert.Equal(0, renderer.LastHResult);
            Assert.NotEqual(IntPtr.Zero, renderer.Handle);
        }
Example #3
0
 private static void InitializeRenderer(int state)
 {
     if (t_visualStyleRenderer is null)
     {
         t_visualStyleRenderer = new VisualStyleRenderer(s_textBoxElement.ClassName, s_textBoxElement.Part, state);
     }
     else
     {
         t_visualStyleRenderer.SetParameters(s_textBoxElement.ClassName, s_textBoxElement.Part, state);
     }
 }
Example #4
0
 private static void InitializeRenderer(VisualStyleElement element)
 {
     if (visualStyleRenderer == null)
     {
         visualStyleRenderer = new VisualStyleRenderer(element);
     }
     else
     {
         visualStyleRenderer.SetParameters(element);
     }
 }
Example #5
0
 private static void InitializeRenderer(int state)
 {
     if (visualStyleRenderer == null)
     {
         visualStyleRenderer = new VisualStyleRenderer(CheckBoxElement.ClassName, CheckBoxElement.Part, state);
     }
     else
     {
         visualStyleRenderer.SetParameters(CheckBoxElement.ClassName, CheckBoxElement.Part, state);
     }
 }
 private VisualStyleRenderer GetVisualStyleRenderer(VisualStyleElement element)
 {
     if (visualStyleRenderer == null)
     {
         visualStyleRenderer = new VisualStyleRenderer(element);
     }
     else
     {
         visualStyleRenderer.SetParameters(element);
     }
     return(visualStyleRenderer);
 }
Example #7
0
 private VisualStyleRenderer GetVisualStyleRenderer(VisualStyleElement vsElement)
 {
     if (_vsRenderer == null)
     {
         _vsRenderer = new VisualStyleRenderer(vsElement);
     }
     else
     {
         _vsRenderer.SetParameters(vsElement);
     }
     return(_vsRenderer);
 }
Example #8
0
        // Set the element to draw.
        void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // Clear the element description.
            elementDescription.Remove(0, elementDescription.Length);

            // If the user clicked a first-level node, disable drawing.
            if (e.Node.Nodes.Count > 0)
            {
                drawElement = false;
                elementDescription.Append("No element is selected");
                domainUpDown1.Enabled = false;
            }

            // The user clicked an element node.
            else
            {
                // Add the element name to the description.
                elementDescription.Append(e.Node.Text);

                // Get the element that corresponds to the selected
                // node's name.
                String key = e.Node.Name;
                element = elementDictionary[key];

                // Disable resizing if the element is not defined.
                if (!VisualStyleRenderer.IsElementDefined(element))
                {
                    drawElement = false;
                    elementDescription.Append(" is not defined.");
                    domainUpDown1.Enabled = false;
                }
                else
                {
                    // Set the element to the renderer.
                    drawElement = true;
                    renderer.SetParameters(element);
                    elementDescription.Append(" is defined.");

                    // Get the system-defined size of the element.
                    Graphics g = this.CreateGraphics();
                    currentTrueSize = renderer.GetPartSize(g,
                                                           ThemeSizeType.True);
                    g.Dispose();
                    displayRect.Size = currentTrueSize;

                    domainUpDown1.Enabled       = true;
                    domainUpDown1.SelectedIndex = 2;
                }
            }

            Invalidate();
        }
Example #9
0
 protected static void RenderStatusStripBackground(ToolStripRenderEventArgs e)
 {
     if (Application.RenderWithVisualStyles)
     {
         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);
     }
 }
Example #10
0
        /// <summary>Initialize the renderer.</summary>
        /// <param name="state">The state of the control.</param>
        private void InitializeRenderer(int state)
        {
            VisualStyleElement visualstyleelement = VisualStyleElement.Button.GroupBox.Normal;

            if (m_Renderer == null)
            {
                m_Renderer = new VisualStyleRenderer(visualstyleelement.ClassName, visualstyleelement.Part, state);
            }
            else
            {
                m_Renderer.SetParameters(visualstyleelement.ClassName, visualstyleelement.Part, state);
            }
        }
Example #11
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            if (Application.RenderWithVisualStyles)
            {
                renderer.SetParameters(_currentElement);

                renderer.DrawBackground(pe.Graphics, this.ClientRectangle);
            }


            // Calling the base class OnPaint
            base.OnPaint(pe);
        }
        //This sets the renderer to the element we want
        private bool SetRenderer(VisualStyleElement element)
        {
            bool bReturn = VisualStyleRenderer.IsElementDefined(element);

            if (bReturn && renderer == null)
            {
                renderer = new VisualStyleRenderer(element);
            }
            else
            {
                renderer.SetParameters(element);
            }
            return(bReturn);
        }
Example #13
0
        /// <include file='doc\ToolStripRenderer.uex' path='docs/doc[@for="ToolStripRenderer.OnRenderBackground"]/*' />
        /// <devdoc>
        /// Draw the winbar background.  ToolStrip users should override this if they want to draw differently.
        /// </devdoc>
        protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
        {
            ToolStrip toolStrip = e.ToolStrip;
            Graphics  g         = e.Graphics;
            Rectangle bounds    = e.AffectedBounds;

            if (!ShouldPaintBackground(toolStrip))
            {
                return;
            }

            if (toolStrip is StatusStrip)
            {
                RenderStatusStripBackground(e);
            }
            else
            {
                if (DisplayInformation.HighContrast)
                {
                    FillBackground(g, bounds, SystemColors.ButtonFace);
                }
                else if (DisplayInformation.LowResolution)
                {
                    FillBackground(g, bounds, (toolStrip is ToolStripDropDown) ? SystemColors.ControlLight : e.BackColor);
                }
                else if (toolStrip.IsDropDown)
                {
                    FillBackground(g, bounds, (!ToolStripManager.VisualStylesEnabled) ?
                                   e.BackColor : SystemColors.Menu);
                }
                else if (toolStrip is MenuStrip)
                {
                    FillBackground(g, bounds, (!ToolStripManager.VisualStylesEnabled) ?
                                   e.BackColor : SystemColors.MenuBar);
                }
                else if (ToolStripManager.VisualStylesEnabled && VisualStyleRenderer.IsElementDefined(VisualStyleElement.Rebar.Band.Normal))
                {
                    VisualStyleRenderer vsRenderer = VisualStyleRenderer;

                    vsRenderer.SetParameters(VisualStyleElement.ToolBar.Bar.Normal);
                    vsRenderer.DrawBackground(g, bounds);
                }
                else
                {
                    FillBackground(g, bounds, (!ToolStripManager.VisualStylesEnabled) ?
                                   e.BackColor : SystemColors.MenuBar);
                }
            }
        }
Example #14
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); //このサイズでは設定によってはダメかも
         _markSizeLeftRight = new Size(16, 16);
     }
 }
Example #15
0
 private bool SetRenderer(VisualStyleElement element)
 {
     if (!VisualStyleRenderer.IsElementDefined(element))
     {
         return(false);
     }
     if (renderer == null)
     {
         renderer = new VisualStyleRenderer(element);
     }
     else
     {
         renderer.SetParameters(element);
     }
     return(true);
 }
Example #16
0
 private static void InitializeRenderer(int state)
 {
     if (visualStyleRenderer == null)
     {
         visualStyleRenderer = new VisualStyleRenderer(
             VisualStyleElement.Header.Item.Normal.ClassName,
             VisualStyleElement.Header.Item.Normal.Part,
             state);
     }
     else
     {
         visualStyleRenderer.SetParameters(
             VisualStyleElement.Header.Item.Normal.ClassName,
             VisualStyleElement.Header.Item.Normal.Part,
             state);
     }
 }
            public static void DrawHeader(Graphics g, Rectangle bounds, int headerState)
            {
                Rectangle rect = Rectangle.Truncate(g.ClipBounds);

                if (2 == headerState)
                {
                    VisualStyleRenderer.SetParameters(DataGridViewColumnHeaderCell.HeaderElement);
                    Rectangle clipRectangle = new Rectangle(bounds.Left, bounds.Bottom - 2, 2, 2);
                    clipRectangle.Intersect(rect);
                    VisualStyleRenderer.DrawBackground(g, bounds, clipRectangle);
                    clipRectangle = new Rectangle(bounds.Right - 2, bounds.Bottom - 2, 2, 2);
                    clipRectangle.Intersect(rect);
                    VisualStyleRenderer.DrawBackground(g, bounds, clipRectangle);
                }
                VisualStyleRenderer.SetParameters(DataGridViewColumnHeaderCell.HeaderElement.ClassName, DataGridViewColumnHeaderCell.HeaderElement.Part, headerState);
                VisualStyleRenderer.DrawBackground(g, bounds, rect);
            }
Example #18
0
 private static void InitializeRenderer(ListViewItemState state)
 {
     if (visualStyleRenderer == null)
     {
         visualStyleRenderer = new VisualStyleRenderer(
             baseElement.ClassName,
             baseElement.Part,
             (int)state);
     }
     else
     {
         visualStyleRenderer.SetParameters(
             baseElement.ClassName,
             baseElement.Part,
             (int)state);
     }
 }
        private void RenderItemInternal(ToolStripItemRenderEventArgs e)
        {
            ToolStripItem item = e.Item;
            Graphics      g    = e.Graphics;

            ToolBarState       state          = GetToolBarState(item);
            VisualStyleElement toolBarElement = VisualStyleElement.ToolBar.Button.Normal;

            if (ToolStripManager.VisualStylesEnabled &&
                (VisualStyleRenderer.IsElementDefined(toolBarElement)))
            {
                VisualStyleRenderer vsRenderer = VisualStyleRenderer;
                vsRenderer.SetParameters(toolBarElement.ClassName, toolBarElement.Part, (int)state);
                vsRenderer.DrawBackground(g, new Rectangle(Point.Empty, item.Size));

                if (!SystemInformation.HighContrast &&
                    (state == ToolBarState.Hot || state == ToolBarState.Pressed || state == ToolBarState.Checked))
                {
                    var bounds = item.ClientBounds;
                    bounds.Height -= 1;
                    ControlPaint.DrawBorderSimple(g, bounds, SystemColors.Highlight);
                }
            }
            else
            {
                RenderSmall3DBorderInternal(g, new Rectangle(Point.Empty, item.Size), state, (item.RightToLeft == RightToLeft.Yes));
            }

            Rectangle fillRect = item.ContentRectangle;

            if (item.BackgroundImage is not null)
            {
                ControlPaint.DrawBackgroundImage(g, item.BackgroundImage, item.BackColor, item.BackgroundImageLayout, fillRect, fillRect);
            }
            else
            {
                ToolStrip parent = item.GetCurrentParent();
                if ((parent is not null) && (state != ToolBarState.Checked) && (item.BackColor != parent.BackColor))
                {
                    FillBackground(g, fillRect, item.BackColor);
                }
            }
        }
Example #20
0
 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 scroller position is changed we should remember that new position.
         unsafe
         {
             NativeMethods.WINDOWPOS *wp = (NativeMethods.WINDOWPOS *)m.LParam.ToPointer();
             this.x = wp->x;
         }
     }
     else if (m.Msg == NativeMethods.WM_MOUSEMOVE && fparent.lastHotIndex > 0 &&
              fparent.lastHotIndex != fparent.SelectedIndex)
     {
         //owerdrawing former hot tab as normal
         using (Graphics context = Graphics.FromHwnd(fparent.Handle))
         {
             VisualStyleRenderer rend = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Normal);
             fparent.DrawTabItem(context, fparent.lastHotIndex, fparent.GetTabRect(fparent.lastHotIndex), rend);
             if (fparent.lastHotIndex - fparent.SelectedIndex == 1)
             {
                 Rectangle selRect = fparent.GetTabRect(fparent.SelectedIndex);
                 selRect.Inflate(2, 2);
                 rend.SetParameters(rend.Class, rend.Part, (int)TabItemState.Selected);
                 fparent.DrawTabItem(context, fparent.SelectedIndex, selRect, rend);
             }
         }
     }
     else if (m.Msg == NativeMethods.WM_LBUTTONDOWN)
     {
         Rectangle invalidRect = fparent.GetTabRect(fparent.SelectedIndex);
         invalidRect.X = 0; invalidRect.Width = 2;
         invalidRect.Inflate(0, 2);
         fparent.Invalidate(invalidRect);
     }
     base.WndProc(ref m);
 }
 private bool InitializeRenderer()
 {
     if (Application.RenderWithVisualStyles)
     {
         try
         {
             if (rnd == null)
             {
                 rnd = new VisualStyleRenderer(StyleClass, StylePart, (int)ButtonState);
             }
             else
             {
                 rnd.SetParameters(StyleClass, StylePart, (int)ButtonState);
             }
             return(true);
         }
         catch { }
     }
     return(false);
 }
Example #22
0
        /// <summary>
        ///  Draw the button background
        /// </summary>
        protected override void OnRenderOverflowButtonBackground(ToolStripItemRenderEventArgs e)
        {
            ToolStripItem item = e.Item;
            Graphics      g    = e.Graphics;

            if (ToolStripManager.VisualStylesEnabled && VisualStyleRenderer.IsElementDefined(VisualStyleElement.Rebar.Chevron.Normal))
            {
                VisualStyleElement  chevronElement = VisualStyleElement.Rebar.Chevron.Normal;
                VisualStyleRenderer vsRenderer     = VisualStyleRenderer;
                vsRenderer.SetParameters(chevronElement.ClassName, chevronElement.Part, GetItemState(item));
                vsRenderer.DrawBackground(g, new Rectangle(Point.Empty, item.Size));
            }
            else
            {
                RenderItemInternal(e);
                Color arrowColor = item.Enabled ? SystemColors.ControlText : SystemColors.ControlDark;

                DrawArrow(new ToolStripArrowRenderEventArgs(g, item, new Rectangle(Point.Empty, item.Size), arrowColor, ArrowDirection.Down));
            }
        }
Example #23
0
        private static void InitializeRenderer(int state)
        {
            int part = GroupBoxElement.Part;

            if (SystemInformation.HighContrast &&
                ((GroupBoxState)state == GroupBoxState.Disabled) &&
                VisualStyleRenderer.IsCombinationDefined(GroupBoxElement.ClassName, VisualStyleElement.Button.GroupBox.HighContrastDisabledPart))
            {
                part = VisualStyleElement.Button.GroupBox.HighContrastDisabledPart;
            }

            if (visualStyleRenderer == null)
            {
                visualStyleRenderer = new VisualStyleRenderer(GroupBoxElement.ClassName, part, state);
            }
            else
            {
                visualStyleRenderer.SetParameters(GroupBoxElement.ClassName, part, state);
            }
        }
Example #24
0
        private static void InitializeRenderer(int state)
        {
            int part = s_checkBoxElement.Part;

            if (SystemInformation.HighContrast &&
                IsDisabled((CheckBoxState)state) &&
                VisualStyleRenderer.IsCombinationDefined(s_checkBoxElement.ClassName, VisualStyleElement.Button.CheckBox.HighContrastDisabledPart))
            {
                part = VisualStyleElement.Button.CheckBox.HighContrastDisabledPart;
            }

            if (t_visualStyleRenderer == null)
            {
                t_visualStyleRenderer = new VisualStyleRenderer(s_checkBoxElement.ClassName, part, state);
            }
            else
            {
                t_visualStyleRenderer.SetParameters(s_checkBoxElement.ClassName, part, state);
            }
        }
Example #25
0
        private static void InitializeRenderer(int state)
        {
            int part = CheckBoxElement.Part;

            if (AccessibilityImprovements.Level2 &&
                SystemInformation.HighContrast &&
                IsDisabled((CheckBoxState)state) &&
                VisualStyleRenderer.IsCombinationDefined(CheckBoxElement.ClassName, VisualStyleElement.Button.CheckBox.HighContrastDisabledPart))
            {
                part = VisualStyleElement.Button.CheckBox.HighContrastDisabledPart;
            }

            if (visualStyleRenderer == null)
            {
                visualStyleRenderer = new VisualStyleRenderer(CheckBoxElement.ClassName, part, state);
            }
            else
            {
                visualStyleRenderer.SetParameters(CheckBoxElement.ClassName, part, state);
            }
        }
        private static void InitializeRenderer(int state)
        {
            RadioButtonState radioButtonState = (RadioButtonState)state;
            int part = RadioElement.Part;

            if (SystemInformation.HighContrast &&
                (radioButtonState == RadioButtonState.CheckedDisabled || radioButtonState == RadioButtonState.UncheckedDisabled) &&
                VisualStyleRenderer.IsCombinationDefined(RadioElement.ClassName, VisualStyleElement.Button.RadioButton.HighContrastDisabledPart))
            {
                part = VisualStyleElement.Button.RadioButton.HighContrastDisabledPart;
            }

            if (visualStyleRenderer == null)
            {
                visualStyleRenderer = new VisualStyleRenderer(RadioElement.ClassName, part, state);
            }
            else
            {
                visualStyleRenderer.SetParameters(RadioElement.ClassName, part, state);
            }
        }
Example #27
0
 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)
     {
         ReleaseHandle();
     }
     else if (m.Msg == NativeMethods.WM_WINDOWPOSCHANGING)
     {
         //When a scroller position is changed we should remember that new position.
         var wp = (NativeMethods.WINDOWPOS)m.GetLParam(typeof(NativeMethods.WINDOWPOS));
         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 (var context = Graphics.FromHwnd(parentControl.Handle))
         {
             var rend = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Normal);
             parentControl.DrawTabItem(context, parentControl.lastHotIndex, parentControl.GetTabRect(parentControl.lastHotIndex), rend);
             if (parentControl.lastHotIndex - parentControl.SelectedIndex == 1)
             {
                 var 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)
     {
         var invalidRect = parentControl.GetTabRect(parentControl.SelectedIndex);
         invalidRect.X     = 0;
         invalidRect.Width = 2;
         invalidRect.Inflate(0, 2);
         parentControl.Invalidate(invalidRect);
     }
     base.WndProc(ref m);
 }
Example #28
0
 protected override void WndProc(ref Message m)
 {
     //如果本地UPDOWN被破坏,我们需要释放我们的钩子
     if (m.Msg == NativeMethods.WM_DESTROY || m.Msg == NativeMethods.WM_NCDESTROY)
     {
         this.ReleaseHandle();
     }
     else if (m.Msg == NativeMethods.WM_WINDOWPOSCHANGING)
     {
         //当滚动条位置发生变化时,我们应该记住,新的位置。
         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)
     {
         //作为正常的重绘前热片
         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);
 }
        protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
        {
            if (EnsureRenderer())
            {
                renderer.SetParameters(MenuClass, (int)MenuParts.PopupBorders, 0);
                if (e.ToolStrip.IsDropDown)
                {
                    Region oldClip = e.Graphics.Clip;

                    // Tool strip borders are rendered *after* the content, for some reason.
                    // So we have to exclude the inside of the popup otherwise we'll draw over it.
                    Rectangle insideRect = e.ToolStrip.ClientRectangle;
                    insideRect.Inflate(-1, -1);
                    e.Graphics.ExcludeClip(insideRect);

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

                    // Restore the old clip in case the Graphics is used again (does that ever happen?)
                    e.Graphics.Clip = oldClip;
                }
            }
            else
            {
                base.OnRenderToolStripBorder(e);
            }
        }
 /// <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);
 }