// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Drawing; using System.Windows.Forms; using System.Text; namespace E { public class MainForm : Form { private string[] lbltxt = { "aaa", "bbb", "ccc" }; private Label[] lbl; private CheckBox[] chkbx; private Label result; public MainForm() { InitializeComponent(); } [STAThread] public static void Main(string[] args) { Application.Run(new MainForm()); } private void InitializeComponent() { lbl = new Label[lbltxt.Length]; chkbx = new CheckBox[lbltxt.Length]; for(int i = 0; i < lbltxt.Length; i++) { lbl[i] = new Label(); chkbx[i] = new CheckBox(); } result = new Label(); SuspendLayout(); for(int i = 0; i < lbltxt.Length; i++) { lbl[i].Size = new Size(50, 25); lbl[i].Location = new Point(50, 50 + i * 50); lbl[i].Text = lbltxt[i]; Controls.Add(lbl[i]); chkbx[i].Size = new Size(25, 25); chkbx[i].Location = new Point(125, 50 + i * 50); chkbx[i].CheckedChanged += new EventHandler(Update); Controls.Add(chkbx[i]); } result.Size = new Size(200, 25); result.Location = new Point(50, 100 + lbltxt.Length * 50); result.Text = ""; Controls.Add(result); ClientSize = new Size(300, lbltxt.Length * 50 + 200); Text = "Demo"; ResumeLayout(false); } private void Update(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(""); for(int i = 0; i < chkbx.Length; i++) { if(chkbx[i].Checked) { if(sb.Length > 0) { sb.Append(" "); } sb.Append(lbl[i].Text); } } result.Text = sb.ToString(); } } }