how to change the check image on a checkbox

后端 未结 4 1854
耶瑟儿~
耶瑟儿~ 2020-12-06 17:59

it has text, an image, and then the checkbox,

I want to use a better image for the check, but cannot find a way to change the checked and unchecked images



        
4条回答
  •  孤街浪徒
    2020-12-06 18:23

    A simple one :

    overrides check box OnPaint(PaintEventArgs e) as below:

    Graphics g = e.Graphics;
    
            base.OnPaint(e);
            //// Fill the background
            //SetControlSizes();
    
            // Paint the outer rounded rectangle
            g.SmoothingMode = SmoothingMode.AntiAlias;
            using (GraphicsPath outerPath = GeneralUtilities.RoundedRectangle(mLabelRect, 1, 0))
            {
                using (LinearGradientBrush outerBrush = new LinearGradientBrush(mLabelRect,
                       mGradientTop, mGradientBottom, LinearGradientMode.Vertical))
                {
                    g.FillPath(outerBrush, outerPath);
                }
                using (Pen outlinePen = new Pen(mGradientTop, mRectOutlineWidth))
                {
                    outlinePen.Alignment = PenAlignment.Inset;
                    g.DrawPath(outlinePen, outerPath);
                }
            }
    
            //// Paint the gel highlight
            using (GraphicsPath innerPath = GeneralUtilities.RoundedRectangle(mHighlightRect, mRectCornerRadius, mHighlightRectOffset))
            {
                using (LinearGradientBrush innerBrush = new LinearGradientBrush(mHighlightRect,
                       Color.FromArgb(mHighlightAlphaTop, Color.White),
                       Color.FromArgb(mHighlightAlphaBottom, Color.White), LinearGradientMode.Vertical))
                {
                    g.FillPath(innerBrush, innerPath);
                }
            }
            // Paint the text
            TextRenderer.DrawText(g, Text, Font, mLabelRect, Color.White, Color.Transparent,
            TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis);
    

    But if you want to have a good one you have to use wpf CheckBox ControlTemplate Example

提交回复
热议问题