Ejemplo n.º 1
0
        internal static void DrawButtonForHandle(
            IDeviceContext deviceContext,
            Rectangle bounds,
            bool focused,
            PushButtonState state,
            IntPtr hwnd)
        {
            Rectangle contentBounds;

            Graphics g = deviceContext.TryGetGraphics(create: true);

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

                using var hdc = new DeviceContextHdcScope(deviceContext);
                t_visualStyleRenderer.DrawBackground(hdc, bounds, hwnd);
                contentBounds = t_visualStyleRenderer.GetBackgroundContentRectangle(hdc, bounds);
            }
            else
            {
                Graphics graphics = deviceContext.TryGetGraphics(create: true);
                ControlPaint.DrawButton(graphics, bounds, ConvertToButtonState(state));
                contentBounds = Rectangle.Inflate(bounds, -3, -3);
            }

            if (focused)
            {
                Graphics graphics = deviceContext.TryGetGraphics(create: true);
                ControlPaint.DrawFocusRectangle(graphics, contentBounds);
            }
        }
Ejemplo n.º 2
0
 internal static void DrawButton(IDeviceContext deviceContext, Rectangle bounds, PushButtonState state)
 {
     if (RenderWithVisualStyles)
     {
         InitializeRenderer((int)state);
         t_visualStyleRenderer.DrawBackground(deviceContext, bounds);
     }
     else
     {
         Graphics graphics = deviceContext.TryGetGraphics(create: true);
         ControlPaint.DrawButton(graphics, bounds, ConvertToButtonState(state));
     }
 }
Ejemplo n.º 3
0
        internal static void DrawButton(
            IDeviceContext deviceContext,
            Rectangle bounds,
            string?buttonText,
            Font?font,
            TextFormatFlags flags,
            Image image,
            Rectangle imageBounds,
            bool focused,
            PushButtonState state)
        {
            Rectangle contentBounds;
            Color     textColor;

            Graphics?graphics = deviceContext.TryGetGraphics(create: true);

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

                t_visualStyleRenderer.DrawBackground(deviceContext, bounds);
                if (graphics is not null)
                {
                    t_visualStyleRenderer.DrawImage(graphics, imageBounds, image);
                }

                contentBounds = t_visualStyleRenderer.GetBackgroundContentRectangle(deviceContext, bounds);
                textColor     = t_visualStyleRenderer.GetColor(ColorProperty.TextColor);
            }
            else
            {
                if (graphics is not null)
                {
                    ControlPaint.DrawButton(graphics, bounds, ConvertToButtonState(state));
                    graphics.DrawImage(image, imageBounds);
                }

                contentBounds = Rectangle.Inflate(bounds, -3, -3);
                textColor     = SystemColors.ControlText;
            }

            TextRenderer.DrawText(deviceContext, buttonText, font, contentBounds, textColor, flags);

            if (focused && graphics is not null)
            {
                ControlPaint.DrawFocusRectangle(graphics, contentBounds);
            }
        }