tags:

views:

38

answers:

2

How do I increase the size of a checkbox in a .Net WinForm. I tried Height and Width but it does not increases the Box size.

+2  A: 

Unfortunately the control doesn't give you any options for this. You will need to paint your own.

Adam
+5  A: 

The check box size is hardcoded inside Windows Forms, you cannot mess with it. One possible workaround is to draw a check box on top of the existing one. It is not a great solution since auto-sizing cannot work anymore as-is and text alignment is muddled, but it is serviceable.

Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form. Adjust the size of the control so you get the desired box size and ensure it is wide enough to fit the text.

using System;
using System.Drawing;
using System.Windows.Forms;

class MyCheckBox : CheckBox {
    public MyCheckBox() {
        this.TextAlign = ContentAlignment.MiddleRight;
    }
    public override bool AutoSize {
        get { return base.AutoSize; }
        set { base.AutoSize = false; }
    }
    protected override void OnPaint(PaintEventArgs e) {
        base.OnPaint(e);
        int h = this.ClientSize.Height - 2;
        Rectangle rc = new Rectangle(new Point(0, 1), new Size(h, h));
        ControlPaint.DrawCheckBox(e.Graphics, rc,
            this.Checked ? ButtonState.Checked : ButtonState.Normal);
    }
}
Hans Passant