private void button1_Click(object sender, EventArgs e) { try { Calculator calculator = client.GetClient(); MatchCollection matches = Regex.Matches(textBox1.Text, "^(\\d+)( *)([+-])( *)(\\d+)$"); if (matches.Count == 1) { GroupCollection groups = matches[0].Groups; int x = Int32.Parse(groups[1].Value); int y = Int32.Parse(groups[5].Value); if (groups[3].Value == "+") { int z = calculator.Add(x, y); textBox2.AppendText(x + " + " + y + " = " + z + Environment.NewLine); } else if (groups[3].Value == "-") { int z = calculator.Subtract(x, y); textBox2.AppendText(x + " - " + y + " = " + z + Environment.NewLine); } else { textBox2.AppendText("error.: " + textBox1.Text); } } } catch (Exception ex) { MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Form1_Load(object sender, EventArgs e) { try { service = new NSingletonWellKnownService <Calculator>(12345); service.Start(); NWellKnownClient <Calculator> client = new NWellKnownClient <Calculator>("127.0.0.1", 12345); Calculator calculator = client.GetClient(); calculator.OnAdded += OnAdded; calculator.OnSubtracted += OnSubtracted; textBox1.AppendText("started." + Environment.NewLine); } catch (Exception ex) { MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }