2008-12-06 107 views
0

我最近開始學習F#,這是我第一次使用WinForms。這是我的代碼。F#winforms MenuStrip問題:不知道如何獲得DropDownItems的句柄

#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#那麼久。謝謝你的幫助。

編輯:我也想指出,我知道這段代碼中有很多醜陋的語法,但整個事情只是我一直在使用的測試表單。

回答

3

我想你只需要

let ddi = file.DropDownItems.Add("TestItem") //Code of importance 

的問題是,你忽略了加()調用,它返回添加的項目的結果。

還請注意,這是更地道地說

yadda |> ignore 

而不是

ignore(yadda) 
+0

謝謝你的回答,抱歉沒有擊敗它越快。那天我真的沒有想到,我真的很累。對不起,這樣一個愚蠢的問題。 – Rayne 2008-12-11 08:28:31