Флажок предназначен для двухвариантного выбора.
сумма значений выбранных флажков
Form1.cs
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceWindowsFormsApplication1 {-
publicpartialclassForm1 : Form { -
publicForm1() { -
InitializeComponent(); -
} -
privatevoidbutton1_Click(objectsender, EventArgs e) { -
intres = 0; -
if(checkBox1.Checked) { -
res +=int.Parse(checkBox1.Text); -
} -
if(checkBox2.Checked) { -
res +=int.Parse(checkBox2.Text); -
} -
if(checkBox3.Checked) { -
res +=int.Parse(checkBox3.Text); -
} -
if(checkBox4.Checked) { -
res +=int.Parse(checkBox4.Text); -
} -
if(checkBox5.Checked) { -
res +=int.Parse(checkBox5.Text); -
} -
textBox1.Text = res.ToString(); -
} -
} }
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceWindowsFormsApplication1 {-
publicpartialclassForm1 : Form { -
publicForm1() { -
InitializeComponent(); -
} -
privatevoidbutton1_Click(objectsender, EventArgs e) { -
intres = 0; -
if(checkBox1.Checked) { -
res +=int.Parse(checkBox1.Text); -
} -
if(checkBox2.Checked) { -
res +=int.Parse(checkBox2.Text); -
} -
if(checkBox3.Checked) { -
res +=int.Parse(checkBox3.Text); -
} -
if(checkBox4.Checked) { -
res +=int.Parse(checkBox4.Text); -
} -
if(checkBox5.Checked) { -
res +=int.Parse(checkBox5.Text); -
} -
textBox1.Text = res.ToString(); -
} -
} }
активация элемента
Form1.cs
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceWindowsFormsApplication1 {-
publicpartialclassForm1 : Form { -
publicForm1() { -
InitializeComponent(); -
} -
privatevoidcheckBox1_CheckedChanged(objectsender, EventArgs e) { -
if(checkBox1.Checked) { -
textBox1.ReadOnly =false; -
} -
else{ -
textBox1.ReadOnly =true; -
} -
} -
} }
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceWindowsFormsApplication1 {-
publicpartialclassForm1 : Form { -
publicForm1() { -
InitializeComponent(); -
} -
privatevoidcheckBox1_CheckedChanged(objectsender, EventArgs e) { -
if(checkBox1.Checked) { -
textBox1.ReadOnly =false; -
} -
else{ -
textBox1.ReadOnly =true; -
} -
} -
} }