void DrawCheckBox(PaintEventArgs e, LayoutData layout)
        {
            Graphics g = e.Graphics;

            Rectangle check = layout.checkBounds;

            check.X--;      // compensate for Windows drawing slightly offset to right

            ButtonState style = (ButtonState)0;

            if (isChecked)
            {
                style |= ButtonState.Checked;
            }
            else
            {
                style |= ButtonState.Normal;
            }

            if (!Enabled)
            {
                style |= ButtonState.Inactive;
            }

            if (base.MouseIsDown)
            {
                style |= ButtonState.Pushed;
            }

            ControlPaint.DrawRadioButton(g, check, style);
        }
Example #2
0
        internal static void DrawRadioButton(Graphics g, Point glyphLocation, Rectangle textBounds, string radioButtonText, Font font, TextFormatFlags flags, Image image, Rectangle imageBounds, bool focused, RadioButtonState state, IntPtr hWnd)
        {
            Rectangle glyphBounds = new Rectangle(glyphLocation, GetGlyphSize(g, state, hWnd));
            Color     textColor;

            if (RenderWithVisualStyles)
            {
                InitializeRenderer((int)state);

                //Keep this drawing order! It matches default drawing order.
                visualStyleRenderer.DrawImage(g, imageBounds, image);
                visualStyleRenderer.DrawBackground(g, glyphBounds);
                textColor = visualStyleRenderer.GetColor(ColorProperty.TextColor);
            }
            else
            {
                g.DrawImage(image, imageBounds);
                ControlPaint.DrawRadioButton(g, glyphBounds, ConvertToButtonState(state));
                textColor = SystemColors.ControlText;
            }

            TextRenderer.DrawText(g, radioButtonText, font, textBounds, textColor, flags);

            if (focused)
            {
                ControlPaint.DrawFocusRectangle(g, textBounds);
            }
        }
Example #3
0
        /// <include file='doc\RadioButtonRenderer.uex' path='docs/doc[@for="RadioButtonRenderer.DrawRadioButton2"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Renders a RadioButton control.
        ///    </para>
        /// </devdoc>
        public static void DrawRadioButton(Graphics g, Point glyphLocation, Rectangle textBounds, string radioButtonText, Font font, TextFormatFlags flags, bool focused, RadioButtonState state)
        {
            Rectangle glyphBounds = new Rectangle(glyphLocation, GetGlyphSize(g, state));
            Color     textColor;

            if (RenderWithVisualStyles)
            {
                InitializeRenderer((int)state);

                visualStyleRenderer.DrawBackground(g, glyphBounds);
                textColor = visualStyleRenderer.GetColor(ColorProperty.TextColor);
            }
            else
            {
                ControlPaint.DrawRadioButton(g, glyphBounds, ConvertToButtonState(state));
                textColor = SystemColors.ControlText;
            }

            TextRenderer.DrawText(g, radioButtonText, font, textBounds, textColor, flags);

            if (focused)
            {
                ControlPaint.DrawFocusRectangle(g, textBounds);
            }
        }
Example #4
0
        internal static void DrawRadioButton(Graphics g, Point glyphLocation, Rectangle textBounds, string?radioButtonText, Font?font, TextFormatFlags flags, bool focused, RadioButtonState state, IntPtr hWnd)
        {
            Rectangle glyphBounds;

            using (var hdc = new DeviceContextHdcScope(g))
            {
                glyphBounds = new Rectangle(glyphLocation, GetGlyphSize(hdc, state, hWnd));
            }

            Color textColor;

            if (RenderWithVisualStyles)
            {
                InitializeRenderer((int)state);

                t_visualStyleRenderer.DrawBackground(g, glyphBounds);
                textColor = t_visualStyleRenderer.GetColor(ColorProperty.TextColor);
            }
            else
            {
                ControlPaint.DrawRadioButton(g, glyphBounds, ConvertToButtonState(state));
                textColor = SystemColors.ControlText;
            }

            TextRenderer.DrawText(g, radioButtonText, font, textBounds, textColor, flags);

            if (focused)
            {
                ControlPaint.DrawFocusRectangle(g, textBounds);
            }
        }
Example #5
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (e.Index < 0)
            {
                return;
            }
            if (e.Index > this.Items.Count - 1)
            {
                return;
            }

            int size = e.Font.Height; // button size depends on font height, not on item height

            if (IsTransparent && e.State != DrawItemState.Selected)
            {
                e.Graphics.FillRectangle(TransparentBrush, e.Bounds);
            }
            else
            {
                e.DrawBackground();
            }

            Brush       textBrush;
            ButtonState state = ButtonState.Normal;

            if ((e.State & DrawItemState.Disabled) > 0 || (e.State & DrawItemState.Grayed) > 0)
            {
                textBrush = SystemBrushes.GrayText;
                state     = ButtonState.Inactive;
            }
            else if ((e.State & DrawItemState.Selected) > 0 && !Transparent)
            {
                textBrush = SystemBrushes.HighlightText;
            }
            else
            {
                textBrush = SystemBrushes.FromSystemColor(this.ForeColor);
            }
            if ((e.State & DrawItemState.Selected) > 0)
            {
                state |= ButtonState.Checked;
            }

            // Draw radio button
            Rectangle bounds = e.Bounds;

            bounds.Width = size;
            ControlPaint.DrawRadioButton(e.Graphics, bounds, state);

            // Draw text
            bounds = new Rectangle(e.Bounds.X + size + 2, e.Bounds.Y, e.Bounds.Width - size - 2, e.Bounds.Height);
            e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, textBrush, bounds, this.Align);

            // If the ListBox has focus, draw a focus rectangle around the selected item.
            e.DrawFocusRectangle();
        }
