コード例 #1
0
        protected override void OnRenderToolStripPanelBackground(ToolStripPanelRenderEventArgs e)
        {
            //Draw the background using Rebar & RP_BACKGROUND (or, if that is not available, fall back to
            //Rebar.Band.Normal)
            if (VisualStyleRenderer.IsElementDefined(VisualStyleElement.CreateElement(RebarClass, RP_BACKGROUND, 0)))
            {
                renderer.SetParameters(RebarClass, RP_BACKGROUND, 0);
            }
            else
            {
                renderer.SetParameters(RebarClass, 0, 0);
                //renderer.SetParameters(VisualStyleElement.Taskbar.BackgroundBottom.Normal);
                //renderer.SetParameters(Subclass(VisualStyleElement.Rebar.Band.Normal));
            }

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

            renderer.DrawBackground(e.Graphics, e.ToolStripPanel.ClientRectangle);

            //Draw the etched edges of each row.
            //renderer.SetParameters(Subclass(VisualStyleElement.Rebar.Band.Normal));
            //foreach (ToolStripPanelRow row in e.ToolStripPanel.Rows) {
            //    Rectangle rowBounds = row.Bounds;
            //    rowBounds.Offset(0, -1);
            //    renderer.DrawEdge(e.Graphics, rowBounds, Edges.Top, EdgeStyle.Etched, EdgeEffects.None);
            //}

            e.Handled = true;
        }
コード例 #2
0
        protected override void OnRenderToolStripPanelBackground(ToolStripPanelRenderEventArgs e)
        {
            if (EnsureRenderer())
            {
                // Draw the background using Rebar & RP_BACKGROUND (or, if that is not available, fall back to
                // Rebar.Band.Normal)
                if (VisualStyleRenderer.IsElementDefined(VisualStyleElement.CreateElement(RebarClass, RebarBackground, 0)))
                {
                    renderer.SetParameters(RebarClass, RebarBackground, 0);
                }
                else
                {
                    renderer.SetParameters(RebarClass, 0, 0);
                }

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

                renderer.DrawBackground(e.Graphics, e.ToolStripPanel.ClientRectangle);

                e.Handled = true;
            }
            else
            {
                base.OnRenderToolStripPanelBackground(e);
            }
        }
コード例 #3
0
    /// <summary>
    /// Paints the control using the Buffered Paint API.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void bufferedPainter_PaintVisualState(object sender, BufferedPaintEventArgs <ComboBoxState> e)
    {
        if (_drawWithVisualStyles && _bufferedPainter.BufferedPaintSupported && _bufferedPainter.Enabled)
        {
            // draw in the vista/win7 style
            VisualStyleRenderer r = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal);
            r.DrawParentBackground(e.Graphics, ClientRectangle, this);

            Rectangle buttonBounds = ClientRectangle;
            buttonBounds.Inflate(1, 1);
            ButtonRenderer.DrawButton(e.Graphics, buttonBounds, GetPushButtonState(e.State));

            Rectangle clipBounds = _dropDownButtonBounds;
            clipBounds.Inflate(-2, -2);
            e.Graphics.SetClip(clipBounds);
            ComboBoxRenderer.DrawDropDownButton(e.Graphics, _dropDownButtonBounds, e.State);
            e.Graphics.SetClip(ClientRectangle);
        }
        else if (_drawWithVisualStyles && ComboBoxRenderer.IsSupported)
        {
            // draw using the visual style renderer
            ComboBoxRenderer.DrawTextBox(e.Graphics, ClientRectangle, GetTextBoxState());
            ComboBoxRenderer.DrawDropDownButton(e.Graphics, _dropDownButtonBounds, e.State);
        }
        else
        {
            // draw using the legacy technique
            DrawLegacyComboBox(e.Graphics, ClientRectangle, _dropDownButtonBounds, BackColor, GetPlainButtonState());
        }

        OnPaintContent(new DropDownPaintEventArgs(e.Graphics, ClientRectangle, GetTextBoxBounds()));
    }
コード例 #4
0
            public override void Paint(PaintEventArgs e)
            {
                Layout(e);

                // Get TaskDialog-PrimaryPanel
                var vs = new VisualStyleRenderer(taskDialogClass, 1, 0);

                vs.DrawParentBackground(e.Graphics, Control.ClientRectangle, Control);
                if (Control.headerHot)
                {
                    // Get ListView-GroupHeader-OpenHot
                    vs = new VisualStyleRenderer("ListView", 6, 2);
                    var hdrRect = Control.ClientRectangle;
                    hdrRect.Height = headerHeight;
                    vs.DrawBackground(e.Graphics, hdrRect, e.ClipRectangle);
                }
                // Get TaskDialog-ExpandoButton
                vs = new VisualStyleRenderer(taskDialogClass, 13, ((int)Control.buttonState) + 1);
                vs.DrawBackground(e.Graphics, buttonBounds);
                // Get TaskDialog-MainInstructionPane
                vs = new VisualStyleRenderer(taskDialogClass, 2, 0);
                var tff = TextFormatFlags.SingleLine;

                if (Control.GetRightToLeftProperty() == RightToLeft.Yes)
                {
                    tff |= TextFormatFlags.RightToLeft;
                }
                vs.DrawText(e.Graphics, textBounds, Control.Text, !Control.Enabled, tff);
            }
