Imports Infragistics.Win.UltraWinCalcManager Imports Infragistics.Win.UltraWinCalcManager.FormulaBuilder Imports Infragistics.Win.CalcEngine
The WinCalcManager™ FormulaBuilder can be shown to the user at run-time.
To Show the FomulaBuilder.
Before you start writing any code, you should place using/imports directives in your code-behind so you don’t need to always type out a member’s fully qualified name.
In Visual Basic:
Imports Infragistics.Win.UltraWinCalcManager Imports Infragistics.Win.UltraWinCalcManager.FormulaBuilder Imports Infragistics.Win.CalcEngine
In C#:
using Infragistics.Win.UltraWinCalcManager; using Infragistics.Win.UltraWinCalcManager.FormulaBuilder; using Infragistics.Win.CalcEngine;
Place a UltraCalcManager, three UltraTextEditors, and UltraButton on the form.
Rename the editors to "txtBox1", "txtBox2", and "txtSumBox". In addition, set off each editor’s CalcSettings the PropertyName to Text. If you forget to set the PropertyName to Text your end user will not be able to see any controls in the FormulaBuilderDialog.
Change the UltraButton’s name to be "btnShowFormulaBuilderDialog". Set the Button’s Text property to "Show Formula Builder Dialog".
Add a reference to Infragistics.Win.UltraWinCalcManager.v20.2.FormulaBuilder
In the code behind create a method called ShowFormulaBuilderDialog that passes in a IFormulaProvider.
Inside the ShowFormulaBuilderDialog method declare a new FormulaBuilderDialog, passing in the IForumlaProvider variable that was passed into the ShowFormulaBuilderDialog.
Inside the ShowFormulaBuilderDialog method after you have declared your FormulaBuilderDialog, you’ll need to show the dialog.
Once the dialog is shown we need to test to see if the end user cancels the dialog, and if they do just return from the ShowFormulaBuilderDialog method. If the dialog isn’t cancelled, then we need to take the FormulaBuildDialog’s Formula property and assign it to the passed in IFormulaProvider’s Formula property.
The following example code shows what the previous couple of steps combined code looks like.
In Visual Basic:
Private Sub ShowFormulaBuilderDialog(ByVal formulaProvider As IFormulaProvider) ' Declare a new FormulaBuilderDialog Dim formulaBuilderDialog As New FormulaBuilderDialog(formulaProvider) ' Show the dialog Dim dResult As DialogResult = formulaBuilderDialog.ShowDialog(Me) ' If the user cancelled, do nothing If dResult = System.Windows.Forms.DialogResult.Cancel Then Return End If ' Apply the formula formulaProvider.Formula = formulaBuilderDialog.Formula End Sub
In C#:
private void ShowFormulaBuilderDialog(IFormulaProvider formulaProvider) { // Declare a new FormulaBuilderDialog FormulaBuilderDialog formulaBuilderDialog = new FormulaBuilderDialog(formulaProvider); // Show the dialog DialogResult dResult = formulaBuilderDialog.ShowDialog(this); // If the user cancelled, do nothing if (dResult == System.Windows.Forms.DialogResult.Cancel) return; // Apply the formula formulaProvider.Formula = formulaBuilderDialog.Formula; }
In the designer double click the button to create the button’s click event. Inside the event call the ShowFormulaBuilderDialog method that we created above, passing in the CalcSettings of the txtSumBox control using the GetCalcSettings method of the UltraCalcManager to get the CalcSettings of a control at run-time.
In Visual Basic:
Private Sub btnShowFormulaBuilderDialog_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnShowFormulaBuilderDialog.Click Me.ShowFormulaBuilderDialog(Me.UltraCalcManager1.GetCalcSettings(Me.txtSumBox)) End Sub
In C#:
private void btnShowFormulaBuilderDialog_Click(object sender, System.EventArgs e) { this.ShowFormulaBuilderDialog(this.ultraCalcManager1.GetCalcSettings( this.txtSumBox)); }
Build and run the project. Type numbers into the first two editors, and press the "Show Formula Builder Dialog" button. You should see something similar to the following appear. Put in the calculation you want, and when you click OK, the resulting value will be shown in the third editor.