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 Core.LgMes.Client.LgIntegrationQuery { public partial class DialogFormula : Form { public DataSet _dsSet;//化学成分元素 public string formula = ""; private string ss = "+-*/()"; private frmConfigElementsRow frmConfigEle = new frmConfigElementsRow(); public DialogFormula(frmConfigElementsRow configele) { InitializeComponent(); frmConfigEle = configele; } private void DialogFormula_Load(object sender, EventArgs e) { addContrl(); } /// /// 动态添加控件 /// private void addContrl() { int X = 12; int Y = 46; for (int i = 0; i < _dsSet.Tables[0].Rows.Count; i++) { if ((i + 1) % 10 == 0) { X = 12; Y += 29; } Button toAddButton = new Button(); toAddButton.Name = "Button " + i; toAddButton.Text = _dsSet.Tables[0].Rows[i]["BASENAME"].ToString(); toAddButton.Width = 46; toAddButton.Height = 23; toAddButton.Location = new Point(X, Y); X += 52; // 设置待添加按钮的事件 toAddButton.Click += new System.EventHandler(this.Button_Click); // 把控件添加到窗口中 this.Controls.Add(toAddButton); } } private void Button_Click(object sender, EventArgs e) { Button button = sender as Button; if (textBox1.Text.Length > 0 && ss.IndexOf(textBox1.Text.Substring(textBox1.Text.Length - 1)) < 0 && ss.IndexOf(button.Text) < 0) { MessageBox.Show("请注意,两个元素之间应该有运算符!", "错误"); return; } textBox1.Text += button.Text; } private void button1_Click(object sender, EventArgs e) { if (textBox1.Text.Length > 0) textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 1); } /// /// 添加公式到ListBox中 /// /// /// private void button8_Click(object sender, EventArgs e) { frmConfigEle.textBox1.Text = textBox1.Text; frmConfigEle.checkedListBox1.Items.Add(textBox1.Text, true); } /// /// 检查公式是否合理 /// /// private int checkFormula() { return 0; } } }