コード例 #5
0
        public void VisualStyleRenderer_DrawParentBackground_NullDc_ThrowsArgumentNullException()
        {
            var renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal);

            using var childControl = new Control();
            Assert.Throws <ArgumentNullException>("dc", () => renderer.DrawParentBackground(null, new Rectangle(1, 2, 3, 4), childControl));
        }
コード例 #6
0
ファイル: SummarySlice.cs プロジェクト: vkarthim/FieldWorks
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            e.Graphics.FillRectangle(new SolidBrush(BackColor), ClientRectangle);

            VisualStyleRenderer renderer = Renderer;

            if (renderer != null)
            {
                if (renderer.IsBackgroundPartiallyTransparent())
                {
                    renderer.DrawParentBackground(e.Graphics, ClientRectangle, this);
                }
                renderer.DrawBackground(e.Graphics, ClientRectangle, e.ClipRectangle);
            }
            else
            {
                using (var boxLinePen = new Pen(SystemColors.ControlDark, 1))
                {
                    e.Graphics.DrawRectangle(boxLinePen, ClientRectangle);
                    int ctrY = ClientRectangle.Y + (ClientRectangle.Height / 2);
                    // Draw the minus sign.
                    e.Graphics.DrawLine(boxLinePen, ClientRectangle.X + 2, ctrY, ClientRectangle.X + ClientRectangle.Width - 2, ctrY);
                    if (!m_opened)
                    {
                        // Draw the vertical part of the plus, if we are collapsed.
                        int ctrX = ClientRectangle.X + (ClientRectangle.Width / 2);
                        e.Graphics.DrawLine(boxLinePen, ctrX, ClientRectangle.Y + 4, ctrX, ClientRectangle.Y + ClientRectangle.Height - 4);
                    }
                }
            }
        }
コード例 #7
0
ファイル: XButton.cs プロジェクト: vkarthim/l10nsharp
        /// ------------------------------------------------------------------------------------
        /// <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.
            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.Equals(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.
            var arrowGlyph = (m_drawLeftArrowButton ? "3" : "4");

            var 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, fTxtFmtflags);
        }
コード例 #8
0
    /// <summary>
    /// Paints the control (using the Buffered Paint API).
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void _bufferedPainter_PaintVisualState(object sender, BufferedPaintEventArgs <ComboBoxState> e)
    {
        VisualStyleRenderer r = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal);

        r.DrawParentBackground(e.Graphics, ClientRectangle, this);

        DrawComboBox(e.Graphics, ClientRectangle, e.State);

        Rectangle itemBounds = new Rectangle(0, 0, Width - 21, Height);

        itemBounds.Inflate(-1, -3);
        itemBounds.Offset(2, 0);

        // draw the item in the editable portion
        DrawItemState state = DrawItemState.ComboBoxEdit;

        if (Focused && ShowFocusCues && !DroppedDown)
        {
            state |= DrawItemState.Focus;
        }
        if (!Enabled)
        {
            state |= DrawItemState.Disabled;
        }
        OnDrawItem(new DrawItemEventArgs(e.Graphics, Font, itemBounds, SelectedIndex, state));
    }
コード例 #9
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));

            var arrowGlyph = Platform.IsWindows
                             // In the Marlett font, '3' is the left arrow and '4' is the right.
                                ? (m_drawLeftArrowButton ? "3" : "4")
                             // Linux doesn't have the Marlett font, so use standard Unicode dingbats here.
                                : (m_drawLeftArrowButton ? "\u25C4" : "\u25BA");

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

            TextRenderer.DrawText(e.Graphics, arrowGlyph, Font, rc, clr, m_txtFmtflags);
        }
コード例 #10
0
 /// <summary>
 ///  This is just a convenience wrapper for VisualStyleRenderer.DrawThemeParentBackground. For downlevel,
 ///  this isn't required and does nothing.
 /// </summary>
 public static void DrawParentBackground(Graphics g, Rectangle bounds, Control childControl)
 {
     if (RenderWithVisualStyles)
     {
         InitializeRenderer(0);
         visualStyleRenderer.DrawParentBackground(g, bounds, childControl);
     }
 }
コード例 #11
0
 internal static void DrawParentBackground(IDeviceContext dc, Rectangle bounds, Control childControl)
 {
     if (RenderWithVisualStyles)
     {
         InitializeRenderer(0);
         t_visualStyleRenderer.DrawParentBackground(dc, bounds, childControl);
     }
 }