Example #6
0
        public static void DrawRadioButton(Graphics g, Point glyphLocation, RadioButtonState state)
        {
            Rectangle bounds = new Rectangle(glyphLocation, GetGlyphSize(g, state));

            if (RenderWithVisualStyles)
            {
                InitializeRenderer((int)state);
                visualStyleRenderer.DrawBackground(g, bounds);
            }
            else
            {
                ControlPaint.DrawRadioButton(g, bounds, ConvertToButtonState(state));
            }
        }
        internal static void DrawRadioButton(Graphics g, Point glyphLocation, RadioButtonState state, IntPtr hWnd)
        {
            Rectangle glyphBounds;

            if (RenderWithVisualStyles)
            {
                InitializeRenderer((int)state);
                using var hdc = new DeviceContextHdcScope(g);
                glyphBounds   = new Rectangle(glyphLocation, GetGlyphSize(hdc, state, hWnd));
                t_visualStyleRenderer.DrawBackground(hdc, glyphBounds, hWnd);
            }
            else
            {
                using (var hdc = new DeviceContextHdcScope(g))
                {
                    glyphBounds = new Rectangle(glyphLocation, GetGlyphSize(hdc, state, hWnd));
                }
                ControlPaint.DrawRadioButton(g, glyphBounds, ConvertToButtonState(state));
            }
        }
Example #8
0
        internal static void DrawRadioButton(
            Graphics graphics,
            Point glyphLocation,
            RadioButtonState state,
            IntPtr hWnd)
        {
            Rectangle glyphBounds;

            if (RenderWithVisualStyles)
            {
                using var hdc = new DeviceContextHdcScope(graphics);
                DrawRadioButtonWithVisualStyles(hdc, glyphLocation, state, hWnd);
            }
            else
            {
                using (var hdc = new DeviceContextHdcScope(graphics))
                {
                    glyphBounds = new Rectangle(glyphLocation, GetGlyphSize(hdc, state, hWnd));
                }
                ControlPaint.DrawRadioButton(graphics, glyphBounds, ConvertToButtonState(state));
            }
        }
Example #9
0
        public static void DrawRadioButton(Graphics g, Point glyphLocation, Rectangle textBounds, string radioButtonText, Font font, TextFormatFlags flags, Image image, Rectangle imageBounds, bool focused, RadioButtonState state)
        {
            Rectangle bounds = new Rectangle(glyphLocation, GetGlyphSize(g, state));

            if (Application.RenderWithVisualStyles || always_use_visual_styles == true)
            {
                VisualStyleRenderer vsr = GetRadioButtonRenderer(state);

                vsr.DrawBackground(g, bounds);

                if (image != null)
                {
                    vsr.DrawImage(g, imageBounds, image);
                }

                if (focused)
                {
                    ControlPaint.DrawFocusRectangle(g, textBounds);
                }

                if (radioButtonText != String.Empty)
                {
                    if (state == RadioButtonState.CheckedDisabled || state == RadioButtonState.UncheckedDisabled)
                    {
                        TextRenderer.DrawText(g, radioButtonText, font, textBounds, SystemColors.GrayText, flags);
                    }
                    else
                    {
                        TextRenderer.DrawText(g, radioButtonText, font, textBounds, SystemColors.ControlText, flags);
                    }
                }
            }
            else
            {
                switch (state)
                {
                case RadioButtonState.CheckedDisabled:
                    ControlPaint.DrawRadioButton(g, bounds, ButtonState.Inactive | ButtonState.Checked);
                    break;

                case RadioButtonState.CheckedHot:
                case RadioButtonState.CheckedNormal:
                    ControlPaint.DrawRadioButton(g, bounds, ButtonState.Checked);
                    break;

                case RadioButtonState.CheckedPressed:
                    ControlPaint.DrawRadioButton(g, bounds, ButtonState.Pushed | ButtonState.Checked);
                    break;

                case RadioButtonState.UncheckedDisabled:
                case RadioButtonState.UncheckedPressed:
                    ControlPaint.DrawRadioButton(g, bounds, ButtonState.Inactive);
                    break;

                case RadioButtonState.UncheckedHot:
                case RadioButtonState.UncheckedNormal:
                    ControlPaint.DrawRadioButton(g, bounds, ButtonState.Normal);
                    break;
                }

                if (image != null)
                {
                    g.DrawImage(image, imageBounds);
                }

                if (focused)
                {
                    ControlPaint.DrawFocusRectangle(g, textBounds);
                }

                if (radioButtonText != String.Empty)
                {
                    TextRenderer.DrawText(g, radioButtonText, font, textBounds, SystemColors.ControlText, flags);
                }
            }
        }