【发布时间】:2019-08-05 18:03:10
【问题描述】:
我想在 Windows 窗体中设计屏幕上方。当我尝试使用复选框控件时,框的大小没有增加。
我尝试了下面的代码,但复选框颜色和无聊颜色没有改变。
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);
}
}
RadioButton 也尝试过,但我不知道如何应用颜色和突出显示文本。
【问题讨论】:
-
复选框和单选按钮的大小由主题决定。改变你画一个矩形的大小不会改变控件的大小
-
您的图片是否来自网站?不同的技术。 WinForms 使用 CheckBoxRenderer。 ControlPaint 是旧的。
-
当我增加复选框文本大小时,框大小非常小。我必须增加我的复选框大小。
-
我只需要在 windows 窗体中进行设计。我不应该使用任何图像
-
那么您将不得不自己绘制整个东西,因为您有一个非常自定义的规范。