Beispiel #1
0
        private static Rectangle CreateGlyphButtonTextRectangle(Control control, Size glyphSize)
        {
            //Spacing between the edge of the glyph and the outer edge of the check area.
            //1px padding + 1px for the glyph border.
            const int GLYPH_ADDITIONNAL_SPACE = 2;
            //Some mysterious spacing on the left and right sides of the text.
            const int TEXT_LATTERAL_PADDING = 1;

            Rectangle contentRect   = LayoutAndPaintUtils.InflateRectangle(control.ClientRectangle, control.Padding);
            Size      checkAreaSize = new Size(glyphSize.Width + GLYPH_ADDITIONNAL_SPACE, glyphSize.Height + GLYPH_ADDITIONNAL_SPACE);
            Point     textRectLocation;

            if (control.RightToLeft != RightToLeft.Yes)
            {
                textRectLocation = new Point(contentRect.X + checkAreaSize.Width + TEXT_LATTERAL_PADDING, contentRect.Y);
            }
            else
            {
                textRectLocation = new Point(contentRect.X + TEXT_LATTERAL_PADDING);
            }
            Size      textRectSize = new Size(contentRect.Width - checkAreaSize.Width - 2 * TEXT_LATTERAL_PADDING, contentRect.Height);
            Rectangle textRect     = new Rectangle(textRectLocation, textRectSize);

            return(textRect);
        }
        private static Rectangle CreateGlyphButtonTextRectangle(Control control, Size glyphSize)
        {
            //Spacing between the edge of the glyph and the outer edge of the check area.
            //1px padding + 1px for the glyph border.
            const int glyphAdditionnalSpace = 2;
            //Some mysterious spacing on the left and right sides of the text.
            const int textLatteralPadding = 1;

            Rectangle contentRect      = LayoutAndPaintUtils.InflateRectangle(control.ClientRectangle, control.Padding);
            Size      checkAreaSize    = new Size(glyphSize.Width + glyphAdditionnalSpace, glyphSize.Height + glyphAdditionnalSpace);
            var       textRectLocation =
                control.RightToLeft != RightToLeft.Yes ?
                new Point(contentRect.X + checkAreaSize.Width + textLatteralPadding, contentRect.Y) :
                new Point(contentRect.X + textLatteralPadding);
            Size      textRectSize = new Size(contentRect.Width - checkAreaSize.Width - 2 * textLatteralPadding, contentRect.Height);
            Rectangle textRect     = new Rectangle(textRectLocation, textRectSize);

            return(textRect);
        }
Beispiel #3
0
        public NonClientGraphics(IntPtr hWnd, IntPtr hRgnClip)
        {
            _hWnd = hWnd;

            var flagsDCX = NativeMethods.DCX_WINDOW | NativeMethods.DCX_CACHE | NativeMethods.DCX_CLIPSIBLINGS;

            if (hRgnClip != IntPtr.Zero && hRgnClip != (IntPtr)1)
            {
                //GetDCEx takes ownership of the region, so we give it a copy. This also means that we don't need to delete it afterward.
                _hRgnClip = LayoutAndPaintUtils.CopyHRgn(hRgnClip);
                //Only set this flag if we provide a valid region to GetDCEx. Otherwise, the latter fails and return null.
                flagsDCX |= NativeMethods.DCX_INTERSECTRGN;
            }

            _hDC = NativeMethods.GetDCEx(_hWnd, _hRgnClip, flagsDCX);

            if (_hDC != IntPtr.Zero)
            {
                Graphics = Graphics.FromHdc(_hDC);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Returns a <see cref="TextFormatFlags"/> for the specified button.
        /// </summary>
        /// <param name="btn"></param>
        /// <param name="translatedContentAlign">A <see cref="ContentAlignment"/> value that specifies the
        /// text alignement for the control. Note that this value must be provided already translated for
        /// right-to-left, if desired</param>
        /// <param name="showKeyboardCue"></param>
        /// <returns></returns>
        public static TextFormatFlags CreateTextFormatFlags(ButtonBase btn, ContentAlignment translatedContentAlign, bool showKeyboardCue)
        {
            var flags = BaseTextFormatFlags | LayoutAndPaintUtils.ConvertToTextFormatFlags(translatedContentAlign);

            if (btn.RightToLeft == RightToLeft.Yes)
            {
                flags |= TextFormatFlags.RightToLeft;
            }

            if (!btn.UseMnemonic)
            {
                //Show the ampersand
                flags |= TextFormatFlags.NoPrefix;
            }
            else if (!showKeyboardCue)
            {
                //Hide the cue
                flags |= TextFormatFlags.HidePrefix;
            }

            return(flags);
        }
Beispiel #5
0
 private static Rectangle CreatePushButtonTextRectangle(Control control)
 {
     return(LayoutAndPaintUtils.InflateRectangle(control.ClientRectangle, control.Padding));
 }