F# winforms MenuStrip 问题:不确定如何获取 DropDownItems 的句柄
我最近开始学习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# 的时间并不长。 谢谢你的帮助。
编辑:我还想指出,我知道该代码块中有很多丑陋的语法,但整个事情只是我一直在使用的测试形式。
I have recently started learning F#, and this is the first time I've ever used WinForms. Here is my code.
#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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你只需要
问题是你忽略了 Add() 调用的结果,它返回添加的项目。
说”更惯用。
另请注意,“说”比“
I think you just need to
The problem is that you are ignoring the result of the Add() call, which returns the added item.
Note also that it's more idiomatic to say
rather than