如何提高复选框中的WinForms的大小? [英] How to increase the size of checkbox in WinForms?

查看:212
本文介绍了如何提高复选框中的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 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);
    }
}

这篇关于如何提高复选框中的WinForms的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