这里为了简单,没有扩展RadioButton实现重用。
- private void radioButton1_Paint(object sender, PaintEventArgs e)
- {
- RadioButton rButton = (RadioButton)sender;
- Graphics g = e.Graphics;
- Rectangle radioButtonrect = new Rectangle(0, 0, 12, 12);
- g.SmoothingMode = SmoothingMode.AntiAlias;//抗锯齿处理
- //圆饼背景
- using (SolidBrush brush = new SolidBrush(Color.White))
- {
- g.FillEllipse(brush, radioButtonrect);
- }
- if (rButton.Checked)
- {
- radioButtonrect.Inflate(-2, -2);//矩形内缩2单位
- g.FillEllipse(Brushes.Red,radioButtonrect);
- radioButtonrect.Inflate(2, 2);//还原
- }
- //圆形边框
- using (Pen pen = new Pen(Color.Red))
- {
- g.DrawEllipse(pen, radioButtonrect);
- }
- }
图片:
本文转自 xcf007 51CTO博客,原文链接:http://blog.51cto.com/xcf007/430407,如需转载请自行联系原作者