只要是js支持的運算均可以支持。html
效果圖:注意,給出的Demo是form版本的,其餘版本大同小異。c#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Eval { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void execBtn_Click(object sender, EventArgs e) { if (!"".Equals(inTxt.Text)) { MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControlClass(); sc.Language = "JavaScript"; string rval = inTxt.Text; rval = rval.Replace("Evaluator_a", val_a.Text); string r = ""; try { r = sc.Eval(rval).ToString(); } catch { MessageBox.Show("計算失敗!"); } rtLst.Items.Add(inTxt.Text + "=" + ("".Equals(r)?"ERR":r)); rtLst.SelectedIndex = rtLst.Items.Count - 1; } else { MessageBox.Show("請輸入公式!"); } } } }