コード例 #12
0
        private void DrawBackground(ToolStripRenderEventArgs e)
        {
            if (Renderer.IsBackgroundPartiallyTransparent())
            {
                Renderer.DrawParentBackground(e.Graphics, e.ToolStrip.ClientRectangle, e.ToolStrip);
            }

            Renderer.DrawBackground(e.Graphics, e.ToolStrip.ClientRectangle, e.AffectedBounds);
        }
コード例 #13
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);
                    }
                }
            }
        }
コード例 #14
0
        public static void DrawParentBackground(Graphics g, Rectangle_ bounds, Control childControl)
        {
            if (!VisualStyleRenderer.IsSupported)
            {
                return;
            }

            VisualStyleRenderer vsr = new VisualStyleRenderer(VisualStyleElement.Button.CheckBox.UncheckedNormal);

            vsr.DrawParentBackground(g, bounds, childControl);
        }
コード例 #15
0
        public static void DrawParentBackground(Graphics g, Rectangle bounds, Control childControl)
        {
            if (!VisualStyleRenderer.IsSupported)
            {
                return;
            }

            VisualStyleRenderer vsr = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Default);

            vsr.DrawParentBackground(g, bounds, childControl);
        }
コード例 #16
0
        public void VisualStyleRenderer_DrawParentBackgroundInvokeIDeviceContextRectangleChildWithoutHandle_Success(Rectangle bounds)
        {
            // Don't verify anything, just make sure the interop call succeeds.
            var renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal);

            using var bitmap        = new Bitmap(10, 10);
            using Graphics graphics = Graphics.FromImage(bitmap);
            using var childControl  = new Control();
            renderer.DrawParentBackground(graphics, bounds, childControl);
            Assert.False(childControl.IsHandleCreated);
            Assert.Equal(0, renderer.LastHResult);
        }
コード例 #17
0
        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);
            }
        }
コード例 #18
0
    /// <summary>
    /// Paints the control using the Buffered Paint API.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void bufferedPainter_PaintVisualState(object sender, BufferedPaintEventArgs <ComboBoxState> e)
    {
        if (_drawWithVisualStyles && _bufferedPainter.BufferedPaintSupported && _bufferedPainter.Enabled && (_style == DropDownControlStyles.Discrete))
        {
            // draw in the vista/win7 style
            VisualStyleRenderer r = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal);
            r.DrawParentBackground(e.Graphics, ClientRectangle, this);

            Rectangle buttonBounds = ClientRectangle;
            buttonBounds.Inflate(1, 1);
            ButtonRenderer.DrawButton(e.Graphics, buttonBounds, GetPushButtonState(e.State));

            Rectangle clipBounds = _dropDownButtonBounds;
            clipBounds.Inflate(-2, -2);
            e.Graphics.SetClip(clipBounds);
            ComboBoxRenderer.DrawDropDownButton(e.Graphics, _dropDownButtonBounds, e.State);
            e.Graphics.SetClip(ClientRectangle);
        }
        else if (_drawWithVisualStyles && ComboBoxRenderer.IsSupported)
        {
            // draw using the visual style renderer
            if (Enabled)
            {
                ComboBoxRenderer.DrawTextBox(e.Graphics, ClientRectangle, GetTextBoxState());
            }
            else
            {
                Rectangle outline = ClientRectangle;
                outline.Width--;
                outline.Height--;
                e.Graphics.FillRectangle(SystemBrushes.Control, ClientRectangle);
                e.Graphics.DrawRectangle(Pens.LightGray, outline);
            }

            DrawDropDownGlyph(e.Graphics, _dropDownButtonBounds, e.State);
        }
        else
        {
            // draw using the legacy technique
            DrawLegacyComboBox(e.Graphics, ClientRectangle, _dropDownButtonBounds, BackColor, GetPlainButtonState());
        }

        OnPaintContent(new DropDownPaintEventArgs(e.Graphics, ClientRectangle, GetTextBoxBounds()));
    }
