# How to Create a .NET Button (NOMADS)

> Source: https://manual.pvxplus.com/how-to/how-to-create-dot-net-button-nom

Starting with PxPlus 2025, a **[.NET Interface](https://manual.pvxplus.com/dot-net-interface)** was added to PxPlus that enables the creation of .NET objects in your application.

Important Note:

.NET requires that Windows Desktop Runtime 8 be installed.

For this example, you will be creating a .NET button control in NOMADS. You will be adding various button properties, such as color and text, and creating an event when the button is pressed using the new interface.

![](https://manual.pvxplus.com/migration-assets/9af7e2f79a65ac25bbc236225c5a8dd9ab5dea4c73ab9e5e3882bb5f3d27bf83.png)

***Properties and Event of the .NET Button***

The .NET button is associated with various properties that allow you to customize its appearance and behavior. For this tutorial, you will be shown just a few of the many possibilities that are available when using properties.

This table lists the properties and the event for the .NET button you will be creating.

| **Object/Property** | **Description** |
| --- | --- |
| BackColor | Background color of the button. |
| Enabled | Makes the button available for use or disables it so that it cannot be used. |
| ForeColor | Color of the button text. |
| Image | Adds an image on the button. |
| Text | Adds text on the button. |
| **Event** | **Description** |
| Click | Event triggered by a button click. |

## How to Define the Main Object for the .NET Button

These steps show you how to create a new panel and add a .NET button control.

|  |  |
| --- | --- |
| 1\. | In the **Library Object Selection** window, launch the NOMADS Panel Designer by clicking the *Panel* toolbar button or selecting *Objects* > *Panel Object* in the menu bar.<br>Enter the name of the new panel. For this example, enter: **Net_Button**<br>Click *OK*.<br>![](https://manual.pvxplus.com/migration-assets/554dcbfd1044f51625e549831aa471856815cd94869f419942cb15202584be36.png) |
| 2\. | In the NOMADS Panel Designer, select the *External Control* button on the toolbar. Draw an External Control on the panel.<br>![](https://manual.pvxplus.com/migration-assets/db35278d56195515f689a15d0936f06f380d8cf7d76e0ca4056c8dd74a91e57f.png) |
| 3\. | The **External Control Properties** window is displayed.<br>![](https://manual.pvxplus.com/migration-assets/7c80d5ad0f3dbfd0eaafc459b1652b2b521fef2f3eb3c926e40d172c57012006.jpg) |
| 4\. | In the *Object Name* field, enter the control name or object handle.<br>For this example, enter: **Net_BSave**<br>![](https://manual.pvxplus.com/migration-assets/daf3b596f6b31ab7ad5f3f2f7f1a62e8fb007dd8b01d2ff7ab65de2ae968ab16.png) |
| 5\. | For the *Ext. Control* field, click the Query button. From the list, select the type of External Control you want to create.<br>For this example, select: **.NET Controls**<br>![](https://manual.pvxplus.com/migration-assets/4b9f324deab744445517414091e7de189325ef9c3e4a975e2c3e3c1d80a2db82.png) |
| 6\. | Additional fields display for specifying a .NET *DLL Name*, *Object Name* and any optional *Arguments*.<br>![](https://manual.pvxplus.com/migration-assets/021664d703e1576e4949cde6cf5b735026aef4728f7892e74400c5d1715fdd14.png) |
| 7\. | The *DLL Name* can be defined either as a *Fixed* value or an *Expression*.<br>For this example, define it as a fixed value. Leave the *DLL Name* drop box set to *Fixed*. The remaining fields will be completed later.<br>To define the DLL Name as an expression, you would change the *DLL Name* drop box to *Expression* and then enter the expression in the input field. The expression must evaluate to the correct value while in the NOMADS Panel Designer. |
| 8\. | To define the DLL Name as a fixed value, three methods are available.<br>For this example, use ***Method 1***.<br>***Method 1:***<br>Click the **Browse System DLLs** button.<br>If the button is disabled, make sure that the *DLL Name* drop box is set to *Fixed* and the *DLL Name* input field is empty.<br>![](https://manual.pvxplus.com/migration-assets/a446d049dfcd27b0add55f6c7480422e43ec94cb3eef6e6ab71ba18b9162f17e.png)<br>The **Select a System DLL** window is displayed. Select a system DLL from the list.<br>For this example, select **System.Windows.Forms**. Click *OK*.<br>![](https://manual.pvxplus.com/migration-assets/bed97482915186a459c429d407963281afae5b3ce1c78f87cb1c43ef67608d2f.png)<br>The **Select a System Object** window is displayed automatically. Select a system Object from the list.<br>For this example, select **System.Windows.Forms.Button**. Click *OK*. To continue with this example, go to **Step 9**.<br>![](https://manual.pvxplus.com/migration-assets/2c5ef62ec2d0c63fa66d1a9fecb2705a1958240f613f06f1a493f8cc7c7b4543.png)<br>***OR***<br>***Method 2:***<br>Click the Browse button *(yellow folder icon)* beside the input field to specify the location of the **.dll** file.<br>The *DLL Name* does not require the **.dll** extension.<br>![](https://manual.pvxplus.com/migration-assets/70a92ab8a3071e2ea05c2a756bd47adac7a2c506c075053fe334c3ff05522f4b.png)<br>The **Path to \[.NET\] DLL File** window is displayed, allowing you to browse to or enter the path to the **.dll** file.<br>![](https://manual.pvxplus.com/migration-assets/bbdb3a71ce0518bd4593848466f2c95e9b71ee2ad655e3f4bfafbfd216427b3e.png)<br>***OR***<br>***Method 3:***<br>Enter the name of the .NET DLL directly in the *DLL Name* input field.<br>![](https://manual.pvxplus.com/migration-assets/4dc3db12abbbd6d0ad3849fd640a312086ad8b623861d7a18c6ee93933daa6cf.png) |
| 9\. | In the **External Control Properties** window, the *DLL Name* and *Object Name* fields should now be populated, and the **Browse System DLLs** button should be disabled.<br>![](https://manual.pvxplus.com/migration-assets/5a047eca4a4eaa29561b6cc332bc446912b84aca0bfa355ffcb3f085b5c7066c.png)<br>This example demonstrates how the *Browse System DLLs* button (***Method 1***) simplifies the selection of a system DLL and its associated object.<br>With ***Method 2*** or ***Method 3***, the Object Name must be specified separately, either by clicking the *Object Name* lookup button or entering the Object Name directly in the *Object Name* input field.<br>Note:  <br>.NET object names are *case sensitive*. |
| 10\. | You can optionally pass in arguments when creating .NET objects. These arguments can be strings, numbers, or .NET object handles. See **[PvxHandle$](https://manual.pvxplus.com/directives/def-object#Mark12)**.<br>Multiple numeric or string arguments ***must*** be separated by commas.<br>For this example, leave the *Arguments* field blank. |
| 11\. | You can optionally adjust the button's **Position** and **Size** coordinates.<br>For this example, leave the values unchanged.<br>![](https://manual.pvxplus.com/migration-assets/a7c67338c1adf9f41840762c03e0470631363d1d9e64cc4ddcd857ae8904d0dc.png) |
| 12\. | Click *OK* to save the changes and exit the **External Control Properties** window. |
| 13\. | In the NOMADS Panel Designer, the .NET button control is displayed on the panel.<br>![](https://manual.pvxplus.com/migration-assets/0f935c95f4bc17ad841d37fb0d84a7eee631914a032dacbf6283816e9a9c6eec.png) |
| 14\. | Save and test the panel by clicking the *Save* and *Test* buttons on the toolbar.<br>![](https://manual.pvxplus.com/migration-assets/156614593e2012c37783d3c09904707fba8f2b9a71cc2b462c10b14ebfbcc6e3.png) |
| 15\. | The .NET button will look similar to the one below:<br>![](https://manual.pvxplus.com/migration-assets/2f2c70cc9b8ee900c00d3a7a99c4b55398f42c2ab7a53a9eb875498c1b71d172.png) |

## How to Add Text to the .NET Button

These steps show you how to add text to the .NET button control.

|  |  |
| --- | --- |
| 1\. | In the NOMADS Panel Designer, double click on the .NET button control on the panel to invoke the **External Control Properties** window. |
| 2\. | In the **External Control Properties** window, click the **Properties** tab to specify the properties, methods or events you would like to set.<br>![](https://manual.pvxplus.com/migration-assets/66c2766a78c15f2f11eb04f50fbaba9f655a22e4af4d887a98558fb17285ed05.png) |
| 3\. | For this example, add the text "Save" to the .NET button.<br>Under the **Item** grid column, scroll down the list until you find the word *Text*.<br>On this row, enter the *Value/Expression*: **Save**<br>![](https://manual.pvxplus.com/migration-assets/6f57f28a1a7ad6096423191d2097cf78e11aaa7cb29c332c4762792229b255c1.png) |
| 4\. | Click *OK* to save the changes and exit the **External Control Properties** window. |
| 5\. | Save and test the panel. The .NET button will look similar to the one below:<br>![](https://manual.pvxplus.com/migration-assets/5c71b2efc1bd8e429401edb652f056e8e2c133455c0f58fcbae9c3310829e2d5.png) |

## How to Set Up the Default Program for the .NET Button

These steps show you how to set up a default program for the .NET button in the header **Panel Definition** window.

|  |  |
| --- | --- |
| 1\. | In the NOMADS Panel Designer, click the *Header Panel* option on the toolbar or select *Panel* > *Header* from the menu bar. |
| 2\. | To define the appearance of the control, you will need to create a default program with some logic. This logic will be additional objects or variables that are needed for the properties you will be using in the NOMADS panel.<br>In the header **Panel Definition** window, on the **Display** tab, enter the name of the *Default Program*.<br>For this example, enter: **NOM_DOTNET_Button**<br>![](https://manual.pvxplus.com/migration-assets/24db865947ebce463ae78c5610c8e362775766225e76251bacb11ab48c56e562.png) |
| 3\. | Leave the header **Panel Definition** window open, as you will enter additional settings later. |

## How to Set Color for the .NET Button

These steps show you how to set the color for the .NET button control.

|  |  |
| --- | --- |
| 1\. | In the header **Panel Definition** window, click the **Logic** tab. |
| 2\. | In the **Pre-Display** section, you will define a method in the program where you will set some logic to define the other objects needed for adding appearance.<br>Select *Perform* from the drop box. Create a method called: **";Pre_Display_Logic"**<br>This will perform the method where all the main objects and variables will be defined.<br>![](https://manual.pvxplus.com/migration-assets/a5e23d6f42286c8be1819afba4283a2806ab32fbacf97409673f0c182b062b56.png) |
| 3\. | Click the Program Logic button to the right of the drop box. The default PxPlus program editor will launch and will have created the method.<br>***Keep the program editor open as you will be adding to the program later.*** |
| 4\. | Create a new object for **Color**. Insert the following line and save the program:<br>def object color,"\[.NET\]System.Drawing,System.Drawing.Color"<br>![](https://manual.pvxplus.com/migration-assets/9ef877e4666a00f96ae6250aba2d18509555b24f1e9be1114452896b3cf299aa.jpg) |
| 5\. | Save the program in the editor if you have not already done this. |
| 6\. | In the NOMADS Panel Designer, double click on the .NET button control on the panel to invoke the **External Control Properties** window. |
| 7\. | In the **External Control Properties** window, click the **Properties** tab. In the first grid, look for **BackColor** in the *Item* column.<br>For this example, set the color *PaleGoldenrod*.<br>Select the *Exp* check box and enter the *Value/Expression*: **color'PaleGoldenrod'Pvxhandle$**<br>Click *OK*.<br>![](https://manual.pvxplus.com/migration-assets/1a03188a6a48f9f43405dd9bac2b135bd5bb0d5d0046964c415885f8a916d896.png) |
| 8\. | Save and test the panel. The .NET button will look similar to the one below:<br>![](https://manual.pvxplus.com/migration-assets/23fc445f0e692c0c62a84a423b2abf90f23913b28199f39c7477368a51ca3730.png) |

## How to Set the Color for the .NET Button Text

When setting colors, you also have the option to use RGB colors.

For this example, the steps below show you how to set the color for the button text using the RGB code for the color Crimson, which is RGB: 220 20 60.

|  |  |
| --- | --- |
| 1\. | In the **External Control Properties** window, click the **Properties** tab. In the first grid, look for **ForeColor** in the *Item* column.<br>Select the *Exp* check box and enter the *Value/Expression*: **color'FromArgb(220,20,60)'Pvxhandle$**<br>Click *OK*.<br>![](https://manual.pvxplus.com/migration-assets/ef917e3315b9d2778d2cb0c8aa3f23b5c389ea5fbe3bdfa8b72422ee48fb77e3.png) |
| 2\. | Save and test the panel. The .NET button will look similar to the one below:<br>![](https://manual.pvxplus.com/migration-assets/c31adc0a8f7d9de5a047ceb26e2d4cd0ef16ad49d4d04da423d1b43f4af53ab1.png) |

## How to Add an Image to the .NET Button

These steps show you how to add an image to the .NET button control.

|  |  |
| --- | --- |
| 1\. | Load the default program, **NOM_DOTNET_Button**, which you created earlier.<br>For this example, define another object called **Image**. The **Image** object will allow the placement of an image.<br>Insert the following line and save the program:<br>def object img,"\[.NET\]System.Drawing,System.Drawing.Image"<br>![](https://manual.pvxplus.com/migration-assets/4095b921a359a479344a98acf8fb535fb1acac93dc6350cf16ad14d2652c1e57.jpg) |
| 2\. | Create a variable to hold the path to the image file using the **[PTH()](https://manual.pvxplus.com/functions/pth)** function.<br>For this example, the variable name is called image_path$. The path will depend on the location of the image you will be using.<br>Insert the following line and save the program:<br>image_path$=pth("\*plus\\inomads\\sysimage\\checkmark.png")<br>![](https://manual.pvxplus.com/migration-assets/983d8d6a421bad72636c9f4ff170feaf2c5798c971e3d6d9127cae4da5f24d05.jpg) |
| 3\. | In the NOMADS Panel Designer, double click on the .NET button control on the panel to invoke the **External Control Properties** window. |
| 4\. | In the **External Control Properties** window, click the **Properties** tab. In the first grid, look for **Image** in the *Item* column.<br>Select the *Exp* check box and enter the *Value/Expression*: **img'fromfile(image_path$)'pvxhandle$**. The **FromFile** object will look for the specified image location.<br>The image will default to the center of the text. In the next set of steps, you will change the alignment.<br>Click *OK*.<br>![](https://manual.pvxplus.com/migration-assets/0e53d302b7083db79de7a7866b4f7dc8e8fd0daefb65bb0b5c94f94760f4433e.png) |
| 5\. | Save and test the panel. The .NET button will look similar to the one below:<br>![](https://manual.pvxplus.com/migration-assets/8f870acb67ce03ec9b94296ea72cc8737aaaa3cd8b376cd98a995f0ba62f5b01.png) |

## How to Align an Image on the .NET Button

These steps show you how to align an image on the .NET button control.

|  |  |
| --- | --- |
| 1\. | Load the default program, **NOM_DOTNET_Button**, which you created earlier.<br>For this example, define another object called **ContentAlignment** to control the alignment of an image. Apply the *Left* alignment (the ***default*** is *Centered*).<br>Insert the following line and save the program:<br>def object img_align,"\[.NET\]System.Drawing,System.Drawing.ContentAlignment"<br>![](https://manual.pvxplus.com/migration-assets/911819b2112122763c003ffefda3254dcb09255bc412d18add9cc0e569b30c62.jpg) |
| 2\. | In the NOMADS Panel Designer, double click on the .NET button control on the panel to invoke the **External Control Properties** window. |
| 3\. | In the **External Control Properties** window, click the **Properties** tab. In the first grid, look for **ImageAlign** in the *Item* column.<br>For this example, align the image to the left of the text. The *MiddleLeft* property will be used with the *ImageAlign* property.<br>Select the *Exp* check box and enter the *Value/Expression*:  **img_align'Middleleft'pvxhandle$**<br>Click *OK*.<br>![](https://manual.pvxplus.com/migration-assets/d5b8001a4c5a0c8f788f969e69f69764a68a8ffb1e5b791ab1daa183de3f2ea3.png) |
| 4\. | Save and test the panel. The .NET button will look similar to the one below:<br>![](https://manual.pvxplus.com/migration-assets/b6e6bc555bf9257d1af772852310e073a85ec849f954f3e818fae185f39dafec.png) |

## How to Set an Event

These steps show you how to set an event that shows a message box confirmation when the button is clicked.

For this example, the **Click** event will be triggered when a user clicks the button.

|  |  |
| --- | --- |
| 1\. | In the NOMADS Panel Designer, double click on the .NET button control on the panel to invoke the **External Control Properties** window. |
| 2\. | In the **External Control Properties** window, click the **Properties** tab. In the second grid, look for **Click** in the *Event* column.<br>In the *Function* column, select *Perform* from the drop box<br>In the *Logic* cell, enter: **";Save_Clicked"**<br>![](https://manual.pvxplus.com/migration-assets/41e6bf1ad6b7041c3e00508f98ad06c2525370390017d8fda30281141d76dcd8.png) |
| 3\. | Load the default program, **NOM_DOTNET_Button**, which you created earlier.<br>Insert this method and save the program:<br>```<br>Save_Clicked:<br>     msgbox "Information has been updated!","Save Confirmation"<br>     return<br>```<br>![](https://manual.pvxplus.com/migration-assets/2435d04c100a1de329fafb629c2b59dc116fb976f051d7877b3f3f20e412c8ca.jpg) |
| 4\. | Click *OK* to save the changes and exit the **External Control Properties** window. |
| 5\. | Save and test the panel. In Test mode, click the .NET button. The message box is displayed.<br>![](https://manual.pvxplus.com/migration-assets/87f04642279788ec253b21f0134a94d2a8d50578384f623badcb29721808bd6b.png) |

## Setting Other .NET Button Properties

***How to Enable or Disable the .NET Button***

These steps show you how to enable or disable the .NET button control.

|  |  |
| --- | --- |
| 1\. | In the **Extended Control Properties** window, click the **Properties** tab. In the first grid, look for **Enabled** in the *Item* column.<br>· If the button is to be *Enabled*, leave everything blank or enter 1 in the *Value/Expression* cell.  <br>· If the button is to be *Disabled*, enter 0 (zero) in the *Value/Expression* cell.<br>For this example, enter **0** in the *Value/Expression* cell.<br>Click *OK*.<br>![](https://manual.pvxplus.com/migration-assets/a605bb47b85b6aa0ec4ae8011a289a5760c5e45fa797c09f83ea995f4a4d108c.png) |
| 2\. | Save and test the panel. The .NET button is disabled.<br>![](https://manual.pvxplus.com/migration-assets/2fbd9131954d63c944c2b4676b38595d31e57db6c818f3d7b984c8557d9a802c.png) |

## How to Clean Up Objects

These steps show you how to clean up any objects that were defined.

|  |  |
| --- | --- |
| 1\. | From the NOMADS Panel Designer, invoke the header **Panel Definition** window for the Net_Button panel by clicking the *Header Panel* option on the toolbar or selecting *Panel* > *Header* from the menu bar. |
| 2\. | In the **Panel Definition** window, click the **Logic** tab. In the **On Exit** section, perform the cleanup of any objects defined.<br>![](https://manual.pvxplus.com/migration-assets/c8d844fa26786986832c5fed082c224b5caebcd60c5fa68bbd881179c3f35792.png) |
| 3\. | In the **On Exit** section, select *Perform* from the drop box. Create a method called: **";On_Exit_Logic"**<br>This will perform the method where all the objects will be dropped.<br>![](https://manual.pvxplus.com/migration-assets/11622ac9e7e0d4f457288f194718723636ba2978855d6624e84322153d153619.png) |
| 4\. | If the program is not already loaded in the editor, click the Program Logic button to the right of the drop box to load the default program **NOM_DOTNET_Button**.<br>Insert this method and save the program:<br>```<br>On_Exit_Logic:<br>     drop object color,err=*next<br>     drop object img,err=*next<br>     drop object img_align,err=*next<br>     return<br>```<br>![](https://manual.pvxplus.com/migration-assets/7d424cda32cb062a57ffcb7af6efa75866bf73e77a36dbc17fe2927e5a676486.jpg) |

## PxPlus Program .NET Button (NOM_DOTNET_Button)

After completing this tutorial example, you should have a working program similar to the one below:

```
Pre_Display_Logic:
     def object color,"[.NET]System.Drawing,System.Drawing.Color"
     def object img,"[.NET]System.Drawing,System.Drawing.Image"
     image_path$=pth("*plus\inomads\sysimage\checkmark.png")
     def object img_align,"[.NET]System.Drawing,System.Drawing.ContentAlignment"
     return
!
Save_Clicked:
     msgbox "Information has been updated!","Save Confirmation"
     return
!
On_Exit_Logic:
     drop object color,err=*next
     drop object img,err=*next
     drop object img_align,err=*next
     return
```

## See Also

**[.NET Interface](https://manual.pvxplus.com/dot-net-interface)  
[How To Tutorials (for .NET Interface)](https://manual.pvxplus.com/how-to/dot-net-tutorials-intro)  
[DEF OBJECT Define Windows Object](https://manual.pvxplus.com/directives/def-object)  
[ON EVENT Event Processing](https://manual.pvxplus.com/directives/on-event)**
