1.2.3 Adding Custom Button on Dialog
Adding Custom Button on Dialog
The following example shows how to add two custom buttons: the Reset button and the Apply button, to an X-Function dialog, as well as an event1 function to catch what button is being clicked.
- Press F10 to open X-Function Builder. Type "CustomButton" into the X-Function edit box as the X-Function name.
- Click the button to switch to the Tree View panel, and type "Reset|Apply" in the GetN Dialog Custom Buttons edit box. Click Save to save this X-Function.
- Open the X-Function in Code Builder, and put the following code in the CustomButton_event1 function, then click the button.
if( nEventID == GETNE_ON_CUSTOM_BUTTON1 )
if( nEventID == GETNE_ON_APPLY )
if( nEventID == GETNE_ON_OK )
- Run CustomButton -d in the Command window to open the dialog of this X-Function. There should be four buttons: Reset, Apply, OK and Cancel.
- Click the Reset button, and "Reset click" gets printed in the Command window. If you click the Apply button, "Apply click" is printed and the Cancel button is changed to a Close button. Click OK, and "OK click" is printed and the dialog is closed.
Show Preview Button on Graph Preview GetN Dialog
X-Function framework supports a Show Preview button and an Auto Preview check box on the Graph Preview GetN dialog. These two controls are used to update the preview automatically (keep the Auto Preview check box checked) or manually (click the Preview button).
The following steps demonstrate how to add the two controls.
The following five steps illustrate the process to add Preview button controls.
- Press F10 to open X-Function Builder. Type "PreviewButtons" into the X-Function edit box as the X-Function name.
- In the Variables table, set up a variable as below and then click the Save button to save this X-Function.
Data Type: string
- Run the command PreviewButtons -d to open this X-Function dialog. There are only two buttons: OK and Cancel. Click Cancel to close the dialog.
- In X-Function Builder, click the button to switch to the Tree View panel, set Usage Context -> Menus -> Auto GetN Dialog as GetNGraphBox with Preview, and check the Show Preview Button check box. Save this X-Function.
- Run PreviewButtons -d to open the dialog again. Now there are two more controls displayed on the dialog: an Auto Preview check box and a Preview button.
The steps below show how to auto-update the dialog's preview graph according to the selection of the gp variable. For more details about the GetN Graph Preview Dialog, see Creating Graph Preview GetN Dialog.
- Open this X-Function in Code Builder, copy the following code, and paste it into the GetNGraphPreview_OnChange function.
//include the bit to call GetNGraphPreview_OnUpdateGraph to update graph
if( !(dwUpdateGraph & UPDATE_GRAPH_CHANGED) )
dwUpdateGraph |= UPDATE_GRAPH_CHANGED;
- Copy the codes below into the GetNGraphPreview_OnUpdateGraph function.
string strGraph = trGetN.gp.strVal;
- Click the button. Then run PreviewButtons -d in the Command window to open the dialog.
- In the dialog, type the graph page name into the Graph control, or click the button to choose one graph page via the Graph Browser dialog. Click the Auto Preview check box or the Preview button, and the specified graph will display on the preview panel. See the picture below.