/// <summary> Draws the focus on the check box glyph. </summary>
        /// <param name="mgCheckBox"></param>
        /// <param name="graphics"></param>
        public static void DrawFocusRectOnCheckBoxGlyph(MgCheckBox mgCheckBox, Graphics graphics)
        {
            Rectangle focusRectangle  = new Rectangle();
            Rectangle clientRectangle = mgCheckBox.ClientRectangle;
            int       boxWidth        = CheckBoxRenderer.GetGlyphSize(graphics, CheckBoxState.UncheckedNormal).Width;
            int       boxHeight       = CheckBoxRenderer.GetGlyphSize(graphics, CheckBoxState.UncheckedNormal).Height;
            int       left            = mgCheckBox.Padding.Left;
            int       top             = 0;

            //CheckBoxRenderer.GetGlyphSize() always returns the size for 3D style.But, the 2D box is smaller.So, the focus rectangle was too big.
            //There is no way where we can query the size for 2D.Framework has hardcoded the size of the Box as { 11, 11} in CheckBoxFlatAdapter.Layout().
            //So, we also need to hard-code this value. Note that, if framework changes these hard-coded values, we will also need to change them.
            if (mgCheckBox.FlatStyle == FlatStyle.Flat)
            {
                boxWidth = boxHeight = (int)(11f * Utils.GetDpiScaleRatioY(mgCheckBox));
            }

            // calculate the Left based on RightToLeft property.
            // Depends on RightToLeft and NOT Horizontal alignment.
            if (mgCheckBox.RightToLeft == RightToLeft.Yes)
            {
                left = clientRectangle.Width - boxWidth - 1;
            }

            // calculate the Top based on Vertical alignment.
            ControlUtils.AlignmentInfo AlignmentInfo = ControlUtils.GetAlignmentInfo(mgCheckBox.TextAlign);

            switch (AlignmentInfo.VerAlign)
            {
            case AlignmentTypeVert.Top:
                top = 2 + mgCheckBox.Padding.Top;
                break;

            case AlignmentTypeVert.Center:
                top = (clientRectangle.Height - boxHeight) / 2;
                break;

            case AlignmentTypeVert.Bottom:
                top = clientRectangle.Height - boxHeight - 1 - mgCheckBox.Padding.Bottom;
                break;
            }

            focusRectangle.X      = left;
            focusRectangle.Y      = top;
            focusRectangle.Width  = boxWidth;
            focusRectangle.Height = boxHeight;
            focusRectangle.Inflate(1, 1);

            //Ensure that the rectangle is within the control.
            focusRectangle.X      = Math.Max(focusRectangle.X, 0);
            focusRectangle.Y      = Math.Max(focusRectangle.Y, 0);
            focusRectangle.Width  = Math.Min(focusRectangle.Width, clientRectangle.Right - focusRectangle.X);
            focusRectangle.Height = Math.Min(focusRectangle.Height, clientRectangle.Bottom - focusRectangle.Y);

            ControlPaint.DrawFocusRectangle(graphics, focusRectangle);
        }
示例#2
0
 /// <summary>
 /// Set the appearance of CheckBox
 /// </summary>
 public static void SetCheckboxMainStyle(MgCheckBox mgCheckBox, Appearance appearance)
 {
     mgCheckBox.Appearance = appearance;
 }