On Sun, 26 Apr 2009 12:22:51 pm richard terry wrote: > Is it possible to create/add to a menu at runtime. > > If so, I wonder if anyone could give me an example. > > Regards > > Richard > > --------------------------------------------------------------------------- >--- Crystal Reports - New Free Runtime and 30 Day Trial > Check out the new simplified licensign option that enables unlimited > royalty-free distribution of the report engine for externally facing > server and web deployment. > http://p.sf.net/sfu/businessobjects > _______________________________________________ > Gambas-user mailing list > Gambas-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/gambas-user
Answering myself, but perhaps someone can check this code and see if it is valid, or could improve it. The object was to put a popup menu on the print button in my prescription writer, so that if I didn't want to send the script to the default printer I could right mouse click and get up a list, so this is what I did: Public Sub Editor_SpecialButtons_Menu() Dim menu_item As Menu Dim hObs As Observer Dim Printer_name As String '------------------------------------------ 'Create a new menu on the fly '------------------------------------------ Dim mnuPrinter As New Menu(Me) '----------------------------------------------------------------- 'Only do this at the moment in the script writer 'and only on the print button '----------------------------------------------------------------- Select Case WorkspaceEditor.ActiveWindow.Tag Case "Scripts" Select Case Last.tag 'the buttons Case "print" 'Get list of printers attatched to this machine MyApp.Printers_Get_Available() For Each Printer_name InMyApp.available_printers '-------------------------------------------------- 'make a menu item for each printer '-------------------------------------------------- menu_item = New Menu(mnuPrinter) With menu_item .Caption = Printer_name .Tag = Printer_name .Name = Printer_name hobs = New Observer(menu_item) As "mnuPrinter" End With Next mnuPrinter.Popup() End Select End Select End Public Sub mnuPrinter_Click() Print "in the new menu", Last.tag End This seems to give the desired result, but is the code ok? Regards Richard ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensign option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user