Using ToolStrips in Visual APL
There have been several questions recently asking how best to implement ToolStrips on Windows Forms in Visual APL.
Legacy []WI implementations have limited support for ToolStrips, and Visual APL has implemented a subset of what []WI systems supported. However, while the legacy ToolStrip support is there, you will have a better and more extensible solution using the new controls directly.
To show how easy it is to experiment with Windows controls in Visual APL, the code below was created by just typing from scratch in the session.
Notice that a.Show() displays the Form. Do not click on the close X while you are playing with this example, as it will dispose of the form and you will have to run the code again from where you created the Form.
Also, If you have the menu displayed as you add and remove items, it will show them being removed and added.
Also again, the refbyname System.Drawing and using System.Drawing need be done only once during your session, but it is not destructive to run them many times.
The nicest new feature that most APL'ers will notice is that each control is an object, and can be used, reused and even used in different contexts, as on different Forms. It is really quite amazing, and the possibilities are endless once you get aquanted with object programming.
Here is the example, which again was just typed in the session:
a = Form()
ms = MenuStrip()
file = ToolStripMenuItem()
open = ToolStripMenuItem()
exit = ToolStripMenuItem()
help = ToolStripMenuItem()
about = ToolStripMenuItem()
ms.Items.AddRange(file help)
refbyname System.Drawing
using System.Drawing
ms.Location = Point(0,0)
ms.Name= "menuStrip1"
ms.Size= Size(292,24)
ms.TabIndex = 0
file.DropDownItems.AddRange(open exit)
a.Show()
a.Controls.Add(ms)
file.Name= "File"
file.Size = Size(35,20)
file.Text = "File"
open.Name= "open"
open.Size= Size(152,22)
open.Text= "Open"
exit.Name= "exit"
exit.Size= Size(152,22)
exit.Text = "Exit"
file.DropDownItems.Remove(open)
file.DropDownItems.Insert(0, open)
If you want to use arrays to create and modify these controls, which of course opens a veritable panoply of options:
a = Form()
ms = MenuStrip()
tsm = ToolStripMenuItem() ToolStripMenuItem() ToolStripMenuItem() ToolStripMenuItem() ToolStripMenuItem()
file = 0
open = 1
exit = 2
help = 3
about = 4
ms.Items.AddRange(tsm[file] tsm[open])
refbyname System.Drawing
using System.Drawing
ms.Location = Point(0,0)
ms.Name= "menuStrip1"
ms.Size= Size(292,24)
ms.TabIndex = 0
tsm[file].DropDownItems.AddRange(tsm[open] tsm[exit])
a.Show()
a.Controls.Add(ms)
tsm[file].Name= "File"
tsm[file].Size = Size(35,20)
tsm[file].Text = "File"
tsm[open].Name= "open"
tsm[open].Size= Size(152,22)
tsm[open].Text= "Open"
Once you catch the idea of creating menus as seperate objects, you can do all kinds of neat things. Like build the MenuStrip object using the example above, store it in memory until you need it, and then just add it to your Form. Then when your menu has served its purpose, just remove it from your Form. Even though the menu strip is not on any running Form, it still resides in memory, and you can put it back on the Form at any time, or even on several Forms at once.
Also, keep in mind you can paste these into an edit session in Visual APL and they will just run when you press Ctrl+E