コード例 #19
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 override void PaintButton(Graphics graphics, Rectangle bounds)
        {
            if (Application.RenderWithVisualStyles)
            {
                try
                {
                    VisualStyleRenderer rnd = new VisualStyleRenderer(StyleClass, StylePart, (int)ButtonState);
                    if (this.IsDesignMode() || !DesktopWindowManager.IsCompositionEnabled())
                    {
                        rnd.DrawParentBackground(graphics, bounds, this);
                        rnd.DrawBackground(graphics, bounds);
                    }
                    else
                    {
                        rnd.DrawGlassBackground(graphics, bounds, bounds);
                    }
                    return;
                }
                catch { }
            }
            else
            {
                base.PaintButton(graphics, bounds);

                /*Rectangle sr = this.ClientRectangle;
                 * sr.Offset(0, sr.Height * ((int)ButtonState - 1));
                 * graphics.Clear(this.Parent.BackColor);
                 * if (imageStrip != null)
                 * {
                 *      Bitmap bmp = imageStrip.Clone(sr, imageStrip.PixelFormat);
                 *      if (this.IsDesignMode() || !DesktopWindowManager.IsCompositionEnabled())
                 *      {
                 *              base.ImageList.Draw(graphics, bounds.X, bounds.Y, bounds.Width, bounds.Height, ((int)ButtonState - 1));
                 *      }
                 *      else
                 *      {
                 *              VisualStyleRendererExtender.DrawGlassImage(null, graphics, bounds, bmp);
                 *      }
                 * }
                 * else
                 *      using (Brush br = new SolidBrush(this.BackColor))
                 *              graphics.FillRectangle(br, sr);*/
            }
        }
コード例 #20
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);
        }
コード例 #21
0
        /// <summary>
        /// Paints the control (using the Buffered Paint API).
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _bufferedPainter_PaintVisualState(object sender, BufferedPaintEventArgs <ComboBoxState> e)
        {
            var r = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal);

            r.DrawParentBackground(e.Graphics, ClientRectangle, this);

            var buttonBounds = new Rectangle(Width - 17, 0, 17, Height - (e.State != ComboBoxState.Pressed ? 1 : 0));

            var bounds = ClientRectangle;

            bounds.Inflate(1, 1);

            ButtonRenderer.DrawButton(e.Graphics, bounds, GetPushButtonState(e.State));

            Rectangle buttonClip = buttonBounds;

            buttonClip.Inflate(-2, -2);

            e.Graphics.SetClip(buttonClip);
            ComboBoxRenderer.DrawDropDownButton(e.Graphics, buttonBounds, e.State);
            e.Graphics.SetClip(ClientRectangle);

            var itemBounds = new Rectangle(0, 0, Width - 21, Height);

            itemBounds.Inflate(-1, -3);
            itemBounds.Offset(2, 0);

            // draw the item in the editable portion
            var state = DrawItemState.ComboBoxEdit;

            if (Focused && ShowFocusCues && !DroppedDown)
            {
                state |= DrawItemState.Focus;
            }
            if (!Enabled)
            {
                state |= DrawItemState.Disabled;
            }
            OnDrawItem(new DrawItemEventArgs(e.Graphics, Font, itemBounds, SelectedIndex, state));
        }
コード例 #22
0
        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);
            }
        }
コード例 #23
0
        /// <summary>
        /// Paints the control.
        /// </summary>
        /// <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param>
        protected virtual void PaintControl(PaintEventArgs e)
        {
            var cbi = NativeMethods.COMBOBOXINFO.FromComboBox(this);

            string        itemText = this.SelectedIndex >= 0 ? this.GetItemText(this.SelectedItem) : string.Empty;
            ComboBoxState state    = Enabled ? currentState : ComboBoxState.Disabled;
            Rectangle     tr       = cbi.rcItem;

            /*Rectangle tr = this.ClientRectangle;
             * tr.Width -= (SystemInformation.VerticalScrollBarWidth + 2);
             * tr.Inflate(0, -2);
             * tr.Offset(1, 0);*/
            Rectangle br        = cbi.rcButton;
            bool      vsSuccess = false;

            if (VisualStyleRenderer.IsSupported && Application.RenderWithVisualStyles)
            {
                /*Rectangle r = Rectangle.Inflate(this.ClientRectangle, 1, 1);
                 * if (this.DropDownStyle != ComboBoxStyle.DropDownList)
                 * {
                 *      e.Graphics.Clear(this.BackColor);
                 *      ComboBoxRenderer.DrawTextBox(e.Graphics, r, itemText, this.Font, tr, tff, state);
                 *      ComboBoxRenderer.DrawDropDownButton(e.Graphics, br, state);
                 * }
                 * else*/
                {
                    try
                    {
                        var vr = new VisualStyleRenderer("Combobox", this.DropDownStyle == ComboBoxStyle.DropDownList ? 5 : 4, (int)state);
                        vr.DrawParentBackground(e.Graphics, this.ClientRectangle, this);
                        vr.DrawBackground(e.Graphics, this.ClientRectangle);
                        if (this.DropDownStyle != ComboBoxStyle.DropDownList)
                        {
                            br.Inflate(1, 1);
                        }
                        Rectangle cr = this.DropDownStyle == ComboBoxStyle.DropDownList ? Rectangle.Inflate(br, -1, -1) : br;
                        vr.SetParameters("Combobox", 7, (int)(br.Contains(this.PointToClient(Cursor.Position)) ? state : ComboBoxState.Normal));
                        vr.DrawBackground(e.Graphics, br, cr);
                        if (this.Focused && State != ComboBoxState.Pressed)
                        {
                            Size      sz = TextRenderer.MeasureText(e.Graphics, "Wg", this.Font, tr.Size, TextFormatFlags.Default);
                            Rectangle fr = Rectangle.Inflate(tr, 0, ((sz.Height - tr.Height) / 2) + 1);
                            ControlPaint.DrawFocusRectangle(e.Graphics, fr);
                        }
                        TextRenderer.DrawText(e.Graphics, itemText, this.Font, tr, this.ForeColor, tff);
                        vsSuccess = true;
                    }
                    catch { }
                }
            }

            if (!vsSuccess)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("CR:{0};ClR:{1};Foc:{2};St:{3};Tx:{4}", ClientRectangle, e.ClipRectangle, this.Focused, state, itemText));
                e.Graphics.Clear(this.BackColor);
                ControlPaint.DrawBorder3D(e.Graphics, this.ClientRectangle, Border3DStyle.Sunken);
                ControlPaint.DrawComboButton(e.Graphics, br, this.Enabled ? (state == ComboBoxState.Pressed ? ButtonState.Pushed : ButtonState.Normal) : ButtonState.Inactive);
                //using (var bb = new SolidBrush(this.BackColor))
                //	e.Graphics.FillRectangle(bb, tr);
                if (this.Focused)
                {
                    Size      sz = TextRenderer.MeasureText(e.Graphics, "Wg", this.Font, tr.Size, TextFormatFlags.Default);
                    Rectangle fr = Rectangle.Inflate(tr, 0, ((sz.Height - tr.Height) / 2) + 1);
                    e.Graphics.FillRectangle(SystemBrushes.Highlight, fr);
                    ControlPaint.DrawFocusRectangle(e.Graphics, fr);                     //, this.ForeColor, SystemColors.Highlight);
                }
                TextRenderer.DrawText(e.Graphics, itemText, this.Font, tr, this.Focused ? SystemColors.HighlightText : this.ForeColor, tff);
            }
        }
