如何提高复选框中的WinForms的大小?框中、复选、大小、WinForms

由网友(嘘)分享简介:我如何增加一个复选框在.NET WinForm的大小。我想高度和宽度,但它不会增加盒大小。 How do I increase the size of a checkbox in a .Net WinForm. I tried Height and Width but it does not increases th...

我如何增加一个复选框在.NET WinForm的大小。我想高度和宽度,但它不会增加盒大小。

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.

推荐答案

该复选框尺寸是,Windows窗体硬codeD,你不能惹它。一个可能的解决方法是画一个复选框上的现有的顶部。这不是因为自动调整大小一个很好的解决方案无法继续工作的,是和文本对齐糊涂,但维修。

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.

添加一个新类到您的项目并粘贴下面所示的code。编译。从工具箱顶部的新控件到窗体。调整控件的大小,以便您获得所需的箱体尺寸,并确保它是足够宽,以适应文本。

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);
    }
}
阅读全文

相关推荐

最新文章