Create Dynamic Shortcut Menus Sample

JavaScript Editor js editor     Web development 



Main Page

File: ...\Samples\Solution\Menus\Dynshort.scx

This sample illustrates an alternative way to create shortcut menus.

The shortcut menus in the Display Shortcut Menus sample were created in the Menu Designer. The advantages of using the Menu Designer are ease of design, the ability to create cascading menus, and simple integration on a form. With the Menu Designer, however, you need a separate .mnx, .mnt, and .mpr file for each shortcut menu. If you make a change, you need to generate and compile the menu code again.

The dynamic shortcut menu engine is a custom class that you can add to any form: menulib in ...\Samples\Classes\Utility.vcx. The ShowMenu method of this class defines a menu and displays it at the MousePointer location as determined by the MROW(В ) and MCOL(В ) functions.

In the RightClick event of the objects you want to create a shortcut menu for, do the following:

  1. Create an array with the shortcut menu items.

  2. Pass the array to the ShowMenu method of the menulib class.

  3. Process the user choice by checking the BAR(В ) value.

For example, the following code is associated with the RightClick event of the form:

В Copy Code
LOCAL laMenu[5]

laMenu=""
laMenu[1]="\<Center"
laMenu[2]="\<Font..."
laMenu[3]="\<Minimize"
laMenu[4]="\-"
laMenu[5]="E\<xit"
THISFORM.oMenuShortcut.ShowMenu(@laMenu)
DO CASE
   CASE BAR()=1
      THISFORM.AutoCenter=.T.
   CASE BAR()=2
      THISFORM.SetFont
   CASE BAR()=3
      THISFORM.WindowState=1
   CASE BAR()=5
      THISFORM.Release
ENDCASE

See Also



JavaScript Editor js editor     Web development