2014-01-28 26 views
2

我已經在C#中創建了一個winform1 dll並嘗試在F#中使用它,因爲視覺F#沒有可視化設計器。我想要做的就是這樣的在C#中創建一個winform dll並使用它#F#

//F# pesudo code 
let obj1 = new winform1() 
obj1.show()// 
let mutable i = 1 
while true do 
    thread.sleep 1000 
    i<i+1 
    obj1.shownumber i 
換句話說

,我模擬顯示的形式隨着時間的東西。你能給我點什麼嗎?先謝謝你!

+0

而究竟哪些方法不起作用? - 乍一看,代碼看起來不錯。 –

+0

@JohnPalmer它沒有設置適當的消息循環,所以它不能處理任何事件 – JaredPar

+0

@JaredPar - 我有點猜到 - 我只是想讓OP真正解釋他的問題,所以有一個真正的問題。 –

回答

5

要真正運行WinForms應用程序的初始表單,您需要設置適當的消息循環。最好的方法是使用Application.Run方法。

open System.Windows.Forms 

let obj1 = new winform1() 
Application.Run(obj1) 

請注意,標準C#WinForms應用程序添加了2個其他語句。雖然我不知道他們的確切目的,但我也會包括他們

Application.EnableVisualStyles() 
Application.SetCompatibleTextRenderingDefault(false) 
Application.Run(obj1) 
+0

對於'SetCompatibleTextRenderingDefault'看到:http://msdn.microsoft.com/de-de/library/system.windows.forms.application.setcompatibletextrenderingdefault(v=vs.110).aspx 對於'EnableVisualStyles'看到: http://stackoverflow.com/questions/6764100/does-application-enablevisualstyles-do-anything – Andy

+0

首先感謝您的回答。我嘗試了你的方法。它與ShowDialog()具有相同的結果,我的意思是代碼將停在這裏,並且不能隨時間更新表單。可能是我的問題不清楚,我在這裏打開一個新的線程.http://stackoverflow.com/questions/21410402/update-the-form-after-application-run – Constantine

相關問題