Esempio n. 1
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);

            if (Application.RenderWithVisualStyles & useComboBoxTheme)
            {
                ComboBoxState cbState = ComboBoxState.Normal;

                if (base.MouseIsDown)
                {
                    cbState = ComboBoxState.Pressed;
                }
                else if (base.MouseIsOver)
                {
                    cbState = ComboBoxState.Hot;
                }

                Rectangle dropDownButtonRect = new Rectangle(0, 0, Width, Height);
                if (cbState == ComboBoxState.Normal)
                {
                    pevent.Graphics.FillRectangle(SystemBrushes.Window, dropDownButtonRect);
                }
                if (!DpiHelper.EnableDpiChangedHighDpiImprovements)
                {
                    ComboBoxRenderer.DrawDropDownButton(pevent.Graphics, dropDownButtonRect, cbState);
                }
                else
                {
                    ComboBoxRenderer.DrawDropDownButtonForHandle(pevent.Graphics, dropDownButtonRect, cbState, this.HandleInternal);
                }

                if (AccessibilityImprovements.Level1)
                {
                    // Redraw focus cues
                    // For consistency with other PropertyGrid buttons, i.e. those opening system dialogs ("..."), that always show visual cues when focused,
                    // we need to do the same for this custom button, painted as ComboBox control part (drop-down).
                    if (Focused)
                    {
                        dropDownButtonRect.Inflate(-1, -1);
                        ControlPaint.DrawFocusRectangle(pevent.Graphics, dropDownButtonRect, ForeColor, BackColor);
                    }
                }
            }
        }
Esempio n. 2
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);

            if (Application.RenderWithVisualStyles & _useComboBoxTheme)
            {
                ComboBoxState state = ComboBoxState.Normal;

                if (MouseIsDown)
                {
                    state = ComboBoxState.Pressed;
                }
                else if (MouseIsOver)
                {
                    state = ComboBoxState.Hot;
                }

                Rectangle dropDownButtonRect = new Rectangle(0, 0, Width, Height);
                if (state == ComboBoxState.Normal)
                {
                    pevent.Graphics.FillRectangle(SystemBrushes.Window, dropDownButtonRect);
                }

                using (var hdc = new DeviceContextHdcScope(pevent))
                {
                    ComboBoxRenderer.DrawDropDownButtonForHandle(
                        hdc,
                        dropDownButtonRect,
                        state,
                        DpiHelper.IsScalingRequirementMet ? HandleInternal : IntPtr.Zero);
                }

                // Redraw focus cues.
                //
                // For consistency with other PropertyGrid buttons, i.e. those opening system dialogs ("..."), that
                // always show visual cues when focused, we need to do the same for this custom button, painted as
                // a ComboBox control part (drop-down).
                if (Focused)
                {
                    dropDownButtonRect.Inflate(-1, -1);
                    ControlPaint.DrawFocusRectangle(pevent.Graphics, dropDownButtonRect, ForeColor, BackColor);
                }
            }
        }