不同groupbox中的radioButton互斥
假设有2个groupbox
每个groupbox里有2个radiobutton
怎么实现不同4个radiobutton均互斥?
[解决办法]
每个radiobutton的.
CheckChanged事件里面进行判断.
比如:
- C# code
using System.IO;using System.Drawing.Imaging;using System.Drawing;namespace ControlBean{ public class GetStream : MarshalByRefObject, IGetIMG { public MemoryStream GetImageStream() { CatScreen screen = new CatScreen(); Image img = screen.GetScreenImage(); MemoryStream ms = new MemoryStream(); img.Save(ms, ImageFormat.Jpeg); return ms; } }}
[解决办法]
[解决办法]
不要修改布局
- C# code
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;namespace WindowsFormsApplication71{ public partial class Form1 : Form { List<RadioButton> CheckRadioButtons = new List<RadioButton>(); public Form1() { InitializeComponent(); radioButton1.CheckedChanged += new EventHandler(CheckedChanged); radioButton2.CheckedChanged += new EventHandler(CheckedChanged); radioButton3.CheckedChanged += new EventHandler(CheckedChanged); radioButton4.CheckedChanged += new EventHandler(CheckedChanged); } void CheckedChanged(object sender, EventArgs e) { RadioButton RB = (RadioButton)sender; if (!RB.ContainsFocus) return; if (!CheckRadioButtons.Contains(RB)) CheckRadioButtons.Add(RB); foreach (RadioButton RB2 in CheckRadioButtons) if (RB2 != RB) RB2.Checked = false; } }}