我正在尝试轻松制作自定义复选框。我想通过选中状态在每个复选框的顶部绘制一个图像。如何为所有复选框创建单个事件处理程序?我有很多复选框,我不想为它编写每个事件处理程序:
private void checkbox1_Paint(object sender, PaintEventArgs e)
{
Rectangle rect = new Rectangle(0, 0, 16, 16);
if (checkbox1.Checked)
{
e.Graphics.DrawImage(Properties.Resources.checkbox_checked, rect);
}
else
{
e.Graphics.DrawImage(Properties.Resources.checkbox_unchecked, rect);
}
}
private void checkbox2_Paint(object sender, PaintEventArgs e)
{
Rectangle rect = new Rectangle(0, 0, 16, 16);
if (checkbox2.Checked)
{
e.Graphics.DrawImage(Properties.Resources.checkbox_checked, rect);
}
else
{
e.Graphics.DrawImage(Properties.Resources.checkbox_unchecked, rect);
}
}
// etc...