コード例 #24
0
        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 = AppDefs.ColorQualityLow;
            Color clrEnd   = AppDefs.ColorQualityHigh;

            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);
        }
コード例 #25
0
    /// <summary>
    /// Paints the control (using the Buffered Paint API).
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void _bufferedPainter_PaintVisualState(object sender, BufferedPaintEventArgs<ComboBoxState> e) {
		VisualStyleRenderer r = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal);
		r.DrawParentBackground(e.Graphics, ClientRectangle, this);
		
		DrawComboBox(e.Graphics, ClientRectangle, e.State);

		Rectangle itemBounds = new Rectangle(0, 0, Width - 21, Height);
		itemBounds.Inflate(-1, -3);
		itemBounds.Offset(2, 0);

        // draw the item in the editable portion
        DrawItemState state = DrawItemState.ComboBoxEdit;
        if (Focused && ShowFocusCues && !DroppedDown) state |= DrawItemState.Focus;
        if (!Enabled) state |= DrawItemState.Disabled;
        OnDrawItem(new DrawItemEventArgs(e.Graphics, Font, itemBounds, SelectedIndex, state));
    }
コード例 #26
0
        /// <summary>
        /// Raises the Paint event.
        /// </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 (Image != null)
                {
                    //Rectangle ir = CalcImageRenderBounds(this.Image, r, base.RtlTranslateAlignment(this.ImageAlign));
                    if (ImageList != null && ImageIndex == 0)
                    {
                        if (vs != null && !this.IsDesignMode() && DesktopWindowManager.IsCompositionEnabled())
                        {
                            vs.DrawGlassImage(e.Graphics, r, ImageList, ImageIndex);
                        }
                        else
                        {
                            ImageList.Draw(e.Graphics, r.X, r.Y, r.Width, r.Height, ImageIndex);
                        }
                    }
                    else
                    {
                        if (vs != null && !this.IsDesignMode() && DesktopWindowManager.IsCompositionEnabled())
                        {
                            vs.DrawGlassImage(e.Graphics, r, Image);
                        }
                        else
                        {
                            e.Graphics.DrawImage(Image, r);
                        }
                    }
                }

                // Draw text
                if (Text.Length > 0)
                {
                    if (this.IsDesignMode() || vs == null || !DesktopWindowManager.IsCompositionEnabled())
                    {
                        Brush        br = DesktopWindowManager.IsCompositionEnabled() ? SystemBrushes.ActiveCaptionText : SystemBrushes.ControlText;
                        StringFormat sf = new StringFormat(StringFormat.GenericDefault);
                        if (this.GetRightToLeftProperty() == System.Windows.Forms.RightToLeft.Yes)
                        {
                            sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                        }
                        e.Graphics.DrawString(Text, Font, br, base.ClientRectangle, sf);
                    }
                    else
                    {
                        TextFormatFlags tff = CreateTextFormatFlags(base.RtlTranslateAlignment(TextAlign), AutoEllipsis, UseMnemonic);
                        vs.DrawGlowingText(e.Graphics, base.ClientRectangle, Text, Font, ForeColor, tff);
                    }
                }
            }
        }
