最近有个小需求,就是将checkbox选择框画大一点,网上找了点资料整理了下,代码如下。

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;

namespace WindowsFormsApp11
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.checkBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);


        }
        private void panel1_Paint(object sender, PaintEventArgs e)
        {
           
            if (checkBox1.CheckState == CheckState.Unchecked)
            {
                ControlPaint.DrawCheckBox(e.Graphics, new Rectangle(40,80, 30, 30), ButtonState.Normal);

            }
            else
            {
                ControlPaint.DrawCheckBox(e.Graphics, new Rectangle(40, 80, 30, 30), ButtonState.Checked);

            }

        }
        private void panel2_Paint(object sender, PaintEventArgs e)
        {
            


        }
        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = checkBox1.CheckState.ToString();
        }

        
    }
}

 

posted on 2018-10-22 21:42  xiaoshibushiyue  阅读(406)  评论(0)    收藏  举报