【发布时间】:2021-09-03 04:25:38
【问题描述】:
【问题讨论】:
【问题讨论】:
没有直接的方法。
如果您必须使用 winforms,最简单的方法是模仿按钮并使用图像。
为此,请将您的 CheckBoxes 属性编辑为以下内容。
Normal -> Button
Standard -> Flat
1 -> 0
Control
Overlay -> ImageBeforeText
然后在每个 CheckBox 的事件处理程序 CheckedChanged 中,我们将图像从未选中的框更改为已选中的框,反之亦然,如下所示:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox currentCheckBox = (sender as CheckBox);
if (currentCheckBox.Checked)
{
currentCheckBox.Image = Properties.Resources._checked;
}
else
{
currentCheckBox.Image = Properties.Resources._unchecked;
}
}
或者,更短:
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
(sender as CheckBox).Image = (sender as CheckBox).Checked ? Properties.Resources._checked : Properties.Resources._unchecked;
}
结果应该是这样的: Result
【讨论】: