private void btnEvalAt_Click(object sender, EventArgs e) { double fx; string s = InputBoxForm.GetStrInput("Eval at x=", "1.5"); if (s == null || s == "") { return; } if (!double.TryParse(s.Replace(" ", ""), out fx)) { MessageBox.Show("Couldn't parse number."); return; } StringBuilder sbCode = new StringBuilder(); sbCode.AppendLine(this.txtInit.Text); sbCode.AppendLine("double x=" + fx.ToString(CultureInfo.InvariantCulture) + ";"); sbCode.AppendLine("double y;"); sbCode.AppendLine(getUserExpression(this.txtEq1.Text)); //translate one line into code sbCode.AppendLine("ans = y;"); string strError; CodedomEvaluator.CodedomEvaluator cb = new CodedomEvaluator.CodedomEvaluator(); double fOut = cb.mathEval(sbCode.ToString(), new Dictionary <string, double>(), out strError); if (strError != "") { MessageBox.Show(strError); return; } MessageBox.Show("y= " + fOut.ToString()); }
private void btnSetView_Click(object sender, EventArgs e) { double x0, x1, y0, y1; string s = InputBoxForm.GetStrInput("Enter boundaries, separated by commas:", "-10,10,-10,10"); if (s == null || s == "") { return; } string[] ss = s.Split(new char[] { ',' }); if (ss.Length != 4) { MessageBox.Show("Couldn't parse boundaries."); return; } if (!double.TryParse(ss[0].Replace(" ", ""), out x0)) { MessageBox.Show("Couldn't parse boundaries."); return; } if (!double.TryParse(ss[1].Replace(" ", ""), out x1)) { MessageBox.Show("Couldn't parse boundaries."); return; } if (!double.TryParse(ss[2].Replace(" ", ""), out y0)) { MessageBox.Show("Couldn't parse boundaries."); return; } if (!double.TryParse(ss[3].Replace(" ", ""), out y1)) { MessageBox.Show("Couldn't parse boundaries."); return; } this.pointPlotUserControl1.setBounds(x0, x1, y0, y1); this.pointPlotUserControl1.redraw(); }
public static string GetStrInput(string strPrompt, string strCurrent) { InputBoxForm myForm = new InputBoxForm(); myForm.label1.Text = strPrompt; myForm.txtMessage.Text = strCurrent; myForm.ShowDialog(new Form()); if (myForm.DialogResult == DialogResult.OK) { return(myForm.Message); } else { return(null); } }