我最近开始学习 F#,这是我第一次使用 WinForms。这是我的代码。
#light
open System
open System.Windows.Forms
let form =
let temp = new Form()
let ms = new MenuStrip()
let file = new ToolStripDropDownButton("File")
ignore(ms.Items.Add(file))
ignore(file.DropDownItems.Add("TestItem")) \\Code of importance
let things _ _ = ignore(MessageBox.Show("Hai"))
let handle = new EventHandler(things)
ignore(file.Click.AddHandler(handle))
let stuff _ _ = ignore(MessageBox.Show("Hai thar."))
let handler = new EventHandler(stuff)
let myButton = new Button(Text = "My button :>", Left = 8, Top = 100, Width = 80)
myButton.Click.AddHandler(handler)
let dc c = (c :> Control)
temp.Controls.AddRange([| dc myButton; dc ms |]);
temp
do Application.Run(form)
问题是什么,我似乎无法弄清楚如何获得 DropDownItems 项目的句柄,以便我可以使用它。我确信这很简单,但我已经很久没有使用 F#了。谢谢你的帮助。
编辑:我还想指出,我知道那段代码中有很多难看的语法,但整个事情只是我一直在使用的一个测试表格。