Purpose of Article
It’s very easy in LightSwitch to display labels associated with data records in your tables. Adding some static text to a label on a screen isn’t so obvious. The following article describes how we can achieve this by using a local property.
- In Solution Explorer, right click on the ‘Screens’ folder and select the option to ‘Add Screen’. Choose the ‘New Data Screen’ template, and select ‘(None)’ on the ‘Screen Data’ dropdown.
- Click on the ‘Add Data Item’ button. Select the ‘Local Property’ radio button and select ‘String’ as the type. Name this property ‘LabelText’.
- By default, a ‘Two Row’ screen is created. On the top row, select the ‘Choose Content’ dropdown and choose ‘New Group’ from the list of available items. By default, a ‘Vertical Stack’ is created. Click on the ‘Add’ dropdown and select ‘LabelText’.
- By default, LabelText is created as a TextBox. Use the dropdown to change this control to a label.
- On the properties of LabelText, set the ‘Label Position’ to ‘None’. We choose not to use the ‘Display Name’ property to display our text becuase by default, LS appends the ‘:’ symbol to the end of the the text.
- Click on the ‘Write Code’ button and select the ‘LabelScreen_Loaded’ event.
- Write the following code to set the label text
Private Sub LabelScreen_Loaded() LabelText = "Unauthorised use of this system constitutes an offence under the Computer Misuse Act 1990" End Sub
Running the Application
Now run the project and open the form. The label text appears on your form as shown in the screenshot below.
Fig 6 – Final screen