using System; using System.Drawing; using System.Windows.Forms; using System.Text.RegularExpressions; class Program01 : Form { TextBox rBox = new TextBox(); TextBox hBox = new TextBox(); Label rLabel = new Label(); Label hLabel = new Label(); Button szamitButton = new Button(); TextBox resBox = new TextBox(); Program01() { initComponent(); } public void initComponent() { rBox.Location = new Point(120, 10); hBox.Location = new Point(120, 40); rLabel.Location = new Point(10, 10); hLabel.Location = new Point(10, 40); resBox.Location = new Point(120, 80); szamitButton.Location = new Point(10, 80); rLabel.Text = "Sugár"; hLabel.Text = "Magasság"; szamitButton.Text = "Számít"; szamitButton.Click += new EventHandler(SzamitClick); rBox.TextChanged += new EventHandler(rTextChanged); hBox.TextChanged += new EventHandler(hTextChanged); this.Controls.Add(rBox); this.Controls.Add(hBox); this.Controls.Add(rLabel); this.Controls.Add(hLabel); this.Controls.Add(szamitButton); this.Controls.Add(resBox); this.Size = new Size(400, 300); this.Show(); } public void rTextChanged(object sender, EventArgs e) { if(!IsValid(rBox.Text)) { rBox.BackColor = Color.Red; }else { rBox.BackColor = Color.White; } } public void hTextChanged(object sender, EventArgs e) { if(!IsValid(hBox.Text)) { hBox.BackColor = Color.Red; }else { hBox.BackColor = Color.White; } } public bool IsValid(string value) { return Regex.IsMatch(value, @"^[0-9]*$"); } public void SzamitClick(object sender, EventArgs e) { string sugarStr = rBox.Text; string magassagStr = hBox.Text; double sugar = Convert.ToDouble(sugarStr); double magassag = Convert.ToDouble(magassagStr); double terfogat = (1.0/3.0) * Math.Pow(sugar, 2) * Math.PI * magassag; resBox.Text = terfogat.ToString(); } public static void Main() { Application.Run(new Program01()); } }