Step 3 Add a Pop up Menu to the Status Bar

VLF Windows Application Development

Step 3. Add a Pop-up Menu to the Status Bar

VFW082 – Toolbars, Menus and Pop–up Menus

A Pop-up Menu component can be associated with most of the visual components on a form. A right click on this visual component will then display the "context menu".

You will add date and time fields to the right side of the Status bar and the Pop-up Menu will then control whether the date and time fields are visible.

1.  From the Repository tab, drag and drop the STD_DATEX field into the right hand side of the Status Bar.

2.  Hide its label by changing its MarginLeft property to 0 and then reduce its Width as required..

3.  Add field STD_TIMX to the right hand side of the Status Bar. Hide its label and adjust its width. Your form should now look like the following:

     Hint: If you have difficulty adding the Time field, drop it onto the Status Bar up / down buttons and it will be positioned on the right hand side of the status bar.

4.  Set both the date and time fields ReadOnly property to  true.

5.  In this step you will ensure both the date and time fields have a value.

a.  Add logic to the form's Initialize event routine to set STD_DATEX to current date:

#STD_DATEX := *date

 

b.  Drag and drop a Timer component onto your form. This is a non-visual component. The component definition is:

Define_Com Class(#PRIM_TIMR) Name(#TIMR_1)

 

c.  In the source editor, select the timer component name and use the context menu to create a click event routine.

d.  Add logic to the timer click event to set STD_TIMX to current time:

Evtroutine Handling(#TIMR_1.Tick) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
#STD_TIMX := *time
Endroutine

 

     Note: In this case, there is no need for other code. The standard timer behavior is to fire a click event every second. This is defined by its Interval property of 1,000. Setting the Interval to 0 will stop the timer.

     The Timer also has a Start and Stop method.

6.  Compile and execute your form to check that you are displaying a date and time.

7.  Close your form.

8.  Continue on the Design tab, by dragging and dropping a Pop-up Menu component onto the Status Bar.

     The Pop-up Menu will be shown at the top of the Design tab:

9.  Define two menu items, Show &Date and Show &Time. Create a Click event for the new menu items.

10. In the Design view, select the Status Bar and review its properties. Note that it now has a PopUpMenu property of PMNU_1.

     Date and time are initially visible.

11. On the Design tab, select the Status bar and use the context menu to Edit Pop-Up Menu.

a.  Set both Pop-up Menu items Checked property to True.

b.  Complete the Click event code for the Status Bar Pop-up Menu component, to switch the date and time from Visible = true / false and Menu Item Checked = true / false.

     Your code should look like the following:

Evtroutine Handling(#MITM_16.Click)
#STD_DATEX.visible := *Not #STD_DATEX.visible
#MITM_16.checked := *Not #MITM_16.checked
Endroutine
Evtroutine Handling(#MITM_17.Click)
#STD_TIMX.visible := *Not #STD_TIMX.visible
#MITM_17.checked := *Not #MITM_17.checked
Endroutine

 

12. Compile and test your form.