// 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; namespace DefaultNamespace { public class MainForm : Form { private CheckBox[] chkbox; private Button calc; public MainForm() { InitializeComponent(); } [STAThread] public static void Main(string[] args) { Application.Run(new MainForm()); } private void InitializeComponent() { calc = new Button(); chkbox = new CheckBox[64]; for(int i = 0; i < chkbox.Length; i++) { chkbox[i] = new CheckBox(); } SuspendLayout(); for(int i = 0; i < chkbox.Length; i++) { chkbox[i].Location = new Point(400 - 50 * (i % 8), 225 - 25 * (i / 8)); chkbox[i].Text = "bit " + i; } calc.Location = new Point(50, 300); calc.Size = new Size(400, 25); calc.Text = "Beregn integer fra bits"; calc.Click += new EventHandler(CalcClick); ClientSize = new Size(500, 350); for(int i = 0; i < chkbox.Length; i++) { Controls.Add(chkbox[i]); } Controls.Add(calc); Text = "Main Form"; ResumeLayout(false); } void CalcClick(object sender, EventArgs e) { long res = 0; for(int i = 0; i < chkbox.Length; i++) { res = 2 * res + (chkbox[63-i].Checked ? 1 : 0); } MessageBox.Show("Integer = " + res); } } }