/// <summary> /// Event handler for generate button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GenerateButton_Click(object sender, EventArgs e) { //the following formats the string correctly string temp = (String)InfixTextBox.Text; temp = temp.Trim(); temp = Parse(temp); //format temp = temp.Replace("(", "( "); temp = temp.Replace(")", " )"); temp = RemoveDuplicateSpaces(temp); //fix spacing further temp = temp.Trim(); InfixTextBox.Text = temp; Postfix postfix = new Postfix(temp); try { PostfixTextBox.Text = postfix.Convert(); } catch (Exception err) { MessageBox.Show("Error with expression, check for possible missing parenthesis", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Event handler for index selected changed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void InfixListBox_SelectedIndexChanged(object sender, EventArgs e) { Postfix postfix = new Postfix((String)InfixListBox.SelectedItem); //create new postfix item from item selected InfixTextBox.Text = InfixListBox.SelectedItem.ToString(); //add to textbox try { PostfixTextBox.Text = postfix.Convert(); } catch (Exception err) { MessageBox.Show("Error with expression, check for possible missing parenthesis", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }