Exemplo 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);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///  Renders a Button control.
        /// </summary>
        public static void DrawButton(Graphics g, Rectangle bounds, string buttonText, Font font, TextFormatFlags flags, Image image, Rectangle imageBounds, bool focused, PushButtonState state)
        {
            Rectangle contentBounds;
            Color     textColor;

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

                visualStyleRenderer.DrawBackground(g, bounds);
                visualStyleRenderer.DrawImage(g, imageBounds, image);
                contentBounds = visualStyleRenderer.GetBackgroundContentRectangle(g, bounds);
                textColor     = visualStyleRenderer.GetColor(ColorProperty.TextColor);
            }
            else
            {
                ControlPaint.DrawButton(g, bounds, ConvertToButtonState(state));
                g.DrawImage(image, imageBounds);
                contentBounds = Rectangle.Inflate(bounds, -3, -3);
                textColor     = SystemColors.ControlText;
            }

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

            if (focused)
            {
                ControlPaint.DrawFocusRectangle(g, contentBounds);
            }
        }
 public static void DrawButton(Graphics g, Rectangle bounds, PushButtonState state)
 {
     if (RenderWithVisualStyles)
     {
         InitializeRenderer((int)state);
         visualStyleRenderer.DrawBackground(g, bounds);
     }
     else
     {
         ControlPaint.DrawButton(g, bounds, ConvertToButtonState(state));
     }
 }
Exemplo n.º 4
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));
     }
 }
Exemplo n.º 5
0
        public static void DrawButton(Graphics g, Rectangle bounds, string buttonText, Font font, TextFormatFlags flags, Image image, Rectangle imageBounds, bool focused, PushButtonState state)
        {
            if (Application.RenderWithVisualStyles || always_use_visual_styles == true)
            {
                VisualStyleRenderer vsr = GetPushButtonRenderer(state);

                vsr.DrawBackground(g, bounds);

                if (image != null)
                {
                    vsr.DrawImage(g, imageBounds, image);
                }
            }
            else
            {
                if (state == PushButtonState.Pressed)
                {
                    ControlPaint.DrawButton(g, bounds, ButtonState.Pushed);
                }
                else
                {
                    ControlPaint.DrawButton(g, bounds, ButtonState.Normal);
                }

                if (image != null)
                {
                    g.DrawImage(image, imageBounds);
                }
            }

            Rectangle focus_rect = bounds;

            focus_rect.Inflate(-3, -3);

            if (focused)
            {
                ControlPaint.DrawFocusRectangle(g, focus_rect);
            }

            if (buttonText != String.Empty)
            {
                if (state == PushButtonState.Disabled)
                {
                    TextRenderer.DrawText(g, buttonText, font, focus_rect, SystemColors.GrayText, flags);
                }
                else
                {
                    TextRenderer.DrawText(g, buttonText, font, focus_rect, SystemColors.ControlText, flags);
                }
            }
        }
Exemplo n.º 6
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);
            }
        }
        public static void DrawButton(Graphics g, Rectangle bounds, bool focused, PushButtonState state)
        {
            Rectangle backgroundContentRectangle;

            if (RenderWithVisualStyles)
            {
                InitializeRenderer((int)state);
                visualStyleRenderer.DrawBackground(g, bounds);
                backgroundContentRectangle = visualStyleRenderer.GetBackgroundContentRectangle(g, bounds);
            }
            else
            {
                ControlPaint.DrawButton(g, bounds, ConvertToButtonState(state));
                backgroundContentRectangle = Rectangle.Inflate(bounds, -3, -3);
            }
            if (focused)
            {
                ControlPaint.DrawFocusRectangle(g, backgroundContentRectangle);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        ///  Method to draw visualstyle themes in case of per-monitor scenarios where Hwnd is necessary
        /// </summary>
        /// <param name="g"> graphics object</param>
        /// <param name="bounds"> button bounds</param>
        /// <param name="focused"> is focused?</param>
        /// <param name="state"> state</param>
        /// <param name="handle"> handle to the control</param>
        internal static void DrawButtonForHandle(Graphics g, Rectangle bounds, bool focused, PushButtonState state, IntPtr handle)
        {
            Rectangle contentBounds;

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

                visualStyleRenderer.DrawBackground(g, bounds, handle);
                contentBounds = visualStyleRenderer.GetBackgroundContentRectangle(g, bounds);
            }
            else
            {
                ControlPaint.DrawButton(g, bounds, ConvertToButtonState(state));
                contentBounds = Rectangle.Inflate(bounds, -3, -3);
            }

            if (focused)
            {
                ControlPaint.DrawFocusRectangle(g, contentBounds);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        ///  Renders a Button control.
        /// </summary>
        public static void DrawButton(Graphics g, Rectangle bounds, Image image, Rectangle imageBounds, bool focused, PushButtonState state)
        {
            Rectangle contentBounds;

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

                t_visualStyleRenderer.DrawBackground(g, bounds);
                t_visualStyleRenderer.DrawImage(g, imageBounds, image);
                contentBounds = t_visualStyleRenderer.GetBackgroundContentRectangle(g, bounds);
            }
            else
            {
                ControlPaint.DrawButton(g, bounds, ConvertToButtonState(state));
                g.DrawImage(image, imageBounds);
                contentBounds = Rectangle.Inflate(bounds, -3, -3);
            }

            if (focused)
            {
                ControlPaint.DrawFocusRectangle(g, contentBounds);
            }
        }