I have recently started learning F#, and this is the first time I've ever used WinForms. Here is my code.
我最近开始学习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)
What the problem is, I can't seem to figure out how I would get a handle on the DropDownItems item so that I could use it. I'm sure it's something simple, but I haven't been using F# for that long. Thanks for any help.
问题是,我似乎无法弄清楚如何处理DropDownItems项目以便我可以使用它。我确信它很简单,但我没有长时间使用F#。谢谢你的帮助。
edit: I'd also like to point out that I know there are alot of ugly syntax in that block of code, but the whole thing is just a test form I've been using.
编辑:我还想指出,我知道在那段代码中有很多难看的语法,但整个过程只是我一直在使用的测试形式。
1 个解决方案
#1
3
I think you just need to
我想你只需要
let ddi = file.DropDownItems.Add("TestItem") //Code of importance
The problem is that you are ignoring the result of the Add() call, which returns the added item.
问题是您忽略了Add()调用的结果,该调用返回添加的项目。
Note also that it's more idiomatic to say
还要注意,它更具惯用性
yadda |> ignore
rather than
ignore(yadda)
#1
3
I think you just need to
我想你只需要
let ddi = file.DropDownItems.Add("TestItem") //Code of importance
The problem is that you are ignoring the result of the Add() call, which returns the added item.
问题是您忽略了Add()调用的结果,该调用返回添加的项目。
Note also that it's more idiomatic to say
还要注意,它更具惯用性
yadda |> ignore
rather than
ignore(yadda)