2014-01-28 25 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

相关问题