# How to Display a Date in a PxPlus Multi-Line from a NOMADS .NET Calendar

> Source: https://manual.pvxplus.com/how-to/how-to-display-date-in-mline

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.

.NET External controls can also be incorporated into NOMADS panel functionality without creating them as External controls directly on the panel.

For this example, you will be adding a .NET Calendar query button to an existing locked NOMADS multi-line control. Selecting a date from the calendar will populate the multi-line with the date selected.

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

***NOMADS Panel Setup***

You will first need to create a new NOMADS panel with a multi-line control.

|  |  |
| --- | --- |
| 1\. | Create a new NOMADS panel. To launch the NOMADS Panel Designer, select the **[Panel Definition](https://manual.pvxplus.com/nomads-graphical-application/nomads-development/panel-def-ide)** task on the IDE Main Launcher, or open the **Library Object Selection** window and click the *Panel* toolbar button or select *Objects* > *Panel Object* from the menu bar.<br>For this example, enter the panel name: **CalendarDemo** |
| 2\. | Create a **[Fonted Text](https://manual.pvxplus.com/nomads-graphical-application/creating-panel-controls/text-control/text)** control at *Line* 1, *Column* 5.<br>In the **Fonted Text Properties** window, in the **Text** section, leave the drop box as *Fixed*. In the input field beside the drop box, enter: **Invoice Date:**<br>![](https://manual.pvxplus.com/migration-assets/4a95ba5ab4b1c40626c82daa5037442a7973cdde104244430124466426c65b94.png) |
| 3\. | Create a **[Multi-line](https://manual.pvxplus.com/nomads-graphical-application/creating-panel-controls/multi-line-control/overview)** control at *Line* 1, *Column* 17 with a *Height* of 1.<br>In the **Multi-Line Properties** window, in the *Name* field, enter: **ML_Date**<br>![](https://manual.pvxplus.com/migration-assets/facdf852ce7936cd55cc69d82854d08d031443e898b03ecceeebbef5539061f4.png)<br>The position of this control becomes important later with respect to the coordinates used when defining the .NET Calendar object.<br>With the multi-line control in this position, the .NET control may be positioned at Line 2, Column 16 so that it displays just below the multi-line. |
| 4\. | Your controls will look similar to the controls below:<br>![](https://manual.pvxplus.com/migration-assets/92ef491584908dcfc2d0c7415861e3803bafceffff12044e529d1aa1457f719f.png) |

## How to Add the .NET Calendar as an Embedded Query Button

These steps show you how to add the .NET calendar as an embedded query button to the multi-line control.

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

|  |  |
| --- | --- |
| 1\. | In the NOMADS Panel Designer, double click on the **ML_Date** multi-line control on the panel to invoke the **Multi-Line Properties** window.<br>Click the **Query** tab. In the **Query Type** section, select the *Query Program* radio button.<br>![](https://manual.pvxplus.com/migration-assets/746db5d0afe390a9918a3ea683b943672b075be5099c7be1b5f6db43ee81a1cc.png) |
| 2\. | In the **Query Program** section, leave the drop box set to *Fixed*. In the input field beside the drop box, enter the program to be run to display the .NET MonthCalendar.<br>For this example, enter the program: **NOM_DOTNET_Demo**<br>![](https://manual.pvxplus.com/migration-assets/6977cb0c06a7ad9a44f55bf0eb50ce449e42a5c3cc27d6fe642f354dba6da3b6.jpg) |
| 3\. | The **Query Button Options** section automatically becomes enabled after entering the **Query Program**.<br>In the **Query Button Options** section, you need to define the query bitmap by assigning a *Bitmap Image*, defining the *Width* and selecting some *Attributes*.<br>For this example, define these options:<br>*Bitmap Image:* Leave the drop box set to *Fixed*. In the input field beside the drop box, enter: **!16X16/Time/Calendar_View_Day**<br>*Width:* Enter: **3.00**<br>*Attributes:* Select the *Embedded* check box and the *Flat - No Border* check box.<br>![](https://manual.pvxplus.com/migration-assets/c6dc26cdd6e5d5e27556e664a6f7a6aa5641c25335a2eb75536cd3b528840745.png) |

## How to Set Up the Attributes for the Multi-line

Note:  
For this example, the user can only select from the calendar. A date cannot be entered manually.

|  |  |
| --- | --- |
| 1\. | In the **Multi-Line Properties** window, click the **Attributes** tab.<br>Select the *PermaLock/Query Input* check box.<br>Select the *Signal On Exit* check box.<br>![](https://manual.pvxplus.com/migration-assets/11939da13fa28c41e8342c8080d8c2827a0debc7998db9925e0bd4a494d4ee0f.jpg)<br>The **[PermaLock/Query Input](https://manual.pvxplus.com/nomads-graphical-application/creating-panel-controls/multi-line-control/multi-line-properties#attributes)** attribute is required if the user will be getting the date from the calendar only without having the option to manually enter a date in the multi-line. This is not required if the date allows for manual entry. The user will not be able to type inside the ML_Date field.<br>The **[Signal On Exit](https://manual.pvxplus.com/nomads-graphical-application/creating-panel-controls/multi-line-control/multi-line-properties#attributes)** attribute controls whether a 'Change' signal will be generated when the control is exited, regardless of whether the control's value changes.<br>For this example, the *Signal On Exit* flag will be set so that when focus leaves the multi-line, the **On Change** logic is invoked to handle a situation where nothing is selected from the calendar.<br>See **[How to Remove the Calendar without Making a Selection](https://manual.pvxplus.com/how-to/how-to-display-date-in-mline)** below. |
| 2\. | Click *OK* to accept these changes and exit the **Multi Line Properties** window. |

## Getting the Query Program Started

These steps show you how to create the Query program.

|  |  |
| --- | --- |
| 1\. | For this example, open the \*IT Program Editor from the PxPlus IDE. Create the Query program with this name: **NOM_DOTNET_Demo** |
| 2\. | To begin, define the calendar object.<br>***Syntax*:**<br>def object Net_Calendar,@(16,2,33,12),"\[.NET\]System.Windows.Forms,System.Windows.Forms.MonthCalendar" |
| 3\. | To force the maximum number of days that can be selected, set **MaxSelectionCount**=1. (The default Calendar behavior is to allow a 7-day date range selection.)<br>Add the line of code shown below.<br>***Syntax:***<br>Net_Calendar'**MaxSelectionCount**=1 |
| 4\. | Add the **END** command to end the program.<br>![](https://manual.pvxplus.com/migration-assets/67421578249492e8fd8f09031864467c59e61fb762a467376991a44f3e6be617.jpg) |
| 5\. | Save this program. |
| 6\. | Save and Test the NOMADS panel. Clicking the calendar query button should display a calendar similar to the one below.<br>The current date should be selected. Click the **X** in the top right corner of the panel to exit Test mode.<br>![](https://manual.pvxplus.com/migration-assets/b7a088119b9c93c6d3e8fc766b3d4a337553b540e401c76d1af15e9a811a926f.png) |

## How to Apply a Behavior that is to Occur when a Date is Selected

Insert these lines of code in the **NOM_DOTNET_Demo** program and save the program:

```
DATE_SELECTION:
ml_date$=net_calendar'selectionstart'tostring$("dd MMM yyyy")
!

gosub DROP_CALENDAR_OBJECTS
refresh_flg=1
return
!
DROP_CALENDAR_OBJECTS:
drop object net_calendar
net_calendar=0

return
!
```

![](https://manual.pvxplus.com/migration-assets/49e18f42a67b1e47c3e86bbde2d7431fc1824824f09bc4945d7907b79e4e3459.jpg)

## How to Set Up the Defined User CTL Value

This CTL value is required when the user selects the date from the calendar. See **[User-Defined CTLS](https://manual.pvxplus.com/nomads-graphical-application/panel-designer/options-and-utilities/user-defined-ctls)**.

|  |  |
| --- | --- |
| 1\. | The **ON EVENT** syntax below places a CTL value into the input queue.<br>Insert this line in the **NOM_DOTNET_Demo** program after the **DEF OBJECT** command:<br>on event "DateSelected" from Net_Calendar preinput -1042 |
| 2\. | Save the program in the editor.<br>![](https://manual.pvxplus.com/migration-assets/641ac7ff818368abc3a2c0d38db4cad6f6e06f0ef585d82faf32fb1fde623abd.png) |
| 3\. | In the NOMADS Panel Designer, open the **CalendarDemo** panel. Select *Utilities* > *User CTLS* from the menu bar.<br>![](https://manual.pvxplus.com/migration-assets/c55ea4040de05f0b107e7c089726ca2219c68c06da766975fd0449b572d12cf3.jpg) |
| 4\. | The **User Defined CTL Values** window opens.<br>Set the CTL value to use when the date is selected from the calendar. This value must be any other value that is not listed in the *CTL Value* drop box.<br>Enter the *CTL Value* used for this example: **-1042** |
| 5\. | In the *Process* column, *Perform* is automatically selected. |
| 6\. | In the *Logic* column, enter: **"NOM_DOTNET_Demo;Date_Selection"**<br>![](https://manual.pvxplus.com/migration-assets/332806c8942cd0e2150f1ef01168255a976d50a0774b323bf8c9682abdbe8ac6.png)<br>This option results in control being transferred to the **Date_Selection** method in the **NOM_DOTNET_Demo** program when a date is selected. |
| 7\. | Click *OK* to accept this change and exit the **User Defined CTL Values** window. |
| 8\. | Save and Test the panel. Selecting a date will result in the multi-line displaying the date selected.<br>![](https://manual.pvxplus.com/migration-assets/70da87e3060889ba5179960c9e1ab8cc0bf51fb672e8a7814b0e1e9a851fc4d2.png) |

## How to Pre-populate .NET Calendar with an Existing Date in the Multi-line Control

Once a date is selected from the calendar and the multi-line is populated, clicking the calendar query button again should pre-populate the calendar with that date.

|  |  |
| --- | --- |
| 1\. | Insert the lines of code shown below immediately after defining the object for MonthCalendar.<br>Insert these lines immediately after the **DEF OBJECT** command and save the program:<br>if ml_date$\<>"" \\  <br> then \\  <br> {   <br> def object datetime,"\[.NET\]System.Runtime,System.DateTime"   <br> net_calendar'setdate(datetime'parse(ml_date$)'pvxhandle$)  <br> }  <br>! |
| 2\. | Insert this line into the **DROP_CALENDAR_OBJECTS** method and save the program:<br>drop object datetime,err=\*next<br>![](https://manual.pvxplus.com/migration-assets/c7122b2088c46a879c6c66e71e4cfc77740b5c536a49e1f5fd1a3b5c856ea667.jpg) |
| 3\. | Test the panel. Once an initial date is selected, recalling the calendar should display that date rather than today's date.<br>![](https://manual.pvxplus.com/migration-assets/d008dcc794ec5239ee804733b4a979cfa6248a2c3b8fb8794a0f64973f0d213d.png) |

## How to Remove the Calendar without Making a Selection

To address the situation where the calendar is displayed and the user clicks outside the calendar, you will be creating a **CALENDAR_CLEANUP** method.

|  |  |
| --- | --- |
| 1\. | Insert these lines after the **DATE_SELECTION** method and save the program in the editor:<br>```<br>CALENDAR_CLEANUP:<br>     set_focus read date_id ! reads the current control<br>     if date_id<>net_calendar \<br>      then gosub DROP_CALENDAR_OBJECTS<br>     return <br>!<br>```<br>![](https://manual.pvxplus.com/migration-assets/60f43042485c4730c582e03a309e13c4115875c3a39a5f6af416e2fef91dc9e4.jpg) |
| 2\. | Return to NOMADS to the **CalendarDemo** panel. |
| 3\. | Double click on the **ML_Date** multi-line control on this panel to invoke the **Multi-Line Properties** window. |
| 4\. | Click the **Logic** tab. In the **On Change** section, select *Perform* from the drop box.<br>For the method to be performed, enter: **"NOM_DOTNET_Demo;Calendar_Cleanup"**<br>Because the *Signal On Exit* check box (on the **Attributes** tab) has been selected for the **ML_Date** control, this method will drop the .NET objects associated with the calendar control whenever the user clicks outside of the control/calendar.<br>![](https://manual.pvxplus.com/migration-assets/9594761e0684232a1b008f7f043aa519bb4246080de1cb3b86122ebe2ebf1b08.png) |
| 5\. | Save and Test the panel. After clicking the query button, clicking outside the calendar control will also remove the calendar. |

## PxPlus Query Program (NOM_DOTNET_Demo)

At the end of this tutorial example, you should have a working program similar to the one below:

```
!
      def object net_calendar,@(16,2,33,12),"[.NET]System.Windows.Forms,System.Windows.Forms.MonthCalendar"
      net_calendar'maxselectioncount=1

!
      if ml_date$<>"" \
       then \
       {
      def object datetime,"[.NET]System.Runtime,System.DateTime"

      net_calendar'setdate(datetime'parse(ml_date$)'pvxhandle$)
       }
!
      on event "DateSelected" from net_calendar preinput -1042

!
      end
!
DATE_SELECTION:
      ml_date$=net_calendar'selectionstart'tostring$("dd MMM yyyy")
      gosub DROP_CALENDAR_OBJECTS
      refresh_flg=1
      return
!
CALENDAR_CLEANUP:
      set_focus read date_id ! reads the current control
      if date_id<>net_calendar \
       then gosub DROP_CALENDAR_OBJECTS !
      return
!
DROP_CALENDAR_OBJECTS:
      drop object datetime,err=*next
      drop object net_calendar
      net_calendar=0
      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)**
