F # winforms MenuStrip issue: not sure how to get the DropDownItems handle

I recently started learning F # and this is the first time I have 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 is the problem, I cannot figure out how to get the handle to the DropDownItems so that I can use it. I'm sure this is something simple, but I haven't used F # for a long time. Thanks for any help.

edit: I would also like to point out that I know there is a lot of ugly syntax in this block of code, but this is all just a test form that I used.

0


source to share


1 answer


I think you just need

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.

Note also that it is more idiomatic to say



yadda |> ignore

      

but not

ignore(yadda)

      

+3


source







All Articles