views:

380

answers:

1

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.

+2  A: 

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.

Note also that it's more idiomatic to say

yadda |> ignore

rather than

ignore(yadda)
Brian
Thank you for the answer, sorry for not besting it sooner. I was so tired that day I wasn't even thinking. Sorry for such a stupid question.
Rayne