コード例 #27
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);
                }
            }
        }
コード例 #28
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);

            if (pevent == null || !showSplit)
            {
                return;
            }

            Graphics  g      = pevent.Graphics;
            Rectangle bounds = this.ClientRectangle;

            // draw the button background as according to the current state.
            if (State != PushButtonState.Pressed && IsDefault && !Application.RenderWithVisualStyles)
            {
                Rectangle backgroundBounds = bounds;
                backgroundBounds.Inflate(-1, -1);

                ButtonRenderer.DrawButton(g, backgroundBounds, State);

                // button renderer doesnt draw the black frame when themes are off =(
                g.DrawRectangle(SystemPens.WindowFrame, 0, 0, bounds.Width - 1, bounds.Height - 1);
            }
            else
            {
                if (renderer != null)
                {
                    renderer.SetParameters(GetVisualStyleElement(State, Focused));

                    if (renderer.IsBackgroundPartiallyTransparent())
                    {
                        renderer.DrawParentBackground(g, bounds, this);
                    }

                    //
                    // We are using the visual style of a window's close button. In order to render the 'X' offset from center, we render twice:
                    // 1. Render the entire width of the control so the background of the dropdown arrow has the correct style
                    // -------------
                    // |     X     |
                    // -------------
                    // 2. Render the main button portion only which will cover up the originally centered 'X' and render the 'X' offset.
                    // ---------
                    // |   X   |
                    // ---------
                    //
                    Rectangle boundsLessArrowPart = new Rectangle(bounds.Location, new Size(bounds.Width - PushButtonWidth, bounds.Height));
                    if (RightToLeft == System.Windows.Forms.RightToLeft.Yes)
                    {
                        boundsLessArrowPart.X += PushButtonWidth + 1;
                    }

                    renderer.DrawBackground(g, bounds);
                    renderer.DrawBackground(g, boundsLessArrowPart);
                }
                else
                {
                    ButtonRenderer.DrawButton(g, bounds, State);
                }
            }
            // calculate the current dropdown rectangle.
            dropDownRectangle = new Rectangle(bounds.Right - PushButtonWidth - 1, BorderSize, PushButtonWidth, bounds.Height - BorderSize * 2);

            int       internalBorder = BorderSize;
            Rectangle focusRect      =
                new Rectangle(internalBorder,
                              internalBorder,
                              bounds.Width - dropDownRectangle.Width - internalBorder,
                              bounds.Height - (internalBorder * 2));

            bool drawSplitLine = (State == PushButtonState.Hot || State == PushButtonState.Pressed || !Application.RenderWithVisualStyles);

            if (RightToLeft == RightToLeft.Yes)
            {
                dropDownRectangle.X = bounds.Left + 1;
                focusRect.X         = dropDownRectangle.Right;
                if (drawSplitLine && renderer == null)
                {
                    // draw two lines at the edge of the dropdown button
                    g.DrawLine(SystemPens.ButtonShadow, bounds.Left + PushButtonWidth, BorderSize, bounds.Left + PushButtonWidth, bounds.Bottom - BorderSize);
                    g.DrawLine(SystemPens.ButtonFace, bounds.Left + PushButtonWidth + 1, BorderSize, bounds.Left + PushButtonWidth + 1, bounds.Bottom - BorderSize);
                }
            }
            else
            {
                if (drawSplitLine && renderer == null)
                {
                    // draw two lines at the edge of the dropdown button
                    g.DrawLine(SystemPens.ButtonShadow, bounds.Right - PushButtonWidth, BorderSize, bounds.Right - PushButtonWidth, bounds.Bottom - BorderSize);
                    g.DrawLine(SystemPens.ButtonFace, bounds.Right - PushButtonWidth - 1, BorderSize, bounds.Right - PushButtonWidth - 1, bounds.Bottom - BorderSize);
                }
            }

            // Draw an arrow in the correct location
            PaintArrow(g, dropDownRectangle, renderer == null ? SystemBrushes.ControlText : SystemBrushes.HighlightText);

            // Paint as normal if we don't have a renderer
            if (renderer == null)
            {
                // Figure out how to draw the text
                TextFormatFlags formatFlags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter;

                // If we dont' use mnemonic, set formatFlag to NoPrefix as this will show ampersand.
                if (!UseMnemonic)
                {
                    formatFlags = formatFlags | TextFormatFlags.NoPrefix;
                }
                else if (!ShowKeyboardCues)
                {
                    formatFlags = formatFlags | TextFormatFlags.HidePrefix;
                }

                if (!string.IsNullOrEmpty(this.Text))
                {
                    TextRenderer.DrawText(g, Text, Font, focusRect, SystemColors.ControlText, formatFlags);
                }

                // Draw the focus rectangle.
                if (State != PushButtonState.Pressed && Focused)
                {
                    ControlPaint.DrawFocusRectangle(g, focusRect);
                }
            }
        }
        /// <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)
        {
            System.Diagnostics.Debug.WriteLine($"PaintButton: desMode:{this.IsDesignMode()};vsEnabled:{Application.RenderWithVisualStyles};vsOnOS:{VisualStyleInformation.IsSupportedByOS};btnState:{ButtonState};enabled:{Enabled};imgCt:{(ImageList != null ? ImageList.Images.Count : 0)}");

            if (InitializeRenderer())
            {
                if (OnGlass)
                {
                    rnd.DrawGlassBackground(graphics, bounds, bounds);
                }
                else
                {
                    rnd.DrawParentBackground(graphics, bounds, this);
                    rnd.DrawBackground(graphics, bounds);
                }
            }
            else
            {
                if (ImageList != null && ImageList.Images.Count > 0)
                {
                    int idx = (int)ButtonState - 1;
                    if (ImageList.Images.Count == 1)
                    {
                        idx = 0;
                    }
                    else if (ImageList.Images.Count == 2)
                    {
                        idx = ButtonState == PushButtonState.Disabled ? 1 : 0;
                    }
                    else if (ImageList.Images.Count == 3)
                    {
                        idx = ButtonState == PushButtonState.Normal ? 0 : idx - 1;
                    }
                    bool forceDisabled = !Enabled && ImageList.Images.Count == 1;
                    if (OnGlass)
                    {
                        VisualStyleRendererExtension.DrawGlassImage(null, graphics, bounds, ImageList.Images[idx], forceDisabled);
                    }
                    else
                    {
                        if (!Application.RenderWithVisualStyles && VisualStyleInformation.IsSupportedByOS)
                        {
                            System.Drawing.Drawing2D.GraphicsContainer g = graphics.BeginContainer();
                            Rectangle translateRect = bounds;
                            graphics.TranslateTransform(-bounds.Left, -bounds.Top);
                            PaintEventArgs pe = new PaintEventArgs(graphics, translateRect);
                            InvokePaintBackground(Parent, pe);
                            InvokePaint(Parent, pe);
                            graphics.ResetTransform();
                            graphics.EndContainer(g);
                        }
                        else
                        {
                            graphics.Clear(Parent.BackColor);
                        }
                        if (forceDisabled)
                        {
                            ControlPaint.DrawImageDisabled(graphics, ImageList.Images[idx], 0, 0, Color.Transparent);
                        }
                        else
                        {
                            //base.ImageList.Draw(graphics, bounds.X, bounds.Y, bounds.Width, bounds.Height, idx);
                            //VisualStyleRendererExtender.DrawGlassImage(null, graphics, bounds, base.ImageList.Images[idx], forceDisabled); // Not 7
                            graphics.DrawImage(ImageList.Images[idx], bounds, bounds, GraphicsUnit.Pixel); // Works on XP, not 7, with Parent.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 (rnd != null && !this.IsDesignMode() && DesktopWindowManager.IsCompositionEnabled())
                 *                              rnd.DrawGlassIcon(graphics, bounds, this.ImageList, idx);
                 *                      else
                 *                              this.ImageList.Draw(graphics, bounds.X, bounds.Y, bounds.Width, bounds.Height, idx);
                 *              }*/
                // No image so draw standard button
                else
                {
                    ButtonRenderer.DrawParentBackground(graphics, bounds, this);
                    ButtonRenderer.DrawButton(graphics, bounds, ButtonState);
                }
            }

            if (Focused)
            {
                ControlPaint.DrawFocusRectangle(graphics, bounds);
            }
        }
コード例 #30
0
        protected override void OnPaint(PaintEventArgs args)
        {
            try
            {
                var tmpGraphics = args.Graphics;
                if (tmpGraphics == null)
                {
                    base.OnPaint(args); return;
                }

                int normPosition = position - minimum, normMaximum = maximum - minimum;
                if (normMaximum <= 0)
                {
                    normMaximum = 100;
                    System.Diagnostics.Debug.Assert(false);
                }
                if (normPosition < 0)
                {
                    normPosition = 0;
                    System.Diagnostics.Debug.Assert(false);
                }
                if (normPosition > normMaximum)
                {
                    normPosition = normMaximum;
                }

                Rectangle tmpDrawRectangle, tmpClientRectangle = this.ClientRectangle;

                var tmpStyleElement = VisualStyleElement.ProgressBar.Bar.Normal;
                if (VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(tmpStyleElement))
                {
                    var tmpStyleRenderer = new VisualStyleRenderer(tmpStyleElement);

                    if (tmpStyleRenderer.IsBackgroundPartiallyTransparent( ))
                    {
                        tmpStyleRenderer.DrawParentBackground(tmpGraphics, tmpClientRectangle, this);
                    }
                    tmpStyleRenderer.DrawBackground(tmpGraphics, tmpClientRectangle);
                    tmpDrawRectangle = tmpStyleRenderer.GetBackgroundContentRectangle(tmpGraphics, tmpClientRectangle);
                }
                else
                {
                    tmpGraphics.FillRectangle(SystemBrushes.Control, tmpClientRectangle);

                    var tempGrayPen = System.Drawing.SystemPens.ControlDark;
                    var tmpWhitePen = System.Drawing.SystemPens.ControlLight;
                    tmpGraphics.DrawLine(tempGrayPen, 0, 0, tmpClientRectangle.Width - 1, 0);
                    tmpGraphics.DrawLine(tempGrayPen, 0, 0, 0, tmpClientRectangle.Height - 1);
                    tmpGraphics.DrawLine(tmpWhitePen, tmpClientRectangle.Width - 1, 0, tmpClientRectangle.Width - 1, tmpClientRectangle.Height - 1);
                    tmpGraphics.DrawLine(tmpWhitePen, 0, tmpClientRectangle.Height - 1, tmpClientRectangle.Width - 1, tmpClientRectangle.Height - 1);

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

                int tmpDrawWidth = (int)((float)tmpDrawRectangle.Width * normPosition / normMaximum);

                var tmpStartColor = this.qualityLowColor;
                var tmpEndOfColor = this.qualityHighColor;
                if (!this.Enabled)
                {
                    tmpStartColor = HuiruiSoft.Utils.ColorUtils.ColorToGrayscale(SystemColors.ControlDark);
                    tmpEndOfColor = HuiruiSoft.Utils.ColorUtils.ColorToGrayscale(SystemColors.ControlLight);
                }

                bool tmpRightToLeft = (this.RightToLeft == RightToLeft.Yes);
                if (tmpRightToLeft)
                {
                    var tempColor = tmpStartColor; tmpStartColor = tmpEndOfColor; tmpEndOfColor = tempColor;
                }

                var tmpGradientBounds = new Rectangle(tmpDrawRectangle.X, tmpDrawRectangle.Y, tmpDrawRectangle.Width, tmpDrawRectangle.Height);

                if (!HuiruiSoft.Utils.WindowsUtils.IsAtLeastWindowsVista)
                {
                    tmpGradientBounds.Inflate(1, 0);
                }

                using (var tmpFillBrush = new LinearGradientBrush(tmpGradientBounds, tmpStartColor, tmpEndOfColor, LinearGradientMode.Horizontal))
                {
                    tmpGraphics.FillRectangle(tmpFillBrush, tmpRightToLeft ? (tmpDrawRectangle.Width - tmpDrawWidth + 1) : tmpDrawRectangle.Left, tmpDrawRectangle.Top, tmpDrawWidth, tmpDrawRectangle.Height);
                }

                this.PaintText(tmpGraphics, tmpDrawRectangle, tmpRightToLeft);
            }
            catch (System.Exception)
            {
                System.Diagnostics.Debug.Assert(false);
            }
        }
コード例 #31
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;
                    }
                }
            }
        }
