protected override LayoutOptions Layout(PaintEventArgs e)
        {
            LayoutOptions layout = CommonLayout();

            layout.checkPaddingSize    = 1;
            layout.everettButtonCompat = !Application.RenderWithVisualStyles;

            if (Application.RenderWithVisualStyles)
            {
                using var screen = GdiCache.GetScreenHdc();
                layout.checkSize = CheckBoxRenderer.GetGlyphSize(
                    screen,
                    CheckBoxRenderer.ConvertFromButtonState(
                        GetState(),
                        true,
                        Control.MouseIsOver),
                    Control.HandleInternal).Width;
            }
            else
            {
                if (DpiHelper.IsPerMonitorV2Awareness)
                {
                    layout.checkSize = Control.LogicalToDeviceUnits(layout.checkSize);
                }
                else
                {
                    layout.checkSize = (int)(layout.checkSize * GetDpiScaleRatio());
                }
            }

            return(layout);
        }
        public void GraphicsIdentity()
        {
            // https://github.com/dotnet/winforms/issues/3910
            using var hdc             = GdiCache.GetScreenHdc();
            using PaintEventArgs args = new PaintEventArgs(hdc, default);
            Graphics g1 = args.Graphics;
            Graphics g2 = args.Graphics;

            Assert.Same(g1, g2);
        }
Beispiel #3
0
        public void Font_MeasureText(string family, float size, Size proposedSize, uint dt, Size expected)
        {
            using Font font = new Font(family, size);
            if (font.Name != family)
            {
                // Not installed on this machine
                return;
            }

            using var hfont  = GdiCache.GetHFONT(font, Gdi32.QUALITY.CLEARTYPE);
            using var screen = GdiCache.GetScreenHdc();
            Size measure = screen.HDC.MeasureText("Windows Foundation Classes", hfont, proposedSize, (User32.DT)dt);

            Assert.Equal(expected, measure);
        }
Beispiel #4
0
        public void Font_GetTextExtent(string family, float size, int width, int height)
        {
            using Font font = new Font(family, size);
            if (font.Name != family)
            {
                // Not installed on this machine
                return;
            }

            using var hfont  = GdiCache.GetHFONT(font, Gdi32.QUALITY.CLEARTYPE);
            using var screen = GdiCache.GetScreenHdc();
            Size extent = screen.HDC.GetTextExtent("Whizzo Butter", hfont);

            Assert.Equal(width, extent.Width);
            Assert.Equal(height, extent.Height);
        }
Beispiel #5
0
        internal override Size GetPreferredSizeCore(Size proposedSize)
        {
            if (Appearance == Appearance.Button)
            {
                return(ButtonAdapter.GetPreferredSizeCore(proposedSize));
            }

            LayoutOptions options = default;

            using (var screen = GdiCache.GetScreenHdc())
                using (PaintEventArgs pe = new PaintEventArgs(screen, new Rectangle()))
                {
                    options = Layout(pe);
                }

            return(options.GetPreferredSizeCore(proposedSize));
        }
        internal override Size GetPreferredSizeCore(Size proposedSize)
        {
            if (Control.Appearance == Appearance.Button)
            {
                ButtonStandardAdapter adapter = new ButtonStandardAdapter(Control);
                return(adapter.GetPreferredSizeCore(proposedSize));
            }
            else
            {
                LayoutOptions options = default;
                using (var screen = GdiCache.GetScreenHdc())
                    using (PaintEventArgs pe = new PaintEventArgs(screen, new Rectangle()))
                    {
                        options = Layout(pe);
                    }

                return(options.GetPreferredSizeCore(proposedSize));
            }
        }
Beispiel #7
0
        public void Font_AdjustForVerticalAlignment(string family, float size, Rectangle bounds, uint dt, Rectangle expected)
        {
            using Font font = new Font(family, size);
            if (font.Name != family)
            {
                // Not installed on this machine
                return;
            }

            using var hfont         = GdiCache.GetHFONT(font, Gdi32.QUALITY.CLEARTYPE);
            using var screen        = GdiCache.GetScreenHdc();
            using var fontSelection = new Gdi32.SelectObjectScope(screen, hfont.Object);

            User32.DRAWTEXTPARAMS param  = default;
            Rectangle             result = screen.HDC.AdjustForVerticalAlignment(
                "Windows Foundation Classes",
                bounds,
                (User32.DT)dt,
                ref param);

            Assert.Equal(expected, result);
        }
Beispiel #8
0
        protected override LayoutOptions Layout(PaintEventArgs e)
        {
            LayoutOptions layout = CommonLayout();

            layout.HintTextUp            = false;
            layout.DotNetOneButtonCompat = !Application.RenderWithVisualStyles;

            if (Application.RenderWithVisualStyles)
            {
                ButtonBase b = Control;
                using var screen = GdiCache.GetScreenHdc();
                layout.CheckSize = RadioButtonRenderer.GetGlyphSize(
                    screen,
                    RadioButtonRenderer.ConvertFromButtonState(GetState(), b.MouseIsOver),
                    b.HandleInternal).Width;
            }
            else
            {
                layout.CheckSize = (int)(layout.CheckSize * GetDpiScaleRatio());
            }

            return(layout);
        }