# How to Create a .NET Calendar Control (NOMADS)

> Source: https://manual.pvxplus.com/how-to/how-to-create-dot-net-calendar-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 MonthCalendar control in NOMADS. You will be adding various properties, such as color and text, and creating an event when a date is selected using the new interface.

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

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

The .NET MonthCalendar 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 MonthCalendar you will be creating.

| **Object/Property** | **Description** |
| --- | --- |
| BackColor | Background color of the calendar. |
| ForeColor | Color of the calendar dates text. |
| TitleBackColor | Background color of the title area of the calendar. |
| TitleForeColor | Color of the title and today's date on the calendar. |
| MaxSelectionCount | Allows a maximum number of days to be selected at the same time. |
| **Event** | **Description** |
| DateSelected | Sets an event to show a message box when the user selects a date or date range from the calendar. |

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

These steps show you how to create a new panel and add a .NET MonthCalendar 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_Calendar**<br>Click *OK*.<br>![](https://manual.pvxplus.com/migration-assets/3ad6ca3d9bf22ccb930e9066f93ffff96ea93d72348a989787172a43d5bfeeb5.png) |
| 2\. | In the NOMADS Panel Designer, select the *External Control* button on the toolbar. Draw an External Control on the panel so that it is an approximate size suitable for the .NET Calendar control.<br>![](https://manual.pvxplus.com/migration-assets/9f2026759b9cd1cbe04fdb3bd87fab6b27b70cc28377342bc18ac173d65578cd.png) |
| 3\. | The **External Control Properties** window is displayed.<br>![](https://manual.pvxplus.com/migration-assets/3d547f7971f56b37bb08bd0be951862d2c107a3f6fc3799a9ff8601f0cba1ebb.jpg) |
| 4\. | In the *Object Name* field, enter the control name or object handle.<br>For this example, enter: **Net_Calendar**<br>![](https://manual.pvxplus.com/migration-assets/d586c7a56d7c7ed3e8fc94a2266070cc06f30d11e038d9e7323e47f8875540e7.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/2aeb7cdd92ad614ffdd01b12028f18ffd998997d933827bb695915bfb41daedf.png) |
| 6\. | Additional fields display for specifying a .NET *DLL Name*, *Object Name* and any optional *Arguments*.<br>![](https://manual.pvxplus.com/migration-assets/3ae8786f0a35206dba9ea3159a86d734262da7fdd1682566cea5dc1fd400f8f7.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/6361d4da48d709163ea766fc1784f09dca8aaf1f9c556129466e143e70290659.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/966c36c58c79efae9fe31cd06c2c1650e394da502fd31785dfc752b50c6dc9e7.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.MonthCalendar**. Click *OK*. To continue with this example, go to **Step 9**.<br>![](https://manual.pvxplus.com/migration-assets/e75ad48ccf84ec5d2f7c5ffd8768593f8fdd7248de5053c2da2f0bc8a8b2f2c2.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/438e90c9d27c91d067bb21b0bbaabb8dbcaaeb2fe5a1b44779740becb1601531.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/8ca4b7f5a454009ee71501904d440369adfdb56a31bc44155226e7b681ca98ef.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/18acd7af57a70f0a3aa2d581051f437dc309be11a045b219525b6cae12493507.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/23278fb1d2a295e86e75931636e6ab26ff852c10fb8dd304560d0ea42da4a95d.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 can be specified and ***must*** be separated by commas.<br>For this example, leave the *Arguments* field blank. |
| 11\. | You can optionally adjust the calendar's **Position** and **Size** coordinates.<br>For this example, enter the following values:<br>```<br>Column = 3.00<br>Line = 1.60<br>Width = 34.00<br>Height = 11.60<br>```<br>![](https://manual.pvxplus.com/migration-assets/0de3040102fdbd8e51b4fd7a99acfb7efea76197ef40533cc9852c8bc2cd49bd.png) |
| 12\. | Click *OK* to save the changes and exit the **External Control Properties** window. |
| 13\. | In the NOMADS Panel Designer, the .NET calendar control is displayed on the panel.<br>![](https://manual.pvxplus.com/migration-assets/0df056299519e3f781693f91e245f16dc5302cf7b8338cd7b042ac6d1e09b402.png) |
| 14\. | Save and test the panel by clicking the *Save* and *Test* buttons on the toolbar.<br>![](https://manual.pvxplus.com/migration-assets/c25e0ceb9fd013f5659820d0922b827baf846d9c05d012c722de53ed6fd479b9.png) |
| 15\. | The .NET calendar will look similar to the one below:<br>![](https://manual.pvxplus.com/migration-assets/90a7f8c7480ddbb7a5b87873dd716ea12d14445b8c40bc7d0266fc0362cf5f94.png) |

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

These steps show you how to set up a default program for the .NET MonthCalendar control 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, click the **Display** tab. Enter the name of the *Default Program*.<br>For this example, enter: **NOM_DOTNET_Calendar**<br>![](https://manual.pvxplus.com/migration-assets/437e9ee78d4563611675b859260a7be05b728b11b64a652d5680edb467d317ea.jpg) |
| 3\. | Leave the header **Panel Definition** window open, as you will enter additional settings later. |

## How to Set the Color and Appearance for the .NET MonthCalendar

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

|  |  |
| --- | --- |
| 1\. | In the header **Panel Definition** window, click the **Logic** tab. In the **Pre-Display** section, you will define a method to be performed prior to the panel being displayed.<br>![](https://manual.pvxplus.com/migration-assets/d34406f542b19015518a156a1019ec616f7bd70ae9b174f6269722b0d8a19771.jpg) |
| 2\. | Select *Perform* from the drop box. Create a method called: **";Pre_Display_Logic"**<br>This method will include the logic where other necessary .NET objects and variables will be defined.<br>![](https://manual.pvxplus.com/migration-assets/35e7f285ef9d20e89748020faa9445709af5ce3cb30f1265a0c29b0c36d1d917.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>In the header **Panel Definition** window, click *OK* to accept the changes and exit the panel definition.<br>***Keep the program editor open as you will be adding to the program later.*** |
| 4\. | To customize the appearance, create three additional objects and insert the three lines shown below.<br>***Object 1:***<br>The **Application** object has methods to start and stop applications and threads, and to process Windows messages. It allows access to the **VisualStyleState** object below.<br>Insert the following line and save the program:<br>def object app,"\[.NET\]System.Windows.Forms,System.Windows.Forms.Application"<br>***Object 2:***<br>The **VisualStyleState** object specifies how visual styles are applied to the current application. The property needed for the calendar style will also be needed in the program.<br>For this example, you will only apply visual styles to the calendar (nonclient area); otherwise, this property will affect all windows controls.<br>Insert the following two lines and save the program:<br>```<br>def object vis,"[.NET]System.Windows.Forms,System.Windows.Forms.VisualStyles.VisualStyleState"<br>app'VisualStyleState=1<br>```<br>***Object 3:***<br>For this example, create a new object for **Color**.<br>Insert the following line and save the program:<br>```<br>def object color,"[.NET]System.Drawing,System.Drawing.Color"<br>```<br>This screenshot shows the new lines you have inserted:<br>![](https://manual.pvxplus.com/migration-assets/25746681e1db0de5cc8d953a54ce3b93b63b5ea9027e92807b4b30fe1b048bd7.png) |
| 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 MonthCalendar 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 *DarkSalmon*.<br>Select the *Exp* check box and enter the *Value/Expression*: **color'DarkSalmon'Pvxhandle$**<br>Click *OK*.<br>![](https://manual.pvxplus.com/migration-assets/23a545b7e6c73c399b05eeb11c9436507f226ad38226227de7fec12c6df230a5.png) |
| 8\. | Save and test the panel. The .NET calendar will look similar to the one below:<br>![](https://manual.pvxplus.com/migration-assets/c925048941117d5c3a8b75d0f2b5c04cfe4c22dd87d548f33e51b0794489f5a0.png) |

## How to Set the Color for the Calendar Dates 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 calendar dates text using the RGB code for the color *Ivory*, which is RGB: 255 255 240.

|  |  |
| --- | --- |
| 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(255,255,240)'Pvxhandle$**<br>Click *OK*.<br>![](https://manual.pvxplus.com/migration-assets/92d0a3309e8a8008d974f882603dbb948d45d38e61f4c4010358755ea178fbac.png) |
| 2\. | Save and test the panel. The calendar will look similar to the one below:<br>![](https://manual.pvxplus.com/migration-assets/f72343cd95f581206c3644cd777888c1c98375406a472ac48a17f8f33a59488a.png) |

## How to Change the Background Color of the Calendar Header

These steps show you how to change the background color of the calendar header.

|  |  |
| --- | --- |
| 1\. | In the **External Control Properties** window, click the **Properties** tab. In the first grid, look for **TitleBackColor** in the *Item* column.<br>For this example, set the color *MediumOrchid*.<br>Select the *Exp* check box and enter the *Value/Expression*: **color'MediumOrchid'Pvxhandle$**<br>Click *OK*.<br>![](https://manual.pvxplus.com/migration-assets/660169f9044ea38867331e7d0c9d56221cd03aac9050555b916fd051747a6acd.png) |
| 2\. | Save and test the panel. The .NET calendar will look similar to the one below:<br>![](https://manual.pvxplus.com/migration-assets/5689a1398cf1ca4fc3e9691588b75a9e5ed8ab3c406b286df9cff8f845692b1d.png) |

## How to Add Date and Selection Properties

These steps show you how to set the maximum number of days that can be selected.

|  |  |
| --- | --- |
| 1\. | In the **External Control Properties** window, click the **Properties** tab. In the first grid, look for **MaxSelectionCount** in the *Item* column.<br>For this example, enter the *Value/Expression*: **20**<br>(Entering a value of 20 will allow the user to select 20 days as the date range.)<br>Click *OK*.<br>![](https://manual.pvxplus.com/migration-assets/ff061a4a1f2544d872fcffed0737b2d8d84f0b7a708250b22fbe35c40b790bbd.png) |
| 2\. | Save and test the panel. The calendar will look similar to the one below where a maximum of 20 days can be selected.<br>![](https://manual.pvxplus.com/migration-assets/6353b490540939cc7f00ac48f4aa3f14fb09ad39c74e8d3e7d87f7873c4ccd80.png) |

## How to Set an Event

These steps show you how to set an event to show a message box when the user selects a date or date range from the calendar, and then display the date or dates selected in the multi-line fields.

For this example, the **DateSelected** event will be triggered when the user selects a date or date range.

|  |  |
| --- | --- |
| 1\. | In the NOMADS Panel Designer, double click on the .NET MonthCalendar 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 **DateSelected** in the *Event* column.<br>In the *Function* column, select *Perform* from the drop box.<br>In the *Logic* cell, enter: **";Date_Selected"**<br>![](https://manual.pvxplus.com/migration-assets/99e9251d880d027530c82717a8f68d84cb3d80b09feceb6bf0c332e56b394ce3.png) |
| 3\. | Return to the program editor and load the default program, **NOM_DOTNET_Calendar**, which you created earlier.<br>Insert this method and save the program:<br>Date_Selected:  <br> fd$=net_calendar.ctl'selectionstart'toString$("dd MMM yyyy")  <br> td$=net_calendar.ctl'selectionend'toString$("dd MMM yyyy")  <br> if fd$\<>td$ then {! fd$>td$ more than 1 date was selected  <br> msgbox "From Date: "+fd$+sep+"To Date: "+td$,"Date Range Selection"  <br> return  <br> }  <br> msgbox "Date Selected: "+fd$,"Date Selection"  <br> return  <br> !<br>![](https://manual.pvxplus.com/migration-assets/d2d7320a5ffadd2597c1f4c6bec1e6251f72b991becd4b5bf7cafb586bcf5c2b.png) |
| 4\. | Click *OK* to save the changes and exit the **External Control Properties** window. |
| 5\. | Save and test the panel. The .NET Calendar will look similar to the one below. Selecting a date range will result in the message box displaying the date range selected.<br>![](https://manual.pvxplus.com/migration-assets/89d343770518063f833a5075ae2e463efebde8f49b780ece209dcfc183089af5.png) |

## How to Display the Dates in "From Date" and "To Date" Multi-Line Fields

These steps show you how to display the selected dates in "From Date" and "To Date" multi-line fields.

For this example, create these two fields and add them below the .NET MonthCalendar control.

|  |  |
| --- | --- |
| 1\. | Expand the height of the Net_Calendar panel so that you have enough space to add the two multi-line fields (as shown below).<br>![](https://manual.pvxplus.com/migration-assets/a0e6420e441e8b25c4110a6fc6e193fea634e2a7bed55b5077342ace5bd7baca.png) |
| 2\. | Create two multi-line fields with the following details:<br>For the name of the first multi-line, enter: **fd** (stands for *From Date*).<br>For the *Initial Value*, enter: **From Date**<br>Click *OK*.<br>![](https://manual.pvxplus.com/migration-assets/4922f9009800e30ca1f8aa206d480f7c3f6984fee50e57ad5d97c9da832f83f6.jpg)<br>For the name of the second multi-line, enter: **td** (stands for *To Date*).<br>For the *Initial Value*, enter: **To Date**<br>Click *OK*.<br>![](https://manual.pvxplus.com/migration-assets/c965494d29e94b9cd86189e42043b6bf64fb04ae3b01e0e8afaa5862ee98962c.jpg) |

***How to Set Up the Attributes for the Panel Header***

These steps show you how to set up attributes for the panel header:

|  |  |
| --- | --- |
| 1\. | In the NOMADS Panel Designer, open the header **Panel Definition** window. |
| 2\. | In the **Panel Definition** window, click the **Attributes** tab. |
| 3\. | Select the *Auto Refresh* check box. By setting this option, changes to the **fd$** or **td$** values will automatically be displayed on the panel without setting REFRESH_FLG=1.<br>![](https://manual.pvxplus.com/migration-assets/da2cabca266b32acf02875fbf4383f9476cc60ebbb0911c2d2d9851628436ecf.png) |
| 4\. | Click *OK* to save these changes and exit the **Panel Definition** window. |

***How to Show/Hide the Multi-Line with a Dependency***

For this example, define a dependency so that when the user selects a range of dates, those dates will show in the multi-line controls. But when the user selects only one date, then only one multi-line will show.

|  |  |
| --- | --- |
| 1\. | In the NOMADS Panel Designer, select *Utilities* > *Dependency Definition* from the menu bar.<br>![](https://manual.pvxplus.com/migration-assets/71864e9fbfbe4996e8490cbd7f4d6e46e03bb3251b8d0acc96df1ed487aa6b92.jpg) |
| 2\. | The **Dependency Definition** window is displayed.<br>In the *Condition* cell, enter: **td$=fd$**<br>The *Invert* check box is automatically selected. Leave this selected to ensure the opposite logic when the condition is false.<br>![](https://manual.pvxplus.com/migration-assets/876af96234a1f54d6cf646f72551f151629f1523772829cf2678388da2ce7ee3.jpg) |
| 3\. | Click the ellipsis button (*three dots*) in the *Actions for Controls* cell. The **Actions for Controls** window is displayed, showing the two control names.<br>In the *Function* column, leave the **fd** control set to *Ignore*. For the **td** control, select *Hide* from the drop down list.<br>![](https://manual.pvxplus.com/migration-assets/d637499789b196b15695d65760f1c67d2cdcb42f6882bfa3a518313d202f1547.png) |
| 4\. | Click *OK* to accept these selections and exit the **Actions for Controls** window. |
| 5\. | You are returned to the **Dependency Definition** window. Click *OK* again. |
| 6\. | Save and test the panel. |
| 7\. | This first example shows selecting a ***date range*** results in the message box displaying the From/To dates selected. The *From Date* and *To Date* fields are populated with these dates.<br>![](https://manual.pvxplus.com/migration-assets/a94f514f87f040478373257edd0f239edda0d17893422672a297789b79afc908.png)<br>This next example shows that selecting a ***single date*** results in the message box displaying the date selected, and the *To Date* field is hidden, since only one date was selected.<br>![](https://manual.pvxplus.com/migration-assets/ac35ff5b24658bb571d809f89eed28bd9983cc9b9f82507fd6dd2a1911f18321.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_Calendar* 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. You will be using the **On Exit** section to perform the cleanup of any objects defined.<br>![](https://manual.pvxplus.com/migration-assets/1424772f8dd751dfb27710a3e41565717ef1314ac5be490943061014c74006de.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. |
| 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_Calendar**.<br>Insert this method and save the program:<br>On_Exit_Logic:  <br> drop object color,err=\*next  <br> drop object app,err=\*next  <br> drop object vis,err=\*next  <br> drop object dateselected,err=\*next  <br> drop object net_calendar,err=\*next  <br>!  <br> end   <br>! |

## PxPlus Program .NET Calendar (NOM_DOTNET_Calendar)

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

```
! dotnet_calendar - .NET calendar nomads

!

Post_Display_Logic:
     def object APP,"[.NET]System.Windows.Forms,System.Windows.Forms.Application"

     def object VIS,"[.NET]System.Windows.Forms,System.Windows.Forms.VisualStyles.VisualStyleState"
     APP'VISUALSTYLESTATE=1 ! Visual styles are applied only to the nonclient area.

     def object COLOR,"[.NET]System.Drawing,System.Drawing.Color"

     return

!
Date_Selected:
     fd$=net_calendar.ctl'selectionstart'toString$("dd MMM yyyy")
     td$=net_calendar.ctl'selectionend'toString$("dd MMM yyyy")
     if fd$<>td$ then {! fd$>td$ more than 1 date was selected

     msgbox "From Date: "+fd$+sep+"To Date: "+td$,"Date Range Selection"

     return

     }
     msgbox "Date Selected: "+fd$,"Date Selection"

     return

!

On_Exit_Logic:
     drop object COLOR,err=*next
     drop object APP,err=*next
     drop object VIS,err=*next
     drop object DATESELECTED,err=*next
     drop object NET_CALENDAR,err=*next
!

     end

!
```

## 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)**