コード例 #32
0
    /// <summary>
    /// Paints the control using the Buffered Paint API.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void bufferedPainter_PaintVisualState(object sender, BufferedPaintEventArgs<ComboBoxState> e)
    {
        if (_drawWithVisualStyles && _bufferedPainter.BufferedPaintSupported && _bufferedPainter.Enabled) {
            // draw in the vista/win7 style
            VisualStyleRenderer r = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal);
            r.DrawParentBackground(e.Graphics, ClientRectangle, this);

            Rectangle buttonBounds = ClientRectangle;
            buttonBounds.Inflate(1, 1);
            ButtonRenderer.DrawButton(e.Graphics, buttonBounds, GetPushButtonState(e.State));

            Rectangle clipBounds = _dropDownButtonBounds;
            clipBounds.Inflate(-2, -2);
            e.Graphics.SetClip(clipBounds);
            ComboBoxRenderer.DrawDropDownButton(e.Graphics, _dropDownButtonBounds, e.State);
            e.Graphics.SetClip(ClientRectangle);
        }
        else if (_drawWithVisualStyles && ComboBoxRenderer.IsSupported) {
            // draw using the visual style renderer
            ComboBoxRenderer.DrawTextBox(e.Graphics, ClientRectangle, GetTextBoxState());
            ComboBoxRenderer.DrawDropDownButton(e.Graphics, _dropDownButtonBounds, e.State);
        }
        else {
            // draw using the legacy technique
            DrawLegacyComboBox(e.Graphics, ClientRectangle, _dropDownButtonBounds, BackColor, GetPlainButtonState());
        }

        OnPaintContent(new DropDownPaintEventArgs(e.Graphics, ClientRectangle, GetTextBoxBounds()));
    }