checkbox能否像radiobutton一样,一组只能选一个?
如题。
[解决办法]
好像不能,只能自己判断
[解决办法]
那样的话直接用radiobutton不就更好实现了吗?
不懂~~~~~~
[解决办法]
private void checkBox_CheckedChanged(object sender, EventArgs e){ if ((sender as CheckBox).Checked==true) { foreach (CheckBox chk in (sender as CheckBox).Parent.Controls) { if (chk != sender) chk.Checked = false; } }}
[解决办法]
楼主不喜欢radiobutton的形状吧
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Windows.Forms.VisualStyles;namespace WindowsFormsApplication70{ public partial class Form1 : Form { public Form1() { InitializeComponent(); RadioButtonEx RB1 = new RadioButtonEx(); RB1.Parent = this; RB1.Text = "1111111"; RadioButtonEx RB2 = new RadioButtonEx(); RB2.Parent = this; RB2.Location = new Point(0, 50); RB2.Text = "2222222"; } class RadioButtonEx : RadioButton { protected override void OnPaint(PaintEventArgs pevent) { pevent.Graphics.FillRectangle(new SolidBrush(this.BackColor), pevent.ClipRectangle); CheckBoxRenderer.DrawCheckBox(pevent.Graphics, new Point(0, 0), this.Checked ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal); pevent.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), new PointF(20, 0)); } } }}
[解